KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cli > HelloManager


1 package cli;
2
3 import db.Hello;
4 import db.HelloImpl;
5 import org.ozoneDB.ExternalDatabase;
6 import org.ozoneDB.OzoneInterface;
7 import web.HelloServlet;
8
9 public class HelloManager {
10
11     private static Hello hello;
12     private static ExternalDatabase db;
13
14     public static void main(String JavaDoc[] args) {
15         try {
16             buildObject();
17         } catch (Exception JavaDoc e) {
18             e.printStackTrace();
19         }
20     }
21
22     /** makes sure there is a Hello object in Ozone
23      * we keep it extremely simple to show the idea, things could be
24      * easily parameterized.
25      */

26     private static void buildObject() throws Exception JavaDoc {
27         System.out.println("Trying to connect to ozone...");
28         db = ExternalDatabase.openDatabase("ozonedb:remote://localhost:3333");
29         System.out.println("....Connected to ozone");
30         db.reloadClasses();
31         System.out.println("....Classes reloaded");
32         hello = (Hello) db.objectForName(HelloServlet.OBJ_NAME);
33         if (hello == null) {
34             System.out.println("Storing new Hello object");
35             hello = (Hello) db.createObject(HelloImpl.class.getName(), OzoneInterface.Public, HelloServlet.OBJ_NAME);
36         } else {
37             System.out.println("Found existing Hello object");
38         }
39         System.out.println("db.Hello has the following greeting: " + hello.getGreeting());
40         db.close();
41     }
42 }
Popular Tags