1 package org.myoodb.transactions; 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 String NEIGHBORHOOD[][] = 33 { 34 {"John", "Smith"}, {"Mary", "Smith"}, {"Mark", "Johson"}, {"Barb", "Johson"}, {"Jack", "Smith"}, {"Kate", "Smith"}, {"Jean", "Smith"}, }; 42 43 public static void main(String args[]) throws Exception  44 { 45 org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myoodb://localhost:" + PORT, USERNAME, PASSWORD); 46 47 49 Family family = (Family) db.getRoot("The Smith Family"); 50 51 if (family == null) 52 { 53 System.out.println("Create The Smith Family"); 54 55 family = (Family) db.createRoot(FamilyDbImpl.class, "The Smith Family"); 56 family.setName("Smith"); 58 } 59 else 60 { 61 System.out.println("The Smith Family already created"); 62 } 63 64 for (int i = 0; i < NEIGHBORHOOD.length; i++) 65 { 66 org.myoodb.MyOodbTransaction tx = db.createTransaction(); 67 tx.begin(); 68 69 Person person = (Person) db.createObject(PersonDbImpl.class); 70 person.setName(NEIGHBORHOOD[i][0]); 72 73 System.out.println(" Checking if Person " + person + " is part of the Smith Family"); 74 75 System.out.println(" Is Person locked: " + person.isLocked()); 76 77 if (NEIGHBORHOOD[i][1].equals("Smith") == false) 78 { 79 System.out.println(" Person " + person + " is not part of the Smith Family"); 80 81 tx.rollback(); 83 continue; 84 } 85 86 tx.begin(); 88 family.add(person); 89 90 if (family.size() > 4) 91 { 92 System.out.println(" The Smith Family has reached their Maximum size: " + person); 93 94 tx.rollback(); 96 tx.rollback(); 98 continue; 99 } 100 101 tx.commit(); 102 103 tx.commit(); 104 105 System.out.println(" Person " + person + " is now offically part of the Smith Family"); 106 } 107 } 108 } 109
| Popular Tags
|