KickJava   Java API By Example, From Geeks To Geeks.

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


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

9 package org.ozoneDB.odmg;
10
11 import java.io.*;
12 import org.odmg.*;
13 import org.ozoneDB.DxLib.*;
14
15
16 /**
17  * Implementation of the ODMG {@link Implementation} interface.
18  *
19  *
20  * @author <a HREF="http://www.softwarebuero.de/">SMB</a>
21  * @version $Revision: 1.1 $Date: 2001/12/18 10:31:31 $
22  */

23 public class OzoneODMG extends ODMG {
24     
25     /**
26      * All {@link OzoneDatabase} objects that are created by this factory and
27      * that currently are open.
28      */

29     private transient DxSet dbs;
30     
31     
32     public OzoneODMG() {
33         if (org.ozoneDB.core.Env.currentEnv() != null) {
34             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
35         }
36         dbs = new DxHashSet();
37     }
38     
39     
40     /**
41      * Create a new <code>Database</code> object.
42      * @return The new <code>Database</code> object.
43      * @see org.odmg.Database
44      */

45     public synchronized Database newDatabase() {
46         if (org.ozoneDB.core.Env.currentEnv() != null) {
47             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
48         }
49         Database db = new OzoneODMGDatabase( this );
50         return db;
51     }
52     
53     
54     /**
55      * This method is called by the database objects to inform their factory
56      * that another database actually has been opened.
57      */

58     protected synchronized void databaseOpened( Database db ) {
59         // don't allow more than one database per factory; the code to support
60
// this is there but this feature avoid determine the database of a
61
// given thread which is important for the enhanced ozone version of
62
// the ODMG Implementation interface
63
if (dbs.count() > 0) {
64             throw new ODMGRuntimeException( "More than one open databases per factory are not allowed." );
65         }
66         
67         dbs.add( db );
68     }
69     
70     
71     protected synchronized void databaseClosed( Database db ) {
72         dbs.remove( db );
73     }
74     
75     
76     /**
77      * Get the <code>Database</code> that contains the object <code>obj</code>.
78      * @param obj The object.
79      * @return The <code>Database</code> that contains the object.
80      */

81     public Database getDatabase( Object JavaDoc obj ) {
82         if (org.ozoneDB.core.Env.currentEnv() != null) {
83             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
84         }
85         
86         DxIterator it = dbs.iterator();
87         while (it.next() != null) {
88             OzoneODMGDatabase db = (OzoneODMGDatabase)it.object();
89             if (db.containsObject( obj )) {
90                 return db;
91             }
92         }
93         return null;
94     }
95     
96     
97     /**
98      * Create a <code>Transaction</code> object and associate it with the
99      * current thread.
100      * @return The newly created <code>Transaction</code> instance.
101      * @see org.odmg.Transaction
102      */

103     public Transaction newTransaction() {
104         if (org.ozoneDB.core.Env.currentEnv() != null) {
105             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
106         }
107         return new OzoneODMGTransaction( dbs );
108     }
109     
110     
111     /**
112      * Get the current <code>Transaction</code> for the thread.
113      * @return The current <code>Transaction</code> object or null if there is none.
114      * @see org.odmg.Transaction
115      */

116     public Transaction currentTransaction() {
117         if (org.ozoneDB.core.Env.currentEnv() != null) {
118             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
119         }
120         return OzoneODMGTransaction.current();
121     }
122     
123     
124     /**
125      * Get a <code>String</code> representation of the object's identifier.
126      * @param obj The object whose identifier is being accessed.
127      * @return The object's identifier in the form of a String
128      */

129     public String JavaDoc getObjectId( Object JavaDoc obj ) {
130         if (org.ozoneDB.core.Env.currentEnv() != null) {
131             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
132         }
133         
134         throw new RuntimeException JavaDoc( "Method not implemented yet." );
135     }
136     
137     
138     /**
139      * Create a new <code>OQLQuery</code> object.
140      * @return The new <code>OQLQuery</code> object.
141      * @see org.odmg.OQLQuery
142      */

143     public OQLQuery newOQLQuery() {
144         throw new RuntimeException JavaDoc( "newOQLQuery(): ozone does not implement OQL." );
145     }
146     
147     
148     /**
149      * Create a new <code>DList</code> object.
150      * @return The new <code>DList</code> object.
151      * @see org.odmg.DList
152      */

153     public DList newDList() {
154         if (org.ozoneDB.core.Env.currentEnv() != null) {
155             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
156         }
157         return new OzoneODMGDList();
158     }
159     
160     
161     /**
162      * Create a new <code>DBag</code> object.
163      * @return The new <code>DBag</code> object.
164      * @see org.odmg.DBag
165      */

166     public DBag newDBag() {
167         if (org.ozoneDB.core.Env.currentEnv() != null) {
168             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
169         }
170         return new OzoneODMGDBag();
171     }
172     
173     
174     /**
175      * Create a new <code>DSet</code> object.
176      * @return The new <code>DSet</code> object.
177      * @see org.odmg.DSet
178      */

179     public DSet newDSet() {
180         if (org.ozoneDB.core.Env.currentEnv() != null) {
181             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
182         }
183         return new OzoneODMGDSet();
184     }
185     
186     
187     /**
188      * Create a new <code>DArray</code> object.
189      * @return The new <code>DArray</code> object.
190      * @see org.odmg.DArray
191      */

192     public DArray newDArray() {
193         if (org.ozoneDB.core.Env.currentEnv() != null) {
194             throw new ODMGRuntimeException( "Method must not be called from inside an ozone database object." );
195         }
196         return new OzoneODMGDArray();
197     }
198     
199     
200     /**
201      * Create a new <code>DMap</code> object.
202      * @return The new <code>DMap</code> object.
203      * @see org.odmg.DMap
204      */

205     public DMap newDMap() {
206         throw new RuntimeException JavaDoc( "Method not implemented yet" );
207     }
208     
209 }
210
Popular Tags