KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > GarageApp


1 import java.util.*;
2 import org.ozoneDB.*;
3
4 public class GarageApp {
5     
6     public static void main( String JavaDoc[] args ) throws Exception JavaDoc {
7         
8         if (args.length == 0) {
9             System.out.println( "usage: ojvm GarageApp create|delete|oldtimers" );
10             System.exit( 1 );
11         }
12         
13         ExternalDatabase db = ExternalDatabase.openDatabase( "ozonedb:remote://localhost:3333" );
14         System.out.println( "Connected ..." );
15         
16         db.reloadClasses();
17         
18         if (args[0].equals( "create" )) {
19             db.createObject( GarageImpl.class.getName(), 0, "my_garage" );
20         
21         } else if (args[0].equals( "delete" )) {
22             Garage garage = (Garage)(db.objectForName( "my_garage" ));
23             if (garage != null) {
24                 db.deleteObject( garage );
25             }
26
27         } else if (args[0].equals( "add" )) {
28             Garage garage = (Garage)(db.objectForName( "my_garage" ));
29             if (garage != null) {
30                 garage.addCar_update( args[1], Integer.parseInt( args[2] ) );
31             } else {
32                 System.out.println( "Garage object not found!" );
33             }
34
35         } else if (args[0].equals( "oldtimer" )) {
36             Garage garage = (Garage)(db.objectForName( "my_garage" ));
37             if (garage != null) {
38                 System.out.println( "Oldtimers:" );
39                 Vector oldtimers = garage.oldtimers();
40                 for ( int i = 0; i < oldtimers.size(); i++ ) {
41                     Car car = (Car)(oldtimers.elementAt( i ));
42                     System.out.println( " Car " + car.name() + " age="
43                             + car.age() );
44                 }
45             } else {
46                 System.out.println( "Garage object not found!" );
47             }
48         } else {
49             System.out.println( "Unknown parameter: " + args[0] );
50         }
51         
52         db.close();
53     }
54 }
55
Popular Tags