/** Borrowed from Seam */
  public int getStatus() {
    if (ptm == null) {
      return TransactionManager.STATUS_NO_TRANSACTION;
    }

    // logger.debug( "Current TX name (According to TransactionSynchronizationManager) : " +
    // TransactionSynchronizationManager.getCurrentTransactionName() );
    if (TransactionSynchronizationManager.isActualTransactionActive()) {
      TransactionStatus transaction = null;
      boolean commitNewTransaction = false;
      try {
        if (currentTransaction.size() == 0) {
          transaction = ptm.getTransaction(td);
          currentTransaction.push(transaction);
          commitNewTransaction = true;
          if (transaction.isNewTransaction()) {
            return TransactionManager.STATUS_COMMITTED;
          }
        } else {
          transaction = currentTransaction.peek();
        }
        logger.debug("Current TX: " + transaction);
        // If SynchronizationManager thinks it has an active transaction but
        // our transaction is a new one
        // then we must be in the middle of committing
        if (transaction.isCompleted()) {
          if (transaction.isRollbackOnly()) {
            return TransactionManager.STATUS_ROLLEDBACK;
          }
          return TransactionManager.STATUS_COMMITTED;
        } else {
          if (transaction.isRollbackOnly()) {
            return 5;
          }
          return TransactionManager.STATUS_ACTIVE;
        }
      } finally {
        if (commitNewTransaction) {
          ptm.commit(transaction);
        }
      }
    }
    return TransactionManager.STATUS_NO_TRANSACTION;
  }
Ejemplo n.º 2
0
 protected void commitTransaction(TransactionStatus status) {
   if (null != transactionManager && null != status) {
     transactionManager.commit(status);
   }
 }