论坛首页 Java企业应用论坛

TOB 6 编程界面重大简化

浏览 4934 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-02-25  
OO
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<Category> parent;

    @IAm("parent")
    protected KinSet<Category, Category> subcategories = null;

    @IAm("maincate")
    protected KinSet<Product, Product> products = null;

    protected KinSet<Categorization, Product> 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<Category>(
                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<Category>(newParent);
    }

    public KinSet<Category, Category> getSubcategories()
    {
        return this.subcategories;
    }

    public KinSet<Product, Product> getMainProducts()
    {
        return this.products;
    }

    public KinSet<Categorization, Product> getMoreProducts()
    {
        return this.moreProducts;
    }

    private void enlistProducts(List<Product> l)
    {
        for (Kin<?, Product> p : products)
            l.add(p.getO());
        for (Kin<?, Product> p : moreProducts)
            l.add(p.getO());
        for (Kin<?, Category> subcate : subcategories)
            subcate.getO().enlistProducts(l);
    }

    public List<Product> getAllProducts()
    {
        List<Product> all = new ArrayList<Product>(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;
    }

}

   发表时间:2007-02-25  
TestBookStore 的OrderQ.STATUS 和TestContant的UserQ.NAME等这是什么表示法啊
JDK5.0无法编译通过,只能使用JDK6.0?
0 请登录后投票
   发表时间:2007-02-25  
zrweng 写道
TestBookStore 的OrderQ.STATUS 和TestContant的UserQ.NAME等这是什么表示法啊
JDK5.0无法编译通过,只能使用JDK6.0?


编译时TOB自动生成用于拼装SQL的查询条件类, 对应应用自己的持久类名, 后面加个 Q.

TOB 6 是基于 JSR 269 的 Annotation Processor 的, 所以必须是JDK 6才行. 不过这样其实简化了编译步骤, 和平常javac/ant没有什么差别了, 原来5的时候还必须用apt编译才行的.
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics