KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > odmg > OzoneServerODMGDatabase


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by softwarebuero m&b (SMB).
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-1999 by softwarebuero m&b (SMB). All rights reserved.
6
//
7
// $Id: OzoneServerODMGDatabase.java,v 1.1 2001/12/18 10:31:31 per_nyfelt Exp $
8

9 package org.ozoneDB.odmg;
10
11 import java.util.*;
12 import org.odmg.*;
13 import org.ozoneDB.OzoneInterface;
14 import org.ozoneDB.ExternalDatabase;
15 import org.ozoneDB.LocalDatabase;
16 import org.ozoneDB.RemoteDatabase;
17 import org.ozoneDB.OzoneProxy;
18 import org.ozoneDB.OzoneRemote;
19 import org.ozoneDB.OzoneCompatible;
20
21
22 /**
23  * Implementation of the ODMG {@link org.odmg.Database} interface that is used
24  * inside the ozone server to give the ODMG database objects their environment
25  * and their interface to the database.
26  *
27  *
28  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
29  * @version $Revision: 1.1 $Date: 2001/12/18 10:31:31 $
30  */

31 public class OzoneServerODMGDatabase implements EnhDatabase {
32     
33     private int accessMode = OPEN_READ_WRITE;
34     
35     private org.ozoneDB.core.Env env;
36     
37     
38     public OzoneServerODMGDatabase() {
39         env = org.ozoneDB.core.Env.currentEnv();
40     }
41     
42     
43     protected int mode() {
44         return accessMode;
45     }
46     
47     
48     /**
49      * Open this ODMG database.
50      * @param _url URL of the database (ozonedb:remote://host:port or ozonedb:local://datadir)
51      */

52     public synchronized void open( String JavaDoc _url, int _accessMode ) throws ODMGException {
53         throw new ODMGRuntimeException( "Method must not be called." );
54     }
55     
56     
57     public void close() throws ODMGException {
58         throw new ODMGRuntimeException( "Method must not be called." );
59     }
60     
61     
62     protected void finalize() throws Throwable JavaDoc {
63     }
64     
65     
66     public void makePersistent( Object JavaDoc object ) {
67         throw new ODMGRuntimeException( "Method must not be called." );
68     }
69     
70     
71     public Object JavaDoc createPersistent( Class JavaDoc cl ) {
72         if (cl.isAssignableFrom( OzoneCompatible.class )) {
73             throw new ClassNotPersistenceCapableException( cl.getName() );
74         }
75         
76         try {
77             return env.database.createObject( cl.getName(), OzoneInterface.Public, null );
78         } catch (Exception JavaDoc e) {
79             throw new ODMGRuntimeException( e.toString() );
80         }
81     }
82     
83     
84     public void deletePersistent( Object JavaDoc object ) {
85         if (!(object instanceof OzoneProxy)) {
86             throw new ObjectNotPersistentException( object.getClass().getName() );
87         }
88         
89         try {
90             env.database.deleteObject( (OzoneRemote)object );
91         } catch (Exception JavaDoc e) {
92             throw new ODMGRuntimeException( e.toString() );
93         }
94     }
95     
96     
97     public void bind( Object JavaDoc object, String JavaDoc name ) {
98         if (!(object instanceof OzoneProxy)) {
99             throw new ClassNotPersistenceCapableException( object.getClass().getName() );
100         }
101         
102         try {
103             env.database.nameObject( (OzoneRemote)object, name );
104         } catch (Exception JavaDoc e) {
105             throw new ODMGRuntimeException( e.toString() );
106         }
107     }
108     
109     
110     public void unbind( String JavaDoc name ) throws ObjectNameNotFoundException {
111         try {
112             Object JavaDoc obj = lookup( name );
113             if (obj != null) {
114                 env.database.nameObject( (OzoneRemote)obj, null );
115             }
116         } catch (Exception JavaDoc e) {
117             throw new ODMGRuntimeException( e.toString() );
118         }
119     }
120     
121     
122     public Object JavaDoc lookup( String JavaDoc name ) throws ObjectNameNotFoundException {
123         Object JavaDoc result = null;
124         try {
125             result = env.database.objectForName( name );
126         } catch (Exception JavaDoc e) {
127             throw new ODMGRuntimeException( e.toString() );
128         }
129         
130         if (result == null) {
131             throw new ObjectNameNotFoundException( name );
132         }
133         
134         return result;
135     }
136     
137     
138     public boolean containsObject( Object JavaDoc obj ) {
139         if (!(obj instanceof OzoneProxy)) {
140             throw new ClassNotPersistenceCapableException( obj.getClass().getName() );
141         }
142         
143         OzoneProxy proxy = (OzoneProxy)obj;
144         return proxy.link == env.database;
145     }
146     
147 }
148
Popular Tags