WEB开发网
开发学院软件开发Java 面向 Java 开发人员的 db4o 指南: 查询,更新和一... 阅读

面向 Java 开发人员的 db4o 指南: 查询,更新和一致性

 2010-04-01 00:00:00 来源:WEB开发网   
核心提示: 清单 3 所示的简单示例演示了这种不同的一致性概念:清单 3. 三个 Brianimportcom.db4o.*;importcom.tedneward.model.*;publicclassHellodb4o{publicstaticvoidmain(String[]args)throwsEx

清单 3 所示的简单示例演示了这种不同的一致性概念:

清单 3. 三个 Brian

        import com.db4o.*; 
 
import com.tedneward.model.*; 
 
public class Hellodb4o 
{ 
  public static void main(String[] args) 
    throws Exception 
  { 
    ObjectContainer db = null; 
    try 
    { 
      db = Db4o.openFile("persons.data"); 
 
      Person brian = new Person("Brian", "Goetz", 39); 
      Person jason = new Person("Jason", "Hunter", 35); 
      Person clinton = new Person("Brian", "Sletten", 38); 
      Person david = new Person("David", "Geary", 55); 
      Person glenn = new Person("Glenn", "Vanderberg", 40); 
      Person neal = new Person("Neal", "Ford", 39); 
       
      db.set(brian); 
      db.set(jason); 
      db.set(clinton); 
      db.set(david); 
      db.set(glenn); 
      db.set(neal); 
 
      db.commit(); 
       
      // Find all the Brians 
      ObjectSet brians = db.get(new Person("Brian", null, 0)); 
      while (brians.hasNext()) 
        System.out.println(brians.next()); 
         
      Person brian2 = new Person("Brian", "Goetz", 39); 
        db.set(brian2); 
        db.commit(); 
 
      // Find all the Brians 
      ObjectSet brians = db.get(new Person("Brian", null, 0)); 
      while (brians.hasNext()) 
        System.out.println(brians.next()); 
    } 
    finally 
    { 
      if (db != null) 
        db.close(); 
    } 
  } 
} 

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:面向 Java 开发

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接