ava代码
public class Entity
{
protected TableMapping tlbMapping; // 与数据表的结构映射关系
protected Map<String, Object> attrs; // entity的属性
protected Set<Class<Entity>> hasOne; // 1对1
protected Set<Class<Entity>> hasMany; // 1对多
protected Set<Class<Entity>> belongsTo; // 多对1
protected Set<Class<Entity>> hasAndBelongsToMany; // 多对多
public void setAttr(String attrName, Object value)
{
attrs.put(attrName, value);
}
public Object getAttr(String attrName)
{
return attrs.get(attrName);
}
/**
* 重载这个方法,用来设置关系
*/
public void setRelation()
{
// 在这里手动的设置关系,1对1,1对多。。。
hasOne(...);
belongsTo(...);
...
}
protected void hasOne(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasOne.add(clazz);
}
protected void belongsTo(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
belongsTo.add(clazz);
}
protected void hasAndBelongsToMany(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasAndBelongsToMany.add(clazz);
}
}
public class Entity
{
protected TableMapping tlbMapping; // 与数据表的结构映射关系
protected Map<String, Object> attrs; // entity的属性
protected Set<Class<Entity>> hasOne; // 1对1
protected Set<Class<Entity>> hasMany; // 1对多
protected Set<Class<Entity>> belongsTo; // 多对1
protected Set<Class<Entity>> hasAndBelongsToMany; // 多对多
public void setAttr(String attrName, Object value)
{
attrs.put(attrName, value);
}
public Object getAttr(String attrName)
{
return attrs.get(attrName);
}
/**
* 重载这个方法,用来设置关系
*/
public void setRelation()
{
// 在这里手动的设置关系,1对1,1对多。。。
hasOne(...);
belongsTo(...);
...
}
protected void hasOne(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasOne.add(clazz);
}
protected void belongsTo(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
belongsTo.add(clazz);
}
protected void hasAndBelongsToMany(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasAndBelongsToMany.add(clazz);
}
}
Java代码
public class User extends Entity
{
}
public class Entity
{
protected TableMapping tlbMapping; // 与数据表的结构映射关系
protected Map<String, Object> attrs; // entity的属性
protected Set<Class<Entity>> hasOne; // 1对1
protected Set<Class<Entity>> hasMany; // 1对多
protected Set<Class<Entity>> belongsTo; // 多对1
protected Set<Class<Entity>> hasAndBelongsToMany; // 多对多
public void setAttr(String attrName, Object value)
{
attrs.put(attrName, value);
}
public Object getAttr(String attrName)
{
return attrs.get(attrName);
}
/**
* 重载这个方法,用来设置关系
*/
public void setRelation()
{
// 在这里手动的设置关系,1对1,1对多。。。
hasOne(...);
belongsTo(...);
...
}
protected void hasOne(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasOne.add(clazz);
}
protected void belongsTo(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
belongsTo.add(clazz);
}
protected void hasAndBelongsToMany(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasAndBelongsToMany.add(clazz);
}
}
public class Entity
{
protected TableMapping tlbMapping; // 与数据表的结构映射关系
protected Map<String, Object> attrs; // entity的属性
protected Set<Class<Entity>> hasOne; // 1对1
protected Set<Class<Entity>> hasMany; // 1对多
protected Set<Class<Entity>> belongsTo; // 多对1
protected Set<Class<Entity>> hasAndBelongsToMany; // 多对多
public void setAttr(String attrName, Object value)
{
attrs.put(attrName, value);
}
public Object getAttr(String attrName)
{
return attrs.get(attrName);
}
/**
* 重载这个方法,用来设置关系
*/
public void setRelation()
{
// 在这里手动的设置关系,1对1,1对多。。。
hasOne(...);
belongsTo(...);
...
}
protected void hasOne(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasOne.add(clazz);
}
protected void belongsTo(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
belongsTo.add(clazz);
}
protected void hasAndBelongsToMany(Class<Entity>... clazzs)
{
for (Class<Entity> clazz : clazzs)
hasAndBelongsToMany.add(clazz);
}
}
Java代码
public class User extends Entity
{
}