KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > MyApp


1 import org.ozoneDB.*;
2
3 public class MyApp {
4     
5     private static ExternalDatabase db;
6
7     public static void main( String JavaDoc[] args ) throws Exception JavaDoc {
8
9         if (args.length == 0) {
10             System.out.println( "usage: ojvm MyApp create|delete|print" );
11             System.exit( 1 );
12         }
13         
14         // create and open a new database connection
15
db = ExternalDatabase.openDatabase( "ozonedb:remote://localhost:3333" );
16         System.out.println( "Connected ..." );
17         
18         db.reloadClasses();
19         
20         if (args[0].equals( "create" )) {
21             createCar();
22         } else if (args[0].equals( "delete" )) {
23             deleteCar();
24         } else {
25             printCar();
26         }
27         
28         db.close();
29     }
30
31     public static void createCar() throws Exception JavaDoc {
32         // create a new Car object with the name "my_first_car"
33
// the return value is Car_proxy, which implements the Car-interface
34
Car car = (Car)(db.createObject( CarImpl.class.getName(), 0,
35                 "my_first_car" ));
36         
37         car.setName( "gottfried" );
38         car.setYearOfConst( 1957 );
39     }
40
41     public static void printCar() throws Exception JavaDoc {
42         Car car = (Car)(db.objectForName( "my_first_car" ));
43         if (car != null) {
44             System.out.println( "The car " + car.name() + " is "
45                     + car.age() + " years old." );
46         } else {
47             System.out.println( "Object my_first_car not found." );
48         }
49     }
50     
51     public static void deleteCar() throws Exception JavaDoc {
52         Car car = (Car)(db.objectForName( "my_first_car" ));
53         if (car != null) {
54             db.deleteObject( car );
55         } else {
56             System.out.println( "Object my_first_car not found." );
57         }
58     }
59 }
60
Popular Tags