Java Code Examples for javax.transaction.SystemException#initCause()

The following examples show how to use javax.transaction.SystemException#initCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TxRegistry.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Commit a transaction
 * @exception SystemException Thrown if an error occurs
 */
public void commitTransaction() throws SystemException
{
   Long key = Long.valueOf(Thread.currentThread().getId());
   TransactionImpl tx = txs.get(key);
   if (tx != null)
   {
      try
      {
         tx.commit();
      }
      catch (Throwable t)
      {
         SystemException se = new SystemException("Error during commit");
         se.initCause(t);
         throw se;
      }
   }
   else
   {
      throw new IllegalStateException("No transaction to commit");
   }
}
 
Example 2
Source File: TxRegistry.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Rollback a transaction
 * @exception SystemException Thrown if an error occurs
 */
public void rollbackTransaction() throws SystemException
{
   Long key = Long.valueOf(Thread.currentThread().getId());
   TransactionImpl tx = txs.get(key);
   if (tx != null)
   {
      try
      {
         tx.rollback();
      }
      catch (Throwable t)
      {
         SystemException se = new SystemException("Error during rollback");
         se.initCause(t);
         throw se;
      }
   }
   else
   {
      throw new IllegalStateException("No transaction to rollback");
   }
}
 
Example 3
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void invokeTransactionCommitIfNotLocalTransaction(CompensableTransaction compensable) throws RollbackException,
		HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {

	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);

		TransactionContext compensableContext = compensable.getTransactionContext();
		logger.error("{}> jta-transaction in try-phase cannot be xa transaction.",
				ByteUtils.byteArrayToString(compensableContext.getXid().getGlobalTransactionId()));

		transactionCoordinator.rollback(transactionXid);
		throw new HeuristicRollbackException();
	} catch (XAException xaEx) {
		transactionCoordinator.forgetQuietly(transactionXid);
		SystemException sysEx = new SystemException(xaEx.errorCode);
		sysEx.initCause(xaEx);
		throw sysEx;
	}
}
 
Example 4
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void invokeTransactionRollback(CompensableTransaction compensable)
		throws IllegalStateException, SecurityException, SystemException {

	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
		transactionCoordinator.rollback(transactionXid);
	} catch (XAException xaEx) {
		transactionCoordinator.forgetQuietly(transactionXid);
		SystemException sysEx = new SystemException(xaEx.errorCode);
		sysEx.initCause(xaEx);
		throw sysEx;
	} finally {
		compensable.setTransactionalExtra(null);
	}

}
 
Example 5
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void invokeCompensableCommitIfNotLocalTransaction(CompensableTransaction compensable)
		throws HeuristicRollbackException, SystemException {

	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();
	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
		TransactionContext compensableContext = compensable.getTransactionContext();
		logger.error("{}| jta-transaction in compensating-phase cannot be xa transaction.",
				ByteUtils.byteArrayToString(compensableContext.getXid().getGlobalTransactionId()));

		transactionCoordinator.rollback(transactionXid);
		throw new HeuristicRollbackException();
	} catch (XAException xaex) {
		transactionCoordinator.forgetQuietly(transactionXid);
		SystemException sysEx = new SystemException(xaex.errorCode);
		sysEx.initCause(xaex);
		throw sysEx;
	}
}
 
Example 6
Source File: JackRabbitUserTransaction.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see javax.transaction.UserTransaction#begin
 */
@Override
public void begin() throws NotSupportedException, SystemException {
    if (status != Status.STATUS_NO_TRANSACTION) {
        throw new IllegalStateException("Transaction already active");
    }

    try {
        xid = new XidImpl(counter++);
        xares.start(xid, XAResource.TMNOFLAGS);
        status = Status.STATUS_ACTIVE;

    } catch (XAException e) {
        final SystemException systemException = new SystemException("Unable to commit transaction: " + "XA_ERR="
                + e.errorCode);
        systemException.initCause(e);
        throw systemException;
    }
}
 
Example 7
Source File: JackRabbitUserTransaction.java    From mycollab with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * @see javax.transaction.UserTransaction#rollback
 */
@Override
public void rollback() throws IllegalStateException, SecurityException, SystemException {

    if (status != Status.STATUS_ACTIVE && status != Status.STATUS_MARKED_ROLLBACK) {

        throw new IllegalStateException("Transaction not active");
    }

    try {
        xares.end(xid, XAResource.TMFAIL);

        status = Status.STATUS_ROLLING_BACK;
        xares.rollback(xid);
        status = Status.STATUS_ROLLEDBACK;

    } catch (XAException e) {
        final SystemException systemException = new SystemException("Unable to commit transaction: " + "XA_ERR="
                + e.errorCode);
        systemException.initCause(e);
        throw systemException;
    }
}
 
Example 8
Source File: TxRegistry.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Commit a transaction
 * @exception SystemException Thrown if an error occurs
 */
public void commitTransaction() throws SystemException
{
   Long key = Long.valueOf(Thread.currentThread().getId());
   TransactionImpl tx = txs.get(key);
   if (tx != null)
   {
      try
      {
         tx.commit();
      }
      catch (Throwable t)
      {
         SystemException se = new SystemException("Error during commit");
         se.initCause(t);
         throw se;
      }
   }
   else
   {
      throw new IllegalStateException("No transaction to commit");
   }
}
 
Example 9
Source File: TxRegistry.java    From ironjacamar with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Rollback a transaction
 * @exception SystemException Thrown if an error occurs
 */
public void rollbackTransaction() throws SystemException
{
   Long key = Long.valueOf(Thread.currentThread().getId());
   TransactionImpl tx = txs.get(key);
   if (tx != null)
   {
      try
      {
         tx.rollback();
      }
      catch (Throwable t)
      {
         SystemException se = new SystemException("Error during rollback");
         se.initCause(t);
         throw se;
      }
   }
   else
   {
      throw new IllegalStateException("No transaction to rollback");
   }
}
 
Example 10
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeTransactionCommitIfLocalTransaction(CompensableTransaction compensable) throws RollbackException,
		HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException {

	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();
	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
		transactionCoordinator.commit(transactionXid, true);
	} catch (XAException xaEx) {
		switch (xaEx.errorCode) {
		case XAException.XA_HEURCOM:
			transactionCoordinator.forgetQuietly(transactionXid);
			break;
		case XAException.XA_HEURRB:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicRollbackException hrex = new HeuristicRollbackException();
			hrex.initCause(xaEx);
			throw hrex;
		case XAException.XA_HEURMIX:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicMixedException hmex = new HeuristicMixedException();
			hmex.initCause(xaEx);
			throw hmex;
		case XAException.XAER_RMERR:
		default:
			transactionCoordinator.forgetQuietly(transactionXid); // TODO
			SystemException sysEx = new SystemException(xaEx.errorCode);
			sysEx.initCause(xaEx);
			throw sysEx;
		}
	}

}
 
Example 11
Source File: CompensableManagerImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void invokeCompensableCommitIfLocalTransaction(CompensableTransaction compensable)
		throws HeuristicRollbackException, SystemException {

	TransactionParticipant transactionCoordinator = this.beanFactory.getTransactionNativeParticipant();
	Transaction transaction = compensable.getTransaction();
	org.bytesoft.transaction.TransactionContext transactionContext = transaction.getTransactionContext();

	TransactionXid transactionXid = transactionContext.getXid();
	try {
		transactionCoordinator.end(transactionContext, XAResource.TMSUCCESS);
		transactionCoordinator.commit(transactionXid, true);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURCOM:
			transactionCoordinator.forgetQuietly(transactionXid);
			break;
		case XAException.XA_HEURRB:
			transactionCoordinator.forgetQuietly(transactionXid);
			HeuristicRollbackException hrex = new HeuristicRollbackException();
			hrex.initCause(xaex);
			throw hrex;
		default:
			transactionCoordinator.forgetQuietly(transactionXid); // TODO
			SystemException sysEx = new SystemException(xaex.errorCode);
			sysEx.initCause(xaex);
			throw sysEx;
		}
	}
}
 
Example 12
Source File: JackRabbitUserTransaction.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see javax.transaction.UserTransaction#commit
 */
@Override
public void commit() throws IllegalStateException, RollbackException, SecurityException, SystemException {

    if (status != Status.STATUS_ACTIVE) {
        throw new IllegalStateException("Transaction not active");
    }

    try {
        xares.end(xid, XAResource.TMSUCCESS);

        status = Status.STATUS_PREPARING;
        xares.prepare(xid);
        status = Status.STATUS_PREPARED;

        status = Status.STATUS_COMMITTING;
        xares.commit(xid, false);
        status = Status.STATUS_COMMITTED;

    } catch (XAException e) {

        if (e.errorCode >= XAException.XA_RBBASE && e.errorCode <= XAException.XA_RBEND) {
            RollbackException rollbackException = new RollbackException(e.toString());
            rollbackException.initCause(e);
            throw rollbackException;
        }

        final SystemException systemException = new SystemException("Unable to commit transaction: " + "XA_ERR="
                + e.errorCode);
        systemException.initCause(e);
        throw systemException;
    }
}
 
Example 13
Source File: TransactionSynchronizer.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get a registered transaction synchronizer.
 *
 * @param tx the transaction
 * @param ti the transaction integration
 * @throws SystemException sys. exception
 * @throws RollbackException rollback exception
 * @return the registered transaction synchronizer for this transaction
 */
public static TransactionSynchronizer getRegisteredSynchronizer(Transaction tx, 
                                                                TransactionIntegration ti)
   throws SystemException, RollbackException
{
   Object id = ti.getIdentifier(tx);
   Record record = records.get(id);
   if (record == null)
   {
      Record newRecord = new Record(new ReentrantLock(true), new TransactionSynchronizer(tx, id));
      record = records.putIfAbsent(id, newRecord);
      if (record == null)
      {
         record = newRecord;

         if (log.isTraceEnabled())
            log.tracef("Adding: %s [%s]", System.identityHashCode(id), id.toString());

         try
         {
            if (ti.getTransactionSynchronizationRegistry() != null)
            {
               ti.getTransactionSynchronizationRegistry().
                  registerInterposedSynchronization(record.getTransactionSynchronizer());
            }
            else
            {
               tx.registerSynchronization(record.getTransactionSynchronizer());
            }
         }
         catch (Throwable t)
         {
            records.remove(id);

            if (t instanceof SystemException)
            {
               throw (SystemException)t;
            }
            else if (t instanceof RollbackException)
            {
               throw (RollbackException)t;
            }
            else
            {
               SystemException se = new SystemException(t.getMessage());
               se.initCause(t);
               throw se;
            }
         }
      }
   }
   return record.getTransactionSynchronizer();
}
 
Example 14
Source File: TransactionImpl.java    From ByteJTA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public synchronized void fireOnePhaseCommit()
		throws HeuristicRollbackException, HeuristicMixedException, CommitRequiredException, SystemException {

	XAResourceArchive archive = null;
	if (this.nativeParticipantList.size() > 0) {
		archive = this.nativeParticipantList.get(0);
	} else if (this.remoteParticipantList.size() > 0) {
		archive = this.remoteParticipantList.get(0);
	} else {
		archive = this.participant;
	}

	TransactionXid xid = this.transactionContext.getXid();
	try {
		this.transactionListenerList.onCommitStart(xid);
		archive.commit(xid, true);
		this.transactionListenerList.onCommitSuccess(xid);
	} catch (XAException xaex) {
		switch (xaex.errorCode) {
		case XAException.XA_HEURMIX:
			this.transactionListenerList.onCommitHeuristicMixed(xid);
			HeuristicMixedException hmex = new HeuristicMixedException();
			hmex.initCause(xaex);
			throw hmex;
		case XAException.XA_HEURCOM:
			this.transactionListenerList.onCommitSuccess(xid);
			break;
		case XAException.XA_HEURRB:
			this.transactionListenerList.onCommitHeuristicRolledback(xid);
			HeuristicRollbackException hrex = new HeuristicRollbackException();
			hrex.initCause(xaex);
			throw hrex;
		default:
			this.transactionListenerList.onCommitFailure(xid);
			SystemException ex = new SystemException();
			ex.initCause(xaex);
			throw ex;
		}
	} catch (RuntimeException rex) {
		this.transactionListenerList.onCommitFailure(xid);
		SystemException sysEx = new SystemException();
		sysEx.initCause(rex);
		throw sysEx;
	}
}