Java Code Examples for javax.transaction.xa.XAException#getMessage()

The following examples show how to use javax.transaction.xa.XAException#getMessage() . 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: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void compensableRecoverySuspend() throws NotSupportedException, SystemException {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();
	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	if (compensable == null) {
		throw new IllegalStateException();
	}

	TransactionContext transactionContext = compensable.getTransactionContext();
	if (transactionContext.isCoordinator() == false) {
		throw new IllegalStateException();
	}

	TransactionParticipant compensableCoordinator = this.beanFactory.getCompensableNativeParticipant();

	TransactionContext compensableContext = compensable.getTransactionContext();
	try {
		compensableCoordinator.end(compensableContext, XAResource.TMSUCCESS);
	} catch (XAException ex) {
		logger.error("Error occurred while suspending an compensable transaction!", ex);
		throw new SystemException(ex.getMessage());
	}
}
 
Example 2
Source File: FBLocalTransaction.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Begin a local transaction.
 *
 * @throws SQLException
 *         generic exception if operation fails
 */
public void begin() throws SQLException {
    // throw exception only if xid is known to the managed connection
    if (xid != null && mc.isXidActive(xid)) {
        // TODO More specific exception, Jaybird error code
        throw new SQLException("Local transaction active: can't begin another",
                SQLStateConstants.SQL_STATE_TRANSACTION_ACTIVE);
    }

    xid = new FBLocalXid();

    try {
        mc.internalStart(xid, XAResource.TMNOFLAGS);
    } catch (XAException ex) {
        xid = null;
        if (ex.getCause() instanceof SQLException) {
            throw (SQLException) ex.getCause();
        }
        // TODO More specific exception, Jaybird error code (or is this flow unlikely to hit?)
        throw new SQLException(ex.getMessage(), ex);
    }
}
 
Example 3
Source File: FBLocalTransaction.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Commit a local transaction.
 *
 * @throws SQLException
 *         generic exception if operation fails
 */
public void commit() throws SQLException {
    // if there is no xid assigned, but we are still here, that means that automatic commit was called in managed
    // scenario when managed connection was enlisted in global transaction
    if (xid == null) return;

    synchronized (mc.getSynchronizationObject()) {
        try {
            mc.internalEnd(xid, XAResource.TMSUCCESS);
            mc.internalCommit(xid, true);
        } catch (XAException ex) {
            if (ex.getCause() instanceof SQLException) {
                throw (SQLException) ex.getCause();
            }
            // TODO More specific exception, Jaybird error code (or is this flow unlikely to hit?)
            throw new SQLException(ex.getMessage(), ex);
        } finally {
            xid = null;
        }
    }
}
 
Example 4
Source File: FBLocalTransaction.java    From jaybird with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Rollback a local transaction.
 *
 * @throws SQLException
 *         generic exception if operation fails
 */
public void rollback() throws SQLException {
    // if there is no xid assigned, but we are still here, that means that automatic commit was called in managed
    // scenario when managed connection was enlisted in global transaction
    if (xid == null) return;

    synchronized (mc.getSynchronizationObject()) {
        try {
            mc.internalEnd(xid, XAResource.TMSUCCESS); // ??? on flags
            // --FBManagedConnection is its own XAResource
            mc.internalRollback(xid);
        } catch (XAException ex) {
            if (ex.getCause() instanceof SQLException) {
                throw (SQLException) ex.getCause();
            }
            // TODO More specific exception, Jaybird error code (or is this flow unlikely to hit?)
            throw new SQLException(ex.getMessage(), ex);
        } finally {
            xid = null;
        }
    }
}
 
Example 5
Source File: TransactionImpl.java    From clearpool with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean delistResource(XAResource xaresource, int i) throws SystemException {
  if (this.status != Status.STATUS_ACTIVE) {
    throw new IllegalStateException("the transaction is not active");
  }
  TransactionAdapter txAdapt =
      (TransactionAdapter) TransactionManagerImpl.getManager().getTransaction();
  if (txAdapt.getTx() != this) {
    throw new IllegalStateException("the transaction is not held");
  }
  Xid xid = this.xaResMap.get(xaresource);
  if (xid == null) {
    return false;
  }
  try {
    xaresource.end(xid, i);
  } catch (XAException e) {
    String error = "can't end XA: " + e + " (error code = " + e.errorCode + ") " + e.getMessage();
    throw new SystemException(error);
  }
  return true;
}
 
Example 6
Source File: JMSTransactionTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static void startBusAndJMS(String brokerURI) {
    try {
        transactionManager = new GeronimoTransactionManager();
    } catch (XAException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
    bus = BusFactory.getDefaultBus();
    registerTransactionManager();
    ActiveMQXAConnectionFactory cf1 = new ActiveMQXAConnectionFactory(brokerURI);
    cf1.setRedeliveryPolicy(redeliveryPolicy());
    JcaPooledConnectionFactory pcf = new JcaPooledConnectionFactory();
    pcf.setTransactionManager(transactionManager);
    pcf.setConnectionFactory(cf1);
    cf = pcf;
    cff = new ConnectionFactoryFeature(pcf);
}
 
Example 7
Source File: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
public TransactionXid compensableBegin() throws NotSupportedException, SystemException {
	RemoteCoordinator compensableCoordinator = (RemoteCoordinator) this.beanFactory.getCompensableNativeParticipant();
	CompensableManager tompensableManager = this.beanFactory.getCompensableManager();
	XidFactory compensableXidFactory = this.beanFactory.getCompensableXidFactory();

	CompensableTransactionImpl compensable = (CompensableTransactionImpl) tompensableManager
			.getCompensableTransactionQuietly();
	if (compensable != null) {
		throw new NotSupportedException();
	}

	TransactionXid compensableXid = compensableXidFactory.createGlobalXid();

	TransactionContext compensableContext = new TransactionContext();
	compensableContext.setCoordinator(true);
	compensableContext.setPropagated(true);
	compensableContext.setCompensable(true);
	compensableContext.setStatefully(this.statefully);
	compensableContext.setXid(compensableXid);
	compensableContext.setPropagatedBy(compensableCoordinator.getIdentifier());
	compensable = new CompensableTransactionImpl(compensableContext);
	compensable.setBeanFactory(this.beanFactory);

	try {
		compensableCoordinator.start(compensableContext, XAResource.TMNOFLAGS);
	} catch (XAException ex) {
		logger.error("Error occurred while beginning an compensable transaction!", ex);
		throw new SystemException(ex.getMessage());
	}

	return compensableXid;
}
 
Example 8
Source File: ActiveMQMessageHandlerXATest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeDelivery(Method method) throws NoSuchMethodException, ResourceException {
   super.beforeDelivery(method);
   try {
      xaResource.start(xid, XAResource.TMNOFLAGS);
   } catch (XAException e) {
      throw new ResourceException(e.getMessage(), e);
   }
}
 
Example 9
Source File: ActiveMQMessageHandlerXATest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void afterDelivery() throws ResourceException {
   try {
      xaResource.end(xid, XAResource.TMSUCCESS);
   } catch (XAException e) {
      throw new ResourceException(e.getMessage(), e);
   }

   super.afterDelivery();
}
 
Example 10
Source File: UserCompensableImpl.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void compensableRecoveryResume(Xid xid) throws NotSupportedException, SystemException {
	CompensableManager compensableManager = this.beanFactory.getCompensableManager();
	TransactionRepository transactionRepository = this.beanFactory.getCompensableRepository();
	TransactionParticipant compensableCoordinator = this.beanFactory.getCompensableNativeParticipant();
	if (xid == null) {
		throw new IllegalStateException();
	} else if (TransactionXid.class.isInstance(xid) == false) {
		throw new IllegalStateException();
	} else if (xid.getFormatId() != XidFactory.TCC_FORMAT_ID) {
		throw new IllegalStateException();
	}

	TransactionXid compensableXid = (TransactionXid) xid;
	CompensableTransaction transaction = null;
	try {
		transaction = (CompensableTransaction) transactionRepository.getTransaction(compensableXid);
	} catch (TransactionException tex) {
		logger.error("Error occurred while getting transaction from transaction repository!", tex);
		throw new IllegalStateException();
	}

	if (transaction == null) {
		throw new IllegalStateException();
	} else if (CompensableTransaction.class.isInstance(transaction) == false) {
		throw new IllegalStateException();
	}

	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();

	TransactionContext transactionContext = transaction.getTransactionContext();
	if (transactionContext.isCoordinator() == false) {
		throw new IllegalStateException();
	} else if (transactionContext.isRecoveried()) {
		try {
			compensableCoordinator.start(transactionContext, XAResource.TMNOFLAGS);
		} catch (XAException ex) {
			logger.error("Error occurred while resuming an compensable transaction!", ex);
			throw new SystemException(ex.getMessage());
		}
	} else if (compensable == null) {
		throw new IllegalStateException();
	} else if (compensable.equals(transaction) == false) {
		throw new IllegalStateException();
	}

}