Пример #1
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);
   }
 }
Пример #2
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());
 }
Пример #3
0
 public TxState(final String ctx) {
   try {
     final EntityManagerFactory anemf =
         (EntityManagerFactoryImpl) PersistenceContexts.getEntityManagerFactory(ctx);
     checkParam(anemf, notNullValue());
     this.em = anemf.createEntityManager();
     checkParam(this.em, notNullValue());
     this.transaction = this.em.getTransaction();
     checkParam(this.transaction, notNullValue());
     this.sessionRef = new WeakReference<Session>((Session) this.em.getDelegate());
   } catch (final RuntimeException ex) {
     this.doCleanup();
     throw ex;
   }
 }
Пример #4
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());
   }
 }