1 package org.myoodb.selfHealing; 25 26 public class Client 27 { 28 public static int PORT = 54321; 29 public static String USERNAME = "admin"; 30 public static String PASSWORD = "admin"; 31 32 public static void main(String args[]) throws Exception  33 { 34 org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myoodb://localhost:" + PORT, USERNAME, PASSWORD); 35 36 Family family = (Family) db.getRoot("The Smith Family"); 37 38 if (family == null) 39 { 40 family = (Family) db.createRoot(FamilyDbImpl.class, "The Smith Family"); 41 43 family.setName("Smith"); 44 } 45 else 46 { 47 System.out.println("The Smith Family already created"); 48 } 49 50 Person person = (Person) db.createObject(PersonDbImpl.class); 51 53 person.setName("John Smith"); 54 55 family.add(person); 56 57 db.delete(person); 59 60 checkFamilyIntegrity(family); 62 63 family.fixUpReference(family.getLocalTime()); 65 66 checkFamilyIntegrity(family); 68 69 } 72 73 public static void checkFamilyIntegrity(Family family) 74 { 75 try 76 { 77 Person person = (Person) family.first(); 78 79 try 80 { 81 person.getName(); 82 } 83 catch (org.myoodb.exception.ObjectNotFoundException e) 84 { 85 System.out.println(" The family tree has a bad reference (it was suppose to): " + e); 86 } 87 } 88 catch (java.util.NoSuchElementException e) 89 { 90 System.out.println(" The family tree should have no elements, fix up worked: " + e); 91 } 92 } 93 } 94
| Popular Tags
|