`
daojun.zeng
  • 浏览: 10658 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

如此orm可否

阅读更多
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  
{  

分享到:
评论

相关推荐

    Java面试宝典2010版

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 7、char型变量中能不能存贮一个中文汉字?为什么? 8、用最有效...

    最新Java面试宝典pdf版

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...

    Java面试笔试资料大全

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...

    JAVA面试宝典2010

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...

    Java面试宝典-经典

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...

    java面试题大全(2012版)

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...

    Java面试宝典2012版

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用...

    java面试宝典2012

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...

    Java面试宝典2012新版

    5、switch语句能否作用在byte上,能否作用在long上,能否作用在String上? 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 9 7、char型变量中能不能存贮一个中文汉字?为什么? 9 8、用最...

    Java 面试宝典

    5、switch 语句能否作用在 byte 上,能否作用在 long 上,能否作用在 String 上? .. 9 6、short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? ....................... 9 7、char 型变量中能不...

Global site tag (gtag.js) - Google Analytics