示例#1
0
 TxRecord(final String persistenceContext, final String uuid, final StackTraceElement ste) {
   this.persistenceContext = persistenceContext;
   this.uuid = uuid;
   this.ste = ste;
   this.stack = Threads.currentStackString();
   this.startTime = System.currentTimeMillis();
 }
示例#2
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;
   }
 }
示例#3
0
 TransactionState(final String ctx) {
   this.startTime = System.currentTimeMillis();
   this.txUuid = String.format("%s:%s", ctx, UUID.randomUUID().toString());
   this.stopWatch = new StopWatch();
   this.stopWatch.start();
   this.owner = Logs.isExtrrreeeme() ? Threads.currentStackString() : "n/a";
   try {
     this.eventLog(TxStep.BEGIN, TxEvent.CREATE);
     final EntityManagerFactory anemf =
         (EntityManagerFactoryImpl) PersistenceContexts.getEntityManagerFactory(ctx);
     checkParam(anemf, notNullValue());
     this.em = anemf.createEntityManager();
     checkParam(this.em, notNullValue());
     this.transaction = this.em.getTransaction();
     this.transaction.begin();
     this.session = new WeakReference<Session>((Session) this.em.getDelegate());
     this.eventLog(TxStep.END, TxEvent.CREATE);
   } catch (final Throwable ex) {
     Logs.exhaust().error(ex, ex);
     this.eventLog(TxStep.FAIL, TxEvent.CREATE);
     this.rollback();
     throw new RuntimeException(PersistenceExceptions.throwFiltered(ex));
   } finally {
     outstanding.put(this.txUuid, this);
   }
 }
示例#4
0
 public String getMessage() {
   if (Logs.isExtrrreeeme()) {
     return Threads.currentStackString();
   } else {
     return "n.a";
   }
 }
示例#5
0
 public static <E, T> Predicate<T> asTransaction(final Predicate<T> predicate) {
   final List<Class> generics = Classes.genericsToClasses(predicate);
   for (final Class<?> type : generics) {
     if (PersistenceContexts.isPersistentClass(type)) {
       return asTransaction(type, predicate);
     }
   }
   throw new IllegalArgumentException(
       "Failed to find generics for provided predicate, cannot make into transaction: "
           + Threads.currentStackString());
 }
示例#6
0
 /**
  * @delegate Do not change semantics here.
  * @see javax.persistence.EntityTransaction#commit()
  */
 @Override
 public void commit() throws RecoverablePersistenceException {
   removeTransaction(this);
   if ((this.txState != null) && this.txState.isActive()) {
     try {
       this.txState.commit();
     } catch (final RuntimeException ex) {
       throw PersistenceExceptions.throwFiltered(ex);
     }
   } else {
     Logs.extreme().error("Duplicate call to commit( ): " + Threads.currentStackString());
   }
 }
示例#7
0
 public static <T, R> Function<T, R> asTransaction(final Function<T, R> function) {
   if (function instanceof TransactionalFunction) {
     return function;
   } else {
     final List<Class> generics = Classes.genericsToClasses(function);
     for (final Class<?> type : generics) {
       if (PersistenceContexts.isPersistentClass(type)) {
         return asTransaction(type, function);
       }
     }
     throw new IllegalArgumentException(
         "Failed to find generics for provided function, cannot make into transaction: "
             + Threads.currentStackString());
   }
 }
示例#8
0
 /**
  * Private for a reason.
  *
  * @see {@link EntityWrapper#get(Class)}
  * @param persistenceContext
  */
 @SuppressWarnings("unchecked")
 private EntityWrapper(final String persistenceContext) {
   this.tx = new TransactionState(persistenceContext);
   this.txStart = Threads.currentStackString();
 }