TOB 6 编程界面重大简化

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

简化后的持久类模样从下面代码可见一斑, 特别注意 getAllProducts() 的实现.
完整项目源码在附件zip中.
[code]
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;
}

}
[/code]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值