01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: ODMG.java,v 1.1 2002/05/08 15:03:21 per_nyfelt Exp $
08:
09: package org.ozoneDB.odmg;
10:
11: import java.io.*;
12: import org.odmg.*;
13: import org.ozoneDB.DxLib.*;
14:
15: /**
16: * This abstract class enhances the original ODMG {@link Implementation} interface
17: * by a standard way to obtain the database of a given object. The newly
18: * introduced static method allows to obtain the database for a given object
19: * without the need to know the actual {@link Implementation} factory object. This
20: * is particularly useful for ozone, where database object do not have access to
21: * the client side logic and variables.<p>
22: *
23: * {@link OzoneODMG} does already implement this interface. Wrappers for other
24: * ODMG database systems just need to make sure to call the default ctor of the
25: * underlying class.
26: *
27: *
28: * @author <a href="http://www.softwarebuero.de/">SMB</a> @version
29: * $Revision: 1.1 $Date: 2002/05/08 15:03:21 $
30: */
31: public abstract class ODMG implements Implementation {
32:
33: private static DxBag factories;
34:
35: private static EnhDatabase theServerSideODMGDatabase;
36:
37: static {
38: // are we inside the server...
39: if (org.ozoneDB.core.Env.currentEnv() != null) {
40: theServerSideODMGDatabase = new OzoneServerODMGDatabase();
41: } else {
42: // ...or inside the client
43: factories = new DxArrayBag();
44: }
45: }
46:
47: public static Database getDatabase2(Object obj) {
48: // are we inside the server...
49: if (theServerSideODMGDatabase != null) {
50: return theServerSideODMGDatabase;
51: } else {
52: // ...or inside the client
53: ODMG odmg = null;
54: DxIterator it = factories.iterator();
55: while ((odmg = (ODMG) it.next()) != null) {
56: Database db = odmg.getDatabase(obj);
57: if (db != null) {
58: return db;
59: }
60: }
61: return null;
62: }
63: }
64:
65: public ODMG() {
66: factories.add(this);
67: }
68:
69: }
|