KickJava   Java API By Example, From Geeks To Geeks.

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


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: ODMG.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  * This abstract class enhances the original ODMG {@link Implementation} interface
18  * by a standard way to obtain the database of a given object. The newly
19  * introduced static method allows to obtain the database for a given object
20  * without the need to know the actual {@link Implementation} factory object. This
21  * is particularly useful for ozone, where database object do not have access to
22  * the client side logic and variables.<p>
23  *
24  * {@link OzoneODMG} does already implement this interface. Wrappers for other
25  * ODMG database systems just need to make sure to call the default ctor of the
26  * underlying class.
27  *
28  *
29  * @author <a HREF="http://www.softwarebuero.de/">SMB</a> @version
30  * $Revision: 1.1 $Date: 2001/12/18 10:31:31 $
31  */

32 public abstract class ODMG implements Implementation {
33     
34     private static DxBag factories;
35     
36     private static EnhDatabase theServerSideODMGDatabase;
37     
38     
39     static {
40         // are we inside the server...
41
if (org.ozoneDB.core.Env.currentEnv() != null) {
42             theServerSideODMGDatabase = new OzoneServerODMGDatabase();
43         } else {
44             // ...or inside the client
45
factories = new DxArrayBag();
46         }
47     }
48     
49     
50     public static Database getDatabase2( Object JavaDoc obj ) {
51         // are we inside the server...
52
if (theServerSideODMGDatabase != null) {
53             return theServerSideODMGDatabase;
54         } else {
55             // ...or inside the client
56
ODMG odmg = null;
57             DxIterator it = factories.iterator();
58             while ((odmg = (ODMG)it.next()) != null) {
59                 Database db = odmg.getDatabase( obj );
60                 if (db != null) {
61                     return db;
62                 }
63             }
64             return null;
65         }
66     }
67     
68     
69     public ODMG() {
70         factories.add( this );
71     }
72     
73 }
74
Popular Tags