Exemple #1
0
 @Override
 public synchronized void afterCompletion(int status) {
   completed = true;
   synchronizations.remove(id);
   if (transactionMode == TransactionMode.ISOLATE_READS) {
     for (TempTable table : tables.values()) {
       table.getActive().decrementAndGet();
     }
   } else {
     HashSet<TempTable> current = new HashSet<TempTable>(tempTables.values());
     current.retainAll(tables.values());
     for (TempTable table : current) {
       table.getActive().set(0);
       table.getTree().clearClonedFlags();
     }
   }
   for (TransactionCallback callback : callbacks) {
     if (status == Status.STATUS_COMMITTED) {
       callback.commit();
     } else {
       callback.rollback();
     }
   }
   callbacks.clear();
 }
 /*
  * Helper method to encapsulate a transaction. Callback pattern is used
  *
  * */
 public void doInTransaction(TransactionCallback txCallback) {
   Transaction tx = api.beginTx();
   try {
     txCallback.execute(api);
     tx.success();
   } finally {
     tx.finish();
   }
 }
 private <T> T doExecuteInTransaction(TransactionCallback<T> callback) {
   Transaction tx = database.beginTx();
   T result = null;
   try {
     result = callback.doInTransaction(database); // can throw a business exception
     tx.success();
   } catch (RuntimeException e) {
     LOG.warn("Runtime exception occurred during transaction execution.", e);
     tx.failure();
     throw e;
   } catch (Exception e) {
     LOG.warn("Checked exception occurred during transaction execution.", e);
     tx.failure();
     throw new RuntimeException(e);
   } finally {
     tx.close(); // can throw a DB exception
   }
   return result;
 }