예제 #1
0
 /** {@inheritDoc} */
 public void prepare(byte[] gid) {
   try {
     xid = new SimpleXid(gid);
     env.setXATransaction(xid, txn);
     env.prepare(xid);
   } catch (DatabaseException e) {
     throw JeEnvironment.convertException(e, false);
   } catch (XAException e) {
     throw JeEnvironment.convertException(e, false);
   }
 }
예제 #2
0
 /** {@inheritDoc} */
 public void abort() {
   try {
     if (xid != null) {
       env.rollback(xid);
     } else {
       txn.abort();
     }
   } catch (DatabaseException e) {
     throw JeEnvironment.convertException(e, false);
   } catch (XAException e) {
     throw JeEnvironment.convertException(e, false);
   }
 }
예제 #3
0
 /** {@inheritDoc} */
 public void commit() {
   try {
     if (xid != null) {
       env.commit(xid, true /* ignored */);
     } else {
       txn.commit();
     }
   } catch (DatabaseException e) {
     throw JeEnvironment.convertException(e, false);
   } catch (XAException e) {
     throw JeEnvironment.convertException(e, false);
   }
 }
예제 #4
0
 /**
  * Creates an instance of this class.
  *
  * @param env the Berkeley DB environment
  * @param timeout the number of milliseconds the transaction should be allowed to run
  * @throws IllegalArgumentException if timeout is less than {@code 1}
  * @throws DbDatabaseException if an unexpected database problem occurs
  */
 JeTransaction(XAEnvironment env, long timeout) {
   this.env = env;
   if (timeout <= 0) {
     throw new IllegalArgumentException("Timeout must be greater than 0");
   }
   try {
     txn = env.beginTransaction(null, null);
     /* Avoid overflow -- BDB treats 0 as unlimited */
     long timeoutMicros = (timeout < (Long.MAX_VALUE / 1000)) ? timeout * 1000 : 0;
     txn.setTxnTimeout(timeoutMicros);
   } catch (DatabaseException e) {
     throw JeEnvironment.convertException(e, false);
   }
 }