001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by ozone-db.org.
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
006: //
007: // $Id: OzoneODMG.java,v 1.1 2002/05/08 15:03:21 per_nyfelt Exp $
008:
009: package org.ozoneDB.odmg;
010:
011: import java.io.*;
012: import org.odmg.*;
013: import org.ozoneDB.DxLib.*;
014:
015: /**
016: * Implementation of the ODMG {@link Implementation} interface.
017: *
018: *
019: * @author <a href="http://www.softwarebuero.de/">SMB</a>
020: * @version $Revision: 1.1 $Date: 2002/05/08 15:03:21 $
021: */
022: public class OzoneODMG extends ODMG {
023:
024: /**
025: * All {@link OzoneDatabase} objects that are created by this factory and
026: * that currently are open.
027: */
028: private transient DxSet dbs;
029:
030: public OzoneODMG() {
031: if (org.ozoneDB.core.Env.currentEnv() != null) {
032: throw new ODMGRuntimeException(
033: "Method must not be called from inside an ozone database object.");
034: }
035: dbs = new DxHashSet();
036: }
037:
038: /**
039: * Create a new <code>Database</code> object.
040: * @return The new <code>Database</code> object.
041: * @see org.odmg.Database
042: */
043: public synchronized Database newDatabase() {
044: if (org.ozoneDB.core.Env.currentEnv() != null) {
045: throw new ODMGRuntimeException(
046: "Method must not be called from inside an ozone database object.");
047: }
048: Database db = new OzoneODMGDatabase(this );
049: return db;
050: }
051:
052: /**
053: * This method is called by the database objects to inform their factory
054: * that another database actually has been opened.
055: */
056: protected synchronized void databaseOpened(Database db) {
057: // don't allow more than one database per factory; the code to support
058: // this is there but this feature avoid determine the database of a
059: // given thread which is important for the enhanced ozone version of
060: // the ODMG Implementation interface
061: if (dbs.count() > 0) {
062: throw new ODMGRuntimeException(
063: "More than one open databases per factory are not allowed.");
064: }
065:
066: dbs.add(db);
067: }
068:
069: protected synchronized void databaseClosed(Database db) {
070: dbs.remove(db);
071: }
072:
073: /**
074: * Get the <code>Database</code> that contains the object <code>obj</code>.
075: * @param obj The object.
076: * @return The <code>Database</code> that contains the object.
077: */
078: public Database getDatabase(Object obj) {
079: if (org.ozoneDB.core.Env.currentEnv() != null) {
080: throw new ODMGRuntimeException(
081: "Method must not be called from inside an ozone database object.");
082: }
083:
084: DxIterator it = dbs.iterator();
085: while (it.next() != null) {
086: OzoneODMGDatabase db = (OzoneODMGDatabase) it.object();
087: if (db.containsObject(obj)) {
088: return db;
089: }
090: }
091: return null;
092: }
093:
094: /**
095: * Create a <code>Transaction</code> object and associate it with the
096: * current thread.
097: * @return The newly created <code>Transaction</code> instance.
098: * @see org.odmg.Transaction
099: */
100: public Transaction newTransaction() {
101: if (org.ozoneDB.core.Env.currentEnv() != null) {
102: throw new ODMGRuntimeException(
103: "Method must not be called from inside an ozone database object.");
104: }
105: return new OzoneODMGTransaction(dbs);
106: }
107:
108: /**
109: * Get the current <code>Transaction</code> for the thread.
110: * @return The current <code>Transaction</code> object or null if there is none.
111: * @see org.odmg.Transaction
112: */
113: public Transaction currentTransaction() {
114: if (org.ozoneDB.core.Env.currentEnv() != null) {
115: throw new ODMGRuntimeException(
116: "Method must not be called from inside an ozone database object.");
117: }
118: return OzoneODMGTransaction.current();
119: }
120:
121: /**
122: * Get a <code>String</code> representation of the object's identifier.
123: * @param obj The object whose identifier is being accessed.
124: * @return The object's identifier in the form of a String
125: */
126: public String getObjectId(Object obj) {
127: if (org.ozoneDB.core.Env.currentEnv() != null) {
128: throw new ODMGRuntimeException(
129: "Method must not be called from inside an ozone database object.");
130: }
131:
132: throw new RuntimeException("Method not implemented yet.");
133: }
134:
135: /**
136: * Create a new <code>OQLQuery</code> object.
137: * @return The new <code>OQLQuery</code> object.
138: * @see org.odmg.OQLQuery
139: */
140: public OQLQuery newOQLQuery() {
141: throw new RuntimeException(
142: "newOQLQuery(): ozone does not implement OQL.");
143: }
144:
145: /**
146: * Create a new <code>DList</code> object.
147: * @return The new <code>DList</code> object.
148: * @see org.odmg.DList
149: */
150: public DList newDList() {
151: if (org.ozoneDB.core.Env.currentEnv() != null) {
152: throw new ODMGRuntimeException(
153: "Method must not be called from inside an ozone database object.");
154: }
155: return new OzoneODMGDList();
156: }
157:
158: /**
159: * Create a new <code>DBag</code> object.
160: * @return The new <code>DBag</code> object.
161: * @see org.odmg.DBag
162: */
163: public DBag newDBag() {
164: if (org.ozoneDB.core.Env.currentEnv() != null) {
165: throw new ODMGRuntimeException(
166: "Method must not be called from inside an ozone database object.");
167: }
168: return new OzoneODMGDBag();
169: }
170:
171: /**
172: * Create a new <code>DSet</code> object.
173: * @return The new <code>DSet</code> object.
174: * @see org.odmg.DSet
175: */
176: public DSet newDSet() {
177: if (org.ozoneDB.core.Env.currentEnv() != null) {
178: throw new ODMGRuntimeException(
179: "Method must not be called from inside an ozone database object.");
180: }
181: return new OzoneODMGDSet();
182: }
183:
184: /**
185: * Create a new <code>DArray</code> object.
186: * @return The new <code>DArray</code> object.
187: * @see org.odmg.DArray
188: */
189: public DArray newDArray() {
190: if (org.ozoneDB.core.Env.currentEnv() != null) {
191: throw new ODMGRuntimeException(
192: "Method must not be called from inside an ozone database object.");
193: }
194: return new OzoneODMGDArray();
195: }
196:
197: /**
198: * Create a new <code>DMap</code> object.
199: * @return The new <code>DMap</code> object.
200: * @see org.odmg.DMap
201: */
202: public DMap newDMap() {
203: throw new RuntimeException("Method not implemented yet");
204: }
205:
206: }
|