Java的面向对象数据库db4o

上学的时候就听老师说过有对象数据库。
但是我所接触的数据库都是关系型数据库mysql,oracle,ms sql server,或是db2.
最近在ibm development work上看到一个名为db4o的对象数据。
才看第一章,学过Java的都应该很容易理解的。
确实它真的很简单。
看起来似乎就像是在一个Java的操作,而并非如我们所以为的那样的想关系型数据库中操作一样。
如果有兴趣的话,大家也可以去看看。
不过,文章作者也对db4o的一些缺点进行了列举。
自己并没有进行很深入的学习。
只是对其感兴趣罢了。
或许对系数据库可能让我们进入一个新的世界。
 1 public class Person
 2 {
 3     public Person()
 4     { }
 5     public Person(String firstName, String lastName, int age)
 6     {
 7         this.firstName = firstName;
 8         this.lastName = lastName;
 9         this.age = age;
10     }
11     
12     public String getFirstName() { return firstName; }
13     public void setFirstName(String value) { firstName = value; }
14     
15     public String getLastName() { return lastName; }
16     public void setLastName(String value) { lastName = value; }
17     
18     public int getAge() { return age; }
19     public void setAge(int value) { age = value; }
20 
21     public String toString()
22     {
23         return 
24             "[Person: " +
25             "firstName = " + firstName + " " +
26             "lastName = " + lastName + " " +
27             "age = " + age + 
28             "]";
29     }
30     
31     public boolean equals(Object rhs)
32     {
33         if (rhs == this)
34             return true;
35         
36         if (!(rhs instanceof Person))
37             return false;
38         
39         Person other = (Person)rhs;
40         return (this.firstName.equals(other.firstName) &&
41                 this.lastName.equals(other.lastName) &&
42                 this.age == other.age);
43     }
44     
45     private String firstName;
46     private String lastName;
47     private int age;
48 }
49 
数据库的insert
 1 
 2 import com.tedneward.model.*;
 3 
 4 public class Hellodb4o
 5 {
 6     public static void main(String[] args)
 7         throws Exception
 8     {
 9         ObjectContainer db = null;
10         try
11         {
12             db = Db4o.openFile("persons.data");
13 
14             Person brian = new Person("Brian""Goetz"39);
15             
16             db.set(brian);
17             db.commit();
18         }
19         finally
20         {
21             if (db != null)
22                 db.close();
23         }
24     }
25 }
26 
或是用另外的一种方法进行insert操作。
 1 public class Hellodb4o
 2 {
 3     public static void main(String[] args)
 4         throws Exception
 5     {
 6         ObjectContainer db = null;
 7         try
 8         {
 9             db = Db4o.openFile("persons.data");
10 
11             Person brian = new Person("Brian""Goetz"39);
12             Person jason = new Person("Jason""Hunter"35);
13             Person clinton = new Person("Brian""Sletten"38);
14             Person david = new Person("David""Geary"55);
15             Person glenn = new Person("Glenn""Vanderberg"40);
16             Person neal = new Person("Neal""Ford"39);
17             
18             db.set(brian);
19             db.set(jason);
20             db.set(clinton);
21             db.set(david);
22             db.set(glenn);
23             db.set(neal);
24 
25             db.commit();
26             
27             // Find all the Brians
28             ObjectSet brians = db.get(new Person("Brian"null0));
29             while (brians.hasNext())
30                 System.out.println(brians.next());
31         }
32         finally
33         {
34             if (db != null)
35                 db.close();
36         }
37     }
38 }
39 
详细介绍请参看ibm的学习文档。
http://www.ibm.com/developerworks/cn/java/jdb4o/?ca=j-h

posted on 2009-06-09 13:34 duduli 阅读(1526) 评论(3)  编辑  收藏 所属分类: 数据库

评论

# re: Java的面向对象数据库db4o 2009-06-09 17:14 找个美女做老婆

我的博客搬到新家了 http://www.javaly.cn, 顺便给你推荐一个导航网站 http://www.510gougou.com  回复  更多评论   

# re: Java的面向对象数据库db4o 2009-06-10 09:45 subtitle

.....  回复  更多评论   

# re: Java的面向对象数据库db4o 2009-06-13 09:40 metadmin

您看看GAE,可以将对象托管起来。后台编程更简单了。

---------------------------------
解开权限与业务耦合,提高开发效率
细粒度权限管理软件 试用版下载
http://www.metadmin.com

  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2009年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

公告

welcome to my place.

常用链接

留言簿(5)

我参与的团队

随笔分类

随笔档案

新闻分类

石头JAVA摆地摊儿

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

@duduli