TOB 6 编程界面重大简化

阅读更多
TOB 6 的编程界面最近完成了一次重大简化, 附件是更新后的持久应用样板程序, 用6.0的SUN JDK和1.6.5或更新的Apache Ant就可以编译.

简化后的持久类模样从下面代码可见一斑, 特别注意 getAllProducts() 的实现.
完整项目源码在附件zip中.
package tob.bookstore;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import av.tob.IAm;
import av.tob.Index;
import av.tob.Kin;
import av.tob.KinSet;
import av.tob.Retying;
import av.tob.Swappable;
import av.tob.TheRelation;
import av.tob.Writing;

@Swappable(typeInSwap = "Category")
public class Category extends TheRelation
{

    @Index(unique = false)
    protected static final String NAME_INDEX = "name";

    protected Tie parent;

    @IAm("parent")
    protected KinSet subcategories = null;

    @IAm("maincate")
    protected KinSet products = null;

    protected KinSet moreProducts = null;

    private String name;

    private String description;

    protected Category()
    {
    }

    public Category(Category parentCate, String name, String desc)
    {
        this.parent = (parentCate == null) ? null : new Tie(
                parentCate);
        this.name = name;
        this.description = desc;
    }

    public Category getParent()
    {
        return parent == null ? null : parent.o;
    }

    @Retying("parent")
    public void changeParent(Category newParent)
    {
        this.parent = (newParent == null) ? null : new Tie(newParent);
    }

    public KinSet getSubcategories()
    {
        return this.subcategories;
    }

    public KinSet getMainProducts()
    {
        return this.products;
    }

    public KinSet getMoreProducts()
    {
        return this.moreProducts;
    }

    private void enlistProducts(List l)
    {
        for (Kin p : products)
            l.add(p.getO());
        for (Kin p : moreProducts)
            l.add(p.getO());
        for (Kin subcate : subcategories)
            subcate.getO().enlistProducts(l);
    }

    public List getAllProducts()
    {
        List all = new ArrayList(100);
        this.enlistProducts(all);
        return Collections.unmodifiableList(all);
    }

    public String getName()
    {
        return this.name;
    }

    @Writing
    public void setName(String name)
    {
        this.name = name;
    }

    public String getDesciption()
    {
        return this.description;
    }

    @Writing
    public void setDescription(String desc)
    {
        this.description = desc;
    }

}

  • av6patterns.zip (29.7 KB)
  • 描述: 最新样板程序
  • 下载次数: 1607

你可能感兴趣的:(编程,Ant,JDK,SQL,Apache)