Java TransactionContextThreadLocal Example

说明

java transactioncontextthreadlocal示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Java

类/类型: TransactionContextThreadLocal

示例#1
文件: SleeTransactionManagerImpl.java项目: RestComm/jain-slee

 /*
  * (non-Javadoc)
  * @see javax.transaction.TransactionManager#suspend()
  */
 public Transaction suspend() throws SystemException {
   if (doTraceLogs) {
     logger.trace("Suspending tx " + transactionManager.getTransaction());
   }
   final Transaction tx = getAsSleeTransaction(transactionManager.suspend(), false);
   if (tx != null) {
     // remove tx context from thread
     TransactionContextThreadLocal.setTransactionContext(null);
     return tx;
   } else {
     return null;
   }
 }

示例#2
文件: SleeTransactionManagerImpl.java项目: RestComm/jain-slee

 private TransactionContext bindToTransaction(Transaction tx)
     throws IllegalStateException, SystemException {
   final TransactionContextImpl txContext = new TransactionContextImpl();
   // register for call-backs
   try {
     tx.registerSynchronization(new SleeTransactionSynchronization(tx, txContext));
   } catch (RollbackException e) {
     throw new IllegalStateException(
         "Unable to register listener for created transaction. Error: " + e.getMessage());
   }
   // store tx context in thread
   TransactionContextThreadLocal.setTransactionContext(txContext);
   return txContext;
 }

示例#3
文件: SleeTransactionManagerImpl.java项目: RestComm/jain-slee

 /*
  * (non-Javadoc)
  * @see org.mobicents.slee.runtime.transaction.SleeTransactionManager#getTransactionContext()
  */
 public TransactionContext getTransactionContext() {
   TransactionContext txContext = TransactionContextThreadLocal.getTransactionContext();
   if (txContext == null) {
     try {
       final Transaction tx = transactionManager.getTransaction();
       if (tx != null && tx.getStatus() == Status.STATUS_ACTIVE) {
         // a tx was started with the real tx manager, lets try to hook the sync handler and a new
         // tx context
         txContext = bindToTransaction(tx);
       }
     } catch (Throwable e) {
       throw new SLEEException(e.getMessage(), e);
     }
   }
   return txContext;
 }

示例#4
文件: SleeTransactionManagerImpl.java项目: RestComm/jain-slee

 /*
  * (non-Javadoc)
  * @see javax.transaction.TransactionManager#resume(javax.transaction.Transaction)
  */
 public void resume(Transaction transaction)
     throws InvalidTransactionException, IllegalStateException, SystemException {
   if (transaction.getClass() == SleeTransactionImpl.class) {
     final SleeTransactionImpl sleeTransactionImpl = (SleeTransactionImpl) transaction;
     if (doTraceLogs) {
       logger.trace("Resuming tx " + sleeTransactionImpl.getWrappedTransaction());
     }
     // resume wrapped tx
     transactionManager.resume(sleeTransactionImpl.getWrappedTransaction());
     // store tx context in thread
     TransactionContextThreadLocal.setTransactionContext(
         sleeTransactionImpl.getTransactionContext());
   } else {
     throw new InvalidTransactionException();
   }
 }

示例#5
文件: SleeTransactionManagerImpl.java项目: RestComm/jain-slee

 private SleeTransaction getAsSleeTransaction(Transaction transaction, boolean transactionCreation)
     throws SystemException {
   if (transaction != null) {
     TransactionContext transactionContext = null;
     if (transactionCreation) {
       transactionContext = bindToTransaction(transaction);
       if (logger.isDebugEnabled()) {
         logger.debug("Started tx " + transaction);
       }
     } else {
       transactionContext = TransactionContextThreadLocal.getTransactionContext();
       if (transactionContext == null && transaction.getStatus() == Status.STATUS_ACTIVE) {
         // we need to bind to tx, this is edge case for a tx that was created directly in the
         // underlying tx manager
         transactionContext = bindToTransaction(transaction);
       }
     }
     return new SleeTransactionImpl((Transaction) transaction, transactionContext, this);
   } else {
     return null;
   }
 }

展开阅读全文