KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > odmg > Client


1 // $Id: Client.java,v 1.3 2003/11/23 15:19:37 per_nyfelt Exp $
2
package odmg;
3
4 import org.odmg.*;
5 import org.ozoneDB.odmg.*;
6
7
8 /**
9  * This simple sample shows how to use the ODMG interface of ozone. The are
10  * a few things in the ozone ODMG interface that are not fully ODMG 3.0
11  * compliant. So, care must be taken when writing code against this API.<p>
12  *
13  * First, database objects do not implement any database specific interfaces.
14  * This means the actual database connection cannot be simple retrieved by
15  * calling the database() method of the database object.
16  *
17  *
18  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
19  * @version $Revision: 1.3 $Date: 2003/11/23 15:19:37 $
20  */

21 public class Client {
22     
23     public static ODMG odmg;
24     
25     
26     public static void main( String JavaDoc[] args ) throws Exception JavaDoc {
27         odmg = new OzoneODMG();
28         
29         EnhDatabase db = (EnhDatabase)odmg.newDatabase();
30         db.open( "ozonedb:remote://localhost:3333", Database.OPEN_READ_WRITE );
31         
32         Transaction tx = odmg.newTransaction();
33         tx.begin();
34         
35         Bus bus = new Bus( "bus" );
36         bus.print();
37         
38         Auto auto = null;
39         try {
40             auto = (Auto)db.lookup( "name" );
41         } catch (Exception JavaDoc e) {
42             // auto = new AutoImpl ("Name");
43
auto = (Auto)db.createPersistent( AutoImpl.class );
44             System.out.println( auto.getClass().getSuperclass().getName() );
45             System.out.println( Thread.currentThread().getName() + ": " + auto );
46             db.bind( auto, "name" );
47         }
48         
49         auto.setName( "Trabant" );
50         System.out.println( Thread.currentThread().getName() + ": " + auto );
51         
52         auto.doSomething();
53         
54         AccessThread t1 = new AccessThread( db, tx );
55         t1.start();
56         
57         Thread.sleep( 3000 );
58         
59         // db.deletePersistent (auto);
60

61         tx.commit();
62         
63         db.close();
64     }
65 }
66
Popular Tags