WEB开发网
开发学院软件开发Java 面向 Java 开发人员的 db4o 指南: 结构化对象和集... 阅读

面向 Java 开发人员的 db4o 指南: 结构化对象和集合

 2010-04-01 00:00:00 来源:WEB开发网   
核心提示: 测试新模型对新模型的探察测试简单明了,我创建一个叫做 InheritanceTest 的 JUnit 类,面向 Java 开发人员的 db4o 指南: 结构化对象和集合(3),目前为止,它是第一个较为复杂的对象集,充当 OODBMS 最初的工作内容,为了使输出(将会在清单 6 中见到)更加清晰

测试新模型

对新模型的探察测试简单明了。我创建一个叫做 InheritanceTest 的 JUnit 类,目前为止,它是第一个较为复杂的对象集,充当 OODBMS 最初的工作内容。为了使输出(将会在清单 6 中见到)更加清晰,我在清单 3 中展示了带有 @Before 注释的 prepareDatabase() 调用:

清单 3. 欢迎加入本公司(您现在为我服务)

  @Before public void prepareDatabase() 
  { 
    db = Db4o.openFile("persons.data"); 
 
    // The Newards 
    Employee ted = new Employee("Ted", "Neward", "President and CEO", 
      Gender.MALE, 36, Mood.HAPPY); 
    Person charlotte = new Person("Charlotte", "Neward", 
      Gender.FEMALE, 35, Mood.HAPPY); 
    ted.setSpouse(charlotte); 
    Person michael = charlotte.haveBaby("Michael", Gender.MALE); 
    michael.setAge(14); 
    Person matthew = charlotte.haveBaby("Matthew", Gender.MALE); 
    matthew.setAge(8); 
    Address tedsHomeOffice = 
      new Address("12 Redmond Rd", "Redmond", "WA", "98053"); 
    ted.setHomeAddress(tedsHomeOffice); 
    ted.setWorkAddress(tedsHomeOffice); 
    ted.setVacationAddress( 
      new Address("10 Wannahokalugi Way", "Oahu", "HA", "11223")); 
    db.set(ted); 
     
    // The Tates 
    Employee bruce = new Employee("Bruce", "Tate", "Chief Technical Officer", 
      Gender.MALE, 29, Mood.HAPPY); 
    Person maggie = new Person("Maggie", "Tate", 
      Gender.FEMALE, 29, Mood.HAPPY); 
    bruce.setSpouse(maggie); 
    Person kayla = maggie.haveBaby("Kayla", Gender.FEMALE); 
    Person julia = maggie.haveBaby("Julia", Gender.FEMALE); 
    bruce.setHomeAddress( 
      new Address("5 Maple Drive", "Austin", 
        "TX", "12345")); 
    bruce.setWorkAddress( 
      new Address("5701 Downtown St", "Austin", 
        "TX", "12345")); 
    // Ted and Bruce both use the same timeshare, apparently 
    bruce.setVacationAddress( 
      new Address("10 Wanahokalugi Way", "Oahu", 
        "HA", "11223")); 
    db.set(bruce); 
     
    // The Fords 
    Employee neal = new Employee("Neal", "Ford", "Meme Wrangler", 
      Gender.MALE, 29, Mood.HAPPY); 
    Person candi = new Person("Candi", "Ford", 
      Gender.FEMALE, 29, Mood.HAPPY); 
    neal.setSpouse(candi); 
    neal.setHomeAddress( 
      new Address("22 Gritsngravy Way", "Atlanta", "GA", "32145")); 
    // Neal is the roving architect 
    neal.setWorkAddress(null); 
    db.set(neal); 
     
    // The Slettens 
    Employee brians = new Employee("Brian", "Sletten", "Bosatsu Master", 
      Gender.MALE, 29, Mood.HAPPY); 
    Person kristen = new Person("Kristen", "Sletten", 
      Gender.FEMALE, 29, Mood.HAPPY); 
    brians.setSpouse(kristen); 
    brians.setHomeAddress( 
      new Address("57 Classified Drive", "Fairfax", "VA", "55555")); 
    brians.setWorkAddress( 
      new Address("1 CIAWasNeverHere Street", "Fairfax", "VA", "55555")); 
    db.set(brians); 
     
    // The Galbraiths 
    Employee ben = new Employee("Ben", "Galbraith", "Chief UI Director", 
      Gender.MALE, 29, Mood.HAPPY); 
    Person jessica = new Person("Jessica", "Galbraith", 
      Gender.FEMALE, 29, Mood.HAPPY); 
    ben.setSpouse(jessica); 
    ben.setHomeAddress( 
      new Address( 
        "5500 North 2700 East Rd", "Salt Lake City", 
        "UT", "12121")); 
    ben.setWorkAddress( 
      new Address( 
        "5600 North 2700 East Rd", "Salt Lake City", 
        "UT", "12121")); 
    ben.setVacationAddress( 
      new Address( 
        "2700 East 5500 North Rd", "Salt Lake City", 
        "UT", "12121")); 
      // Ben really needs to get out more 
    db.set(ben); 
     
    db.commit(); 
  } 

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

Tags:面向 Java 开发

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