001: // You can redistribute this software and/or modify it under the terms of
002: // the Ozone Library License version 1 published by softwarebuero m&b (SMB).
003: //
004: // The original code and portions created by SMB are
005: // Copyright (C) 1997-1999 by softwarebuero m&b (SMB). All rights reserved.
006: //
007: // $Id: OzoneServerODMGDatabase.java,v 1.1 2002/05/08 15:03:21 per_nyfelt Exp $
008:
009: package org.ozoneDB.odmg;
010:
011: import java.util.*;
012: import org.odmg.*;
013: import org.ozoneDB.OzoneInterface;
014: import org.ozoneDB.ExternalDatabase;
015: import org.ozoneDB.LocalDatabase;
016: import org.ozoneDB.RemoteDatabase;
017: import org.ozoneDB.OzoneProxy;
018: import org.ozoneDB.OzoneRemote;
019: import org.ozoneDB.OzoneCompatible;
020:
021: /**
022: * Implementation of the ODMG {@link org.odmg.Database} interface that is used
023: * inside the ozone server to give the ODMG database objects their environment
024: * and their interface to the database.
025: *
026: *
027: * @author <a href="http://www.softwarebuero.de/">SMB</a>
028: * @version $Revision: 1.1 $Date: 2002/05/08 15:03:21 $
029: */
030: public class OzoneServerODMGDatabase implements EnhDatabase {
031:
032: private int accessMode = OPEN_READ_WRITE;
033:
034: private org.ozoneDB.core.Env env;
035:
036: public OzoneServerODMGDatabase() {
037: env = org.ozoneDB.core.Env.currentEnv();
038: }
039:
040: protected int mode() {
041: return accessMode;
042: }
043:
044: /**
045: * Open this ODMG database.
046: * @param _url URL of the database (ozonedb:remote://host:port or ozonedb:local://datadir)
047: */
048: public synchronized void open(String _url, int _accessMode)
049: throws ODMGException {
050: throw new ODMGRuntimeException("Method must not be called.");
051: }
052:
053: public void close() throws ODMGException {
054: throw new ODMGRuntimeException("Method must not be called.");
055: }
056:
057: protected void finalize() throws Throwable {
058: }
059:
060: public void makePersistent(Object object) {
061: throw new ODMGRuntimeException("Method must not be called.");
062: }
063:
064: public Object createPersistent(Class cl) {
065: if (cl.isAssignableFrom(OzoneCompatible.class)) {
066: throw new ClassNotPersistenceCapableException(cl.getName());
067: }
068:
069: try {
070: return env.database.createObject(cl.getName(),
071: OzoneInterface.Public, null);
072: } catch (Exception e) {
073: throw new ODMGRuntimeException(e.toString());
074: }
075: }
076:
077: public void deletePersistent(Object object) {
078: if (!(object instanceof OzoneProxy)) {
079: throw new ObjectNotPersistentException(object.getClass()
080: .getName());
081: }
082:
083: try {
084: env.database.deleteObject((OzoneRemote) object);
085: } catch (Exception e) {
086: throw new ODMGRuntimeException(e.toString());
087: }
088: }
089:
090: public void bind(Object object, String name) {
091: if (!(object instanceof OzoneProxy)) {
092: throw new ClassNotPersistenceCapableException(object
093: .getClass().getName());
094: }
095:
096: try {
097: env.database.nameObject((OzoneRemote) object, name);
098: } catch (Exception e) {
099: throw new ODMGRuntimeException(e.toString());
100: }
101: }
102:
103: public void unbind(String name) throws ObjectNameNotFoundException {
104: try {
105: Object obj = lookup(name);
106: if (obj != null) {
107: env.database.nameObject((OzoneRemote) obj, null);
108: }
109: } catch (Exception e) {
110: throw new ODMGRuntimeException(e.toString());
111: }
112: }
113:
114: public Object lookup(String name)
115: throws ObjectNameNotFoundException {
116: Object result = null;
117: try {
118: result = env.database.objectForName(name);
119: } catch (Exception e) {
120: throw new ODMGRuntimeException(e.toString());
121: }
122:
123: if (result == null) {
124: throw new ObjectNameNotFoundException(name);
125: }
126:
127: return result;
128: }
129:
130: public boolean containsObject(Object obj) {
131: if (!(obj instanceof OzoneProxy)) {
132: throw new ClassNotPersistenceCapableException(obj
133: .getClass().getName());
134: }
135:
136: OzoneProxy proxy = (OzoneProxy) obj;
137: return proxy.link == env.database;
138: }
139:
140: }
|