01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // General Public License as published by the Free Software Foundation;
10: // either version 2, or (at your option) any later version.
11: //
12: // This program is distributed in the hope that it will be useful,
13: // but WITHOUT ANY WARRANTY; without even the implied warranty of
14: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: // GNU General Public License and GNU Library General Public License
16: // for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // and GNU Library General Public License along with this program; if
20: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21: // MA 02139, USA.
22: //
23: ///////////////////////////////////////////////////////////////////////////////
24: package org.myoodb.selfHealing;
25:
26: import org.myoodb.objects.*;
27:
28: public class Client {
29: public static int PORT = 54321;
30: public static String USERNAME = "admin";
31: public static String PASSWORD = "admin";
32:
33: public static void main(String args[]) throws Exception {
34: org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open(
35: "tcp://localhost:" + PORT, USERNAME, PASSWORD);
36:
37: Family family = (Family) db.getRoot("Family");
38: if (family == null) {
39: family = (Family) db.createRoot("Family",
40: "org.myoodb.objects.FamilyDbImpl");
41: //family = (Family) db.createRoot("Family", FamilyDbImpl.class);
42:
43: family.setName("Smith");
44: } else {
45: System.out.println("The Smith Family already created");
46: }
47:
48: Person person = (Person) db
49: .createObject("org.myoodb.objects.PersonDbImpl");
50: //Person person = (Person) db.createObject(PersonDbImpl.class);
51:
52: person.setName("John Smith");
53: family.add(person);
54:
55: // XXX: now delete "John Smith" without removing him from the Family tree
56: db.deleteObject(person);
57:
58: // XXX: now try and get "John Smith" to show the tree first entry is now "corrupted"
59: checkFamilyIntegrity(family);
60:
61: // XXX: now show how to "Self Heal" this tree ( pass in current time to protect against recursion )
62: family.fixUpReference(family.getLocalTime());
63:
64: // XXX: now try and get "John Smith" to show the tree first entry is no longer there
65: checkFamilyIntegrity(family);
66:
67: // XXX: for how fixUpReference cleaned the tree, take a look at TreeSetDbImpl.java, but first
68: // XXX: take look at derived FamilyDbImpl.java to see what methods you might need to override.
69: }
70:
71: public static void checkFamilyIntegrity(Family family) {
72: try {
73: Person person = (Person) family.first();
74:
75: try {
76: person.getName();
77: } catch (org.myoodb.exception.ObjectNotFoundException e) {
78: System.out
79: .println(" The family tree has a bad reference (it was suppose to): "
80: + e);
81: }
82: } catch (java.util.NoSuchElementException e) {
83: System.out
84: .println(" The family tree should have no elements, fix up worked: "
85: + e);
86: }
87: }
88: }
|