1 9 package org.ozoneDB; 10 11 import org.ozoneDB.core.Transaction; 12 13 import javax.naming.*; 14 import java.io.IOException ; 15 import java.rmi.Remote ; 16 import java.util.Hashtable ; 17 18 19 43 public final class ExternalTransaction 44 extends AbstractTransaction 45 implements Referenceable { 46 47 49 50 public final static int STATUS_NONE = 1; 51 52 53 public final static int STATUS_ACTIVE = 2; 54 55 56 public final static int STATUS_PREPARING = 3; 57 58 59 public final static int STATUS_PREPARED = 4; 60 61 62 public final static int STATUS_COMMITING = 5; 63 64 65 public final static int STATUS_COMMITED = 6; 66 67 68 public final static int STATUS_ROLLINGBACK = 7; 69 70 71 public final static int STATUS_ROLLEDBACK = 8; 72 73 75 protected boolean rollbackOnly = false; 76 77 78 public ExternalTransaction( ExternalDatabase _database ) { 79 super( _database ); 80 } 81 82 83 92 public void begin() throws TransactionException, IOException { 93 database.beginTX( this ); 94 } 95 96 97 101 public void join() throws TransactionException, IOException { 102 if (database instanceof LocalDatabase) { 103 throw new RuntimeException ( "Operation not supported: join() on LocalDatabase's." ); 109 } 110 else { 111 database.leaveTX( this ); 112 database.joinTX( this ); 113 } 114 } 115 116 117 121 public void leave() throws TransactionException, IOException { 122 database.leaveTX( this ); 123 } 124 125 126 130 public void prepare() throws TransactionException, IOException { 131 if (rollbackOnly) { 132 database.rollbackTX( this ); 133 throw new TransactionException( "Transaction was set to rollback only.", TransactionException.ROLLBACK ); 134 } else { 135 database.prepareTX( this ); 137 } 138 } 139 140 141 146 public void commit() throws TransactionException, IOException { 147 commit( true ); 148 } 149 150 151 156 public void commit( boolean onePhase ) throws TransactionException, IOException { 157 if (rollbackOnly) { 158 database.rollbackTX( this ); 159 throw new TransactionException( "Transaction was set to rollback only.", TransactionException.ROLLBACK ); 160 } else { 161 database.commitTX( this, onePhase ); 163 } 164 } 165 166 167 171 public void checkpoint() throws TransactionException, IOException { 172 database.checkpointTX( this ); 173 } 174 175 176 184 public void rollback() throws TransactionException, IOException { 185 database.rollbackTX( this ); 186 } 187 188 189 193 public synchronized void setRollbackOnly() throws TransactionException, IOException { 194 rollbackOnly = true; 195 } 196 197 198 201 public int getStatus() throws TransactionException, IOException { 202 int internal = database.getStatusTX( this ); 203 204 switch (internal) { 207 case Transaction.STATUS_NONE: 208 return STATUS_NONE; 209 case Transaction.STATUS_STARTED: 210 return STATUS_ACTIVE; 211 case Transaction.STATUS_PREPARING: 212 return STATUS_PREPARING; 213 case Transaction.STATUS_PREPARED: 214 return STATUS_PREPARED; 215 case Transaction.STATUS_COMMITING: 216 return STATUS_COMMITING; 217 case Transaction.STATUS_COMMITED: 218 return STATUS_COMMITED; 219 case Transaction.STATUS_ABORTING: 220 return STATUS_ROLLINGBACK; 221 case Transaction.STATUS_ABORTED: 222 return STATUS_ROLLEDBACK; 223 default: 224 throw new RuntimeException ( "Unknown internal transaction status." ); 225 } 226 } 227 228 229 240 public void setTransactionTimeout( int seconds ) throws TransactionException, IOException { 241 throw new RuntimeException ( "setTransactionTimeout() is not yet implemented." ); 242 } 243 244 245 247 248 252 public Reference getReference() throws NamingException { 253 throw new RuntimeException ( "getReference() is not yet implemented." ); 254 255 } 270 271 272 public Object getObjectInstance( Object refObj, Name name, Context nameCtx, Hashtable env ) { 273 274 if (refObj instanceof Reference) { 276 return this; 277 } else if (refObj instanceof Remote ) { 278 return refObj; 279 } else { 280 return null; 281 } 282 } 283 284 285 public static ExternalTransaction getInstance() { 286 throw new RuntimeException ( "ExternalTransaction.getInstance() not implemented yet." ); 287 } 289 290 } 291 | Popular Tags |