1 9 package org.ozoneDB.odmg; 10 11 import java.util.*; 12 import org.odmg.*; 13 import org.ozoneDB.OzoneInterface; 14 import org.ozoneDB.ExternalDatabase; 15 import org.ozoneDB.LocalDatabase; 16 import org.ozoneDB.RemoteDatabase; 17 import org.ozoneDB.OzoneProxy; 18 import org.ozoneDB.OzoneRemote; 19 import org.ozoneDB.OzoneCompatible; 20 21 22 31 public class OzoneServerODMGDatabase implements EnhDatabase { 32 33 private int accessMode = OPEN_READ_WRITE; 34 35 private org.ozoneDB.core.Env env; 36 37 38 public OzoneServerODMGDatabase() { 39 env = org.ozoneDB.core.Env.currentEnv(); 40 } 41 42 43 protected int mode() { 44 return accessMode; 45 } 46 47 48 52 public synchronized void open( String _url, int _accessMode ) throws ODMGException { 53 throw new ODMGRuntimeException( "Method must not be called." ); 54 } 55 56 57 public void close() throws ODMGException { 58 throw new ODMGRuntimeException( "Method must not be called." ); 59 } 60 61 62 protected void finalize() throws Throwable { 63 } 64 65 66 public void makePersistent( Object object ) { 67 throw new ODMGRuntimeException( "Method must not be called." ); 68 } 69 70 71 public Object createPersistent( Class cl ) { 72 if (cl.isAssignableFrom( OzoneCompatible.class )) { 73 throw new ClassNotPersistenceCapableException( cl.getName() ); 74 } 75 76 try { 77 return env.database.createObject( cl.getName(), OzoneInterface.Public, null ); 78 } catch (Exception e) { 79 throw new ODMGRuntimeException( e.toString() ); 80 } 81 } 82 83 84 public void deletePersistent( Object object ) { 85 if (!(object instanceof OzoneProxy)) { 86 throw new ObjectNotPersistentException( object.getClass().getName() ); 87 } 88 89 try { 90 env.database.deleteObject( (OzoneRemote)object ); 91 } catch (Exception e) { 92 throw new ODMGRuntimeException( e.toString() ); 93 } 94 } 95 96 97 public void bind( Object object, String name ) { 98 if (!(object instanceof OzoneProxy)) { 99 throw new ClassNotPersistenceCapableException( object.getClass().getName() ); 100 } 101 102 try { 103 env.database.nameObject( (OzoneRemote)object, name ); 104 } catch (Exception e) { 105 throw new ODMGRuntimeException( e.toString() ); 106 } 107 } 108 109 110 public void unbind( String name ) throws ObjectNameNotFoundException { 111 try { 112 Object obj = lookup( name ); 113 if (obj != null) { 114 env.database.nameObject( (OzoneRemote)obj, null ); 115 } 116 } catch (Exception e) { 117 throw new ODMGRuntimeException( e.toString() ); 118 } 119 } 120 121 122 public Object lookup( String name ) throws ObjectNameNotFoundException { 123 Object result = null; 124 try { 125 result = env.database.objectForName( name ); 126 } catch (Exception e) { 127 throw new ODMGRuntimeException( e.toString() ); 128 } 129 130 if (result == null) { 131 throw new ObjectNameNotFoundException( name ); 132 } 133 134 return result; 135 } 136 137 138 public boolean containsObject( Object obj ) { 139 if (!(obj instanceof OzoneProxy)) { 140 throw new ClassNotPersistenceCapableException( obj.getClass().getName() ); 141 } 142 143 OzoneProxy proxy = (OzoneProxy)obj; 144 return proxy.link == env.database; 145 } 146 147 } 148 | Popular Tags |