Exemplo n.º 1
0
 private static CascadingTx createTransaction(final Object obj)
     throws RecoverablePersistenceException, RuntimeException {
   final String ctx = lookatPersistenceContext(obj);
   final CascadingTx ret = new CascadingTx(ctx);
   try {
     ret.begin();
     if (txRootThreadLocal.get() == null) {
       final String txId = makeTxRootName(ret);
       LOG.trace(
           "Creating root entry for transaction tree: "
               + txId
               + " at: \n"
               + Threads.currentStackString());
       txRootThreadLocal.set(txId);
     }
     txStateThreadLocal.get().put(ctx, ret);
     return ret;
   } catch (RuntimeException ex) {
     try {
       ret.rollback();
     } catch (RuntimeException ex1) {
       throw ex1;
     }
     throw ex;
   }
 }
Exemplo n.º 2
0
 public static EntityTransaction get(final Object obj) {
   if (hasTransaction(obj)) {
     final CascadingTx tx = getTransaction(obj);
     final EntityTransaction etx = tx.join();
     return etx;
   } else {
     return createTransaction(obj);
   }
 }
Exemplo n.º 3
0
 private static void cleanStrandedTx(final CascadingTx txValue) {
   LOG.error(
       "Found stranded transaction: "
           + txValue.getRecord().getPersistenceContext()
           + " started at: "
           + txValue.getRecord().getStack());
   try {
     txValue.rollback();
   } catch (final Exception ex) {
     LOG.trace(ex, ex);
   }
 }
Exemplo n.º 4
0
 public static void removeTransaction(final CascadingTx tx) {
   final String txId = makeTxRootName(tx);
   txLog.remove(txStateThreadLocal.toString() + tx.getRecord().getPersistenceContext());
   txStateThreadLocal.get().remove(tx.getRecord().getPersistenceContext());
   if (txId.equals(txStateThreadLocal.get())) {
     for (final Entry<String, CascadingTx> e : txStateThreadLocal.get().entrySet()) {
       cleanStrandedTx(e.getValue());
     }
     txStateThreadLocal.get().clear();
     txStateThreadLocal.remove();
   }
 }
Exemplo n.º 5
0
 public static boolean hasTransaction(final Object obj) {
   final String ctx = lookatPersistenceContext(obj);
   final CascadingTx tx = txStateThreadLocal.get().get(ctx);
   if (tx == null) {
     return false;
   } else if (tx.isActive()) {
     return true;
   } else {
     cleanStrandedTx(tx);
     return false;
   }
 }
Exemplo n.º 6
0
 private boolean clearStale(final PersistenceContext persistenceContext) {
   final CascadingTx tx = this.get().get(persistenceContext.name());
   if (!tx.isActive()) {
     try {
       tx.getTxState().doCleanup();
     } catch (final Exception ex) {
       LOG.error(ex, ex);
     } finally {
       this.get().remove(persistenceContext.name());
     }
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 7
0
 private static String makeTxRootName(final CascadingTx tx) {
   return txStateThreadLocal.toString() + tx.getRecord().getPersistenceContext();
 }