1 9 package org.ozoneDB; 10 11 import org.ozoneDB.core.DbRemote.CommandThread; 12 import org.ozoneDB.core.DbRemote.DbXMLForObj; 13 import org.ozoneDB.core.*; 14 import org.ozoneDB.util.LogWriter; 15 import org.ozoneDB.xml.util.SAXChunkConsumer; 16 import org.w3c.dom.Document ; 17 import org.w3c.dom.Node ; 18 import org.xml.sax.ContentHandler ; 19 20 21 35 public final class Database extends AbstractDatabase { 36 37 protected transient Env env; 38 39 public Database(Env _env) { 40 this.env = _env; 41 AbstractFactory.setDefaultDatabase(this); 42 } 43 44 45 public void reloadClasses() throws Exception { 46 throw new Exception ("reloadClasses() must not be called from within the server."); 47 } 48 49 50 public User currentOwner() { 51 Thread thread = Thread.currentThread(); 52 57 if (thread instanceof CommandThread) { 58 return ((CommandThread) thread).owner(); 59 } else { 60 env.fatalError(this, "Current thread is not a transaction or command!", null); 61 return null; 62 } 63 } 64 65 66 public OzoneProxy createObject(String className,int access,String objName,String sig,Object [] args) throws RuntimeException ,OzoneObjectException { 67 env.logWriter.newEntry( this, "createObject()...", LogWriter.DEBUG3 ); 68 try { 69 ObjectContainer container = env.transactionManager.currentTA().createObject( className, access, objName, sig, args, null ); 70 71 try { 72 OzoneProxy result = container.ozoneProxy(); 73 return result; 75 } finally { 76 container.unpin(); 77 } 78 } catch (java.lang.reflect.InvocationTargetException e) { 79 throw new OzoneObjectException("Caught during deleteObject()", e); 80 } catch (OzoneObjectException e) { 81 throw e; 82 } catch (Exception e) { 83 env.logWriter.newEntry(this,"createObject(): caught",e,LogWriter.DEBUG3 ); 84 throw new RuntimeException ("Caught during createObject(): ", e); 85 } 86 } 87 88 89 public OzoneProxy copyObject(OzoneRemote rObj) throws Exception { 90 env.logWriter.newEntry(this, "copyObject()...", LogWriter.DEBUG3); 91 ObjectContainer container = env.transactionManager.currentTA().copyObject( ((OzoneProxy)rObj).remoteID() ); 92 try { 93 return container.ozoneProxy(); 94 } finally { 95 container.unpin(); 96 } 97 } 98 99 100 public void deleteObject( OzoneRemote rObj ) throws RuntimeException ,OzoneObjectException { 101 try { 102 if (false) { 103 env.logWriter.newEntry( this, "deleteObject()...", LogWriter.DEBUG3 ); 104 } 105 env.transactionManager.currentTA().deleteObject( ((OzoneProxy)rObj).remoteID() ); 106 } catch (OzoneObjectException e) { 107 throw e; 108 } catch (Exception e) { 109 throw new RuntimeException ("Caught during deleteObject(): ", e); 110 } 111 } 112 113 114 public void nameObject(OzoneRemote rObj, String name) throws Exception { 115 if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { 116 env.logWriter.newEntry(this, "nameObject()...", LogWriter.DEBUG3); 117 } 118 env.transactionManager.currentTA().nameObject(((OzoneProxy) rObj).remoteID(), name); 119 } 120 121 122 public String [] objectNames() throws Exception { 123 if (env.logWriter.hasTarget(LogWriter.DEBUG3)) { 124 env.logWriter.newEntry(this, "objectNames()...", LogWriter.DEBUG3); 125 } 126 Object [] keys = env.transactionManager.currentTA().objectNames().toArray(); 127 String [] names = new String [keys.length]; 128 for (int i = 0; i < keys.length; i++) { 129 names[i] = (String ) keys[i]; 130 } 131 return names; 132 } 133 134 public OzoneProxy objectForName(String name) throws Exception { 135 env.logWriter.newEntry(this, "objectForName()... ", LogWriter.DEBUG3); 136 return env.transactionManager.currentTA().objectForName(name); 137 } 138 139 public OzoneProxy objectForHandle(String handle) throws Exception { 140 env.logWriter.newEntry(this, "objectForHandle()... ", LogWriter.DEBUG3); 141 return env.transactionManager.currentTA().objectForID(new ObjectID(handle)); 142 } 143 144 public Object invoke(OzoneProxy rObj, String methodName, String sig, Object [] args, int lockLevel) 145 throws Exception { 146 147 for (int i = 0; i < args.length; i++) { 150 args[i] = ResultConverter.substituteOzoneCompatibles(args[i]); 151 } 152 153 Object result = env.transactionManager.currentTA().invokeObject(rObj.remoteID(), methodName, sig, args, lockLevel); 154 155 result = ResultConverter.substituteOzoneCompatibles(result); 157 158 return result; 159 } 160 161 162 public Object invoke(OzoneProxy rObj, int methodIndex, Object [] args, int lockLevel) throws Exception { 163 164 for (int i = 0; i < args.length; i++) { 167 args[i] = ResultConverter.substituteOzoneCompatibles(args[i]); 168 } 169 170 Object result = env.transactionManager.currentTA().invokeObject(rObj.remoteID(), methodIndex, args, lockLevel); 171 172 result = ResultConverter.substituteOzoneCompatibles(result); 174 175 return result; 176 } 177 178 179 public OzoneCompatible fetch(OzoneProxy rObj, int lockLevel) throws org.ozoneDB.ObjectNotFoundException, java.io.IOException , java.lang.ClassNotFoundException , org.ozoneDB.TransactionException, org.ozoneDB.core.TransactionError { 180 182 Transaction currentTransaction = getCurrentTransaction(); 183 ObjectID id = rObj.remoteID(); 184 185 ObjectContainer container = currentTransaction.acquireObject( id, lockLevel ); 186 187 try { 188 return container.target(); 189 } finally { 190 container.unpin(); 191 } 192 } 193 194 195 public Node xmlForObject(OzoneRemote rObj, Document domFactory) throws Exception { 196 197 DbXMLForObj command = new DbXMLForObj((OzoneProxy) rObj); 199 command.perform(env.transactionManager.currentTA()); 200 byte[] bytes = (byte[]) command.result; 201 202 SAXChunkConsumer consumer = new SAXChunkConsumer(domFactory, null); 203 consumer.processChunk(bytes); 204 205 return consumer.getResultNode(); 206 } 207 208 209 public void xmlForObject(OzoneRemote rObj, ContentHandler ch) throws Exception { 210 211 DbXMLForObj command = new DbXMLForObj((OzoneProxy) rObj); 213 command.perform(env.transactionManager.currentTA()); 214 byte[] bytes = (byte[]) command.result; 215 216 SAXChunkConsumer consumer = new SAXChunkConsumer(ch); 217 consumer.processChunk(bytes); 218 } 219 220 228 public void notifyProxyDeath(OzoneProxy proxy) { 229 } 231 232 235 public Env getEnv() { 236 return env; 237 } 238 239 242 public Transaction getCurrentTransaction() { 243 TransactionManager transactionManager = getEnv().getTransactionManager(); 244 Transaction currentTransaction = transactionManager.currentTA(); 245 246 return currentTransaction; 247 } 248 } 249 | Popular Tags |