KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > LocalClient


1 import org.ozoneDB.LocalDatabase;
2 import org.ozoneDB.OzoneInterface;
3
4 /**
5  *
6  * <br> Date: Sep 2, 2002
7  * <br> Copyright Nordic Wave Inc, All rights reserved
8  * @author Per Nyfelt
9  */

10 public class LocalClient {
11
12
13     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
14         // this would initialize a local database instead of accessing a
15
// server remote
16
LocalDatabase db = new LocalDatabase();
17         String JavaDoc dbLocation = System.getProperty("user.home") + "/testdb";
18         if (!db.exists(dbLocation)) {
19             db.create(dbLocation);
20         }
21         db.open(dbLocation);
22
23         db.reloadClasses();
24         System.out.println("connected...");
25
26         Bus bus = (Bus) db.createObject(BusImpl.class.getName());
27         System.out.println("bus:" + bus);
28         bus.print();
29         db.deleteObject(bus);
30
31         Auto auto = (Auto) db.objectForName("auto");
32         if (auto == null) {
33             auto = (Auto) db.createObject(AutoImpl.class.getName(), OzoneInterface.Public, "auto");
34         }
35
36         // doSomething() returns the database object itself. However, in the
37
// client we get a proper proxy object.
38
Auto auto2 = (Auto) auto.doSomething(auto);
39
40         System.out.println("auto:" + auto);
41         auto.setAge(3);
42         System.out.println("auto.setAge (3)");
43         // auto and auto2 are proxies of the same object.
44
System.out.println("auto2:" + auto2);
45
46         Auto copy = (Auto) db.copyObject(auto);
47         copy.setAge(100);
48         System.out.println("\nauto:" + auto);
49         System.out.println("copy:" + copy);
50
51         db.deleteObject(copy);
52
53         db.close();
54         System.out.println("disconnected...");
55     }
56
57 }
58
Popular Tags