Java的面向?qū)ο髷?shù)據(jù)庫db4o

          上學(xué)的時候就聽老師說過有對象數(shù)據(jù)庫。
          但是我所接觸的數(shù)據(jù)庫都是關(guān)系型數(shù)據(jù)庫mysql,oracle,ms sql server,或是db2.
          最近在ibm development work上看到一個名為db4o的對象數(shù)據(jù)。
          才看第一章,學(xué)過Java的都應(yīng)該很容易理解的。
          確實它真的很簡單。
          看起來似乎就像是在一個Java的操作,而并非如我們所以為的那樣的想關(guān)系型數(shù)據(jù)庫中操作一樣。
          如果有興趣的話,大家也可以去看看。
          不過,文章作者也對db4o的一些缺點進(jìn)行了列舉。
          自己并沒有進(jìn)行很深入的學(xué)習(xí)。
          只是對其感興趣罷了。
          或許對系數(shù)據(jù)庫可能讓我們進(jìn)入一個新的世界。
           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 
          數(shù)據(jù)庫的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 
          或是用另外的一種方法進(jìn)行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 
          詳細(xì)介紹請參看ibm的學(xué)習(xí)文檔。
          http://www.ibm.com/developerworks/cn/java/jdb4o/?ca=j-h

          posted on 2009-06-09 13:34 duduli 閱讀(1543) 評論(3)  編輯  收藏 所屬分類: 數(shù)據(jù)庫

          評論

          # re: Java的面向?qū)ο髷?shù)據(jù)庫db4o 2009-06-09 17:14 找個美女做老婆

          我的博客搬到新家了 http://www.javaly.cn, 順便給你推薦一個導(dǎo)航網(wǎng)站 http://www.510gougou.com  回復(fù)  更多評論   

          # re: Java的面向?qū)ο髷?shù)據(jù)庫db4o 2009-06-10 09:45 subtitle

          .....  回復(fù)  更多評論   

          # re: Java的面向?qū)ο髷?shù)據(jù)庫db4o 2009-06-13 09:40 metadmin

          您看看GAE,可以將對象托管起來。后臺編程更簡單了。

          ---------------------------------
          解開權(quán)限與業(yè)務(wù)耦合,提高開發(fā)效率
          細(xì)粒度權(quán)限管理軟件 試用版下載
          http://www.metadmin.com

            回復(fù)  更多評論   

          <2009年6月>
          31123456
          78910111213
          14151617181920
          21222324252627
          2829301234
          567891011

          導(dǎo)航

          統(tǒng)計

          公告

          welcome to my place.

          常用鏈接

          留言簿(5)

          我參與的團隊

          隨筆分類

          隨筆檔案

          新聞分類

          石頭JAVA擺地攤兒

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          @duduli
          主站蜘蛛池模板: 汕尾市| 双柏县| 白玉县| 巍山| 邹城市| 陈巴尔虎旗| 三原县| 开原市| 老河口市| 威海市| 宁陵县| 临泉县| 吉林市| 门源| 道孚县| 日喀则市| 华宁县| 来凤县| 台安县| 富源县| 灵璧县| 宝兴县| 青岛市| 工布江达县| 夹江县| 阿瓦提县| 普洱| 大丰市| 盐边县| 闻喜县| 贵港市| 南郑县| 宜兰市| 和田市| 堆龙德庆县| 元朗区| 双柏县| 青川县| 龙门县| 东海县| 大宁县|