Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Jute Powerful Forum  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Jute的O/R Mapping
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2002-08-04 13:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
表结构
 
CREATE TABLE `test` (
  `id` int(11) NOT NULL auto_increment,
  `userid` varchar(25) NOT NULL default '',
  `username` varchar(50) NOT NULL default '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `userid` (`userid`),
  UNIQUE KEY `username` (`username`)
) TYPE=MyISAM


映射的Java对象
 
package org.jute.forum;

import org.jute.dbo.DBObject;
import org.jute.dbo.DBOHome;
import org.jute.dbo.DBOConstant;

public class Test extends DBObject {
    private int id;
    private String userid;
    private String username;

    
    public DBOHome getHome() {
        return TestHome.getInstance();
    }
    
    public Test() {
    }

    public String getOIDMethod() {
        return DBOConstant.AUTOINCREMENT_ID_METHOAD;
    }

    public String getPrimaryKey() {
        return "id";
    }

    public String getTable() {
        return "TEST";
    }

    
    public String getUserid() {
        return userid;
    }
    
    public String getUsername() {
        return username;
    }
    
    public void setUserid(String userid) {
        this.userid = userid;
    }
    
    public void setUsername(String username) {
        this.username = username;
    }
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
}


映射Java对象的商务方法集
 
package org.jute.forum;

import org.jute.dbo.DBOHome;

public class TestHome extends DBOHome {
    protected transient static TestHome home = new TestHome() ;
    
    public static DBOHome getInstance() {
        return home;
    }
    
    public String getDatabase() {
        return "default";
    }
    
    public static int countAll() {
        return home.getIntFieldValue("SELECT countStart FROM TEST");
    }
    
    public static Vector getAll() {
        return home.getDBObjectList("SELECT * FROM TEST",0,-1,Test.class);
    }
    
    public static Test findByPrimaryKey(int id) {
        return (Test) home.getDBObject("SELECT * FROM TEST WHERE id="+id,Test.class);
    }

    ...
}


在Servlet里调用
 
public class TestServlet extends BaseServlet {
    

    public String baseAction(Context context, CGI cgi) {
        try {
                Test test = new Test();
                test.setUserid("userid"+Math.random());
                test.setUsername("username"+Math.random());
                test.insert();
                System.out.println("test.getId(): "+test.getId());
                test.setUsername("hello"+Math.random());
                test.update();
                test.delete();
                System.out.println("TestHome.countAll(): "+TestHome.countAll());
        }
        catch (Exception ex) {
            ex.printStackTrace();
        }
        
        return "test.vm";
    }

    public String getRealmName() {
        return "jute";
    }
    
}


rainman edited on 2002-08-04 22:58


作者 回复: Jute的O/R Mapping [Re:rainman]
carfield



发贴: 0
积分: 0
于 2002-08-05 02:51 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Have you consider using apache's ojb?

http://jakarta.apache.org/ojb



作者 回复: 回复: Jute的O/R Mapping [Re:carfield]
rainman

阿熊

元老


发贴: 5644
积分: 454
于 2002-08-06 01:06 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
carfield wrote:
Have you consider using apache's ojb?

http://jakarta.apache.org/ojb


No,the 1.0 version is not released right now. But it's a really good O/R mapping tool.

I wrote my own O/R mapping tool. it's very fast and easy to use.


rainman edited on 2002-08-06 02:31



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923