use of javax.transaction.xa.XAResource in project geode by apache.
the class JCAConnectionManagerImpl method connectionErrorOccurred.
/**
* CallBack for Connection Error.
*
* @param event ConnectionEvent
*/
public void connectionErrorOccurred(ConnectionEvent event) {
if (isActive) {
// If its an XAConnection
ManagedConnection conn = (ManagedConnection) event.getSource();
XAResource xar = (XAResource) xaResourcesMap.get(conn);
xaResourcesMap.remove(conn);
TransactionManagerImpl transManager = TransactionManagerImpl.getTransactionManager();
try {
Transaction txn = transManager.getTransaction();
if (txn != null && xar != null)
txn.delistResource(xar, XAResource.TMSUCCESS);
} catch (SystemException se) {
se.printStackTrace();
}
try {
mannPoolCache.expirePooledConnection(conn);
// mannPoolCache.destroyPooledConnection(conn);
} catch (Exception ex) {
String exception = "JCAConnectionManagerImpl::connectionErrorOccurred: Exception occurred due to " + ex;
if (logger.isDebugEnabled()) {
logger.debug(exception, ex);
}
}
}
}
use of javax.transaction.xa.XAResource in project geode by apache.
the class JCAConnectionManagerImpl method connectionClosed.
/**
* Callback for Connection Closed.
*
* @param event ConnectionEvent Object.
*/
public void connectionClosed(ConnectionEvent event) {
if (isActive) {
ManagedConnection conn = (ManagedConnection) event.getSource();
XAResource xar = null;
if (xaResourcesMap.get(conn) != null)
xar = (XAResource) xaResourcesMap.get(conn);
xaResourcesMap.remove(conn);
try {
Transaction txn = transManager.getTransaction();
if (txn != null && xar != null) {
txn.delistResource(xar, XAResource.TMSUCCESS);
}
} catch (Exception se) {
String exception = "JCAConnectionManagerImpl::connectionClosed: Exception occurred due to " + se;
if (logger.isDebugEnabled()) {
logger.debug(exception, se);
}
}
mannPoolCache.returnPooledConnectionToPool(conn);
}
}
use of javax.transaction.xa.XAResource in project geode by apache.
the class FacetsJCAConnectionManagerImpl method allocateConnection.
/*
* allocates a ManagedConnection from the ConnectionPool or creates a new
* ManagedConnection. @param javax.resource.spi.ManagedConnectionFactory
*
* @param javax.resource.spi.ConnectionRequestInfo
*
* @throws ResourceException
*/
public Object allocateConnection(ManagedConnectionFactory mcf, ConnectionRequestInfo reqInfo) throws ResourceException {
if (!isActive) {
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPLALLOCATECONNECTIONNO_VALID_CONNECTION_AVAILABLE.toLocalizedString());
}
ManagedConnection conn = null;
try {
conn = (ManagedConnection) mannPoolCache.getPooledConnectionFromPool();
} catch (PoolException ex) {
ex.printStackTrace();
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_IN_GETTING_CONNECTION_FROM_POOL_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
// Transaction Manager.
try {
synchronized (this) {
if (transManager == null) {
transManager = JNDIInvoker.getTransactionManager();
}
}
Transaction txn = transManager.getTransaction();
if (txn != null) {
// Check if Data Source provides XATransaction
// if(configs.getTransactionType = "XATransaction")
XAResource xar = conn.getXAResource();
txn.enlistResource(xar);
java.util.List resList = (List) xalistThreadLocal.get();
if (resList.size() == 0) {
// facets specific implementation
// register syschronisation only once
txn.registerSynchronization(this);
}
resList.add(conn);
// xalistThreadLocal.set(resList);
// Asif :Add in the Map after successful registration of XAResource
// xaResourcesMap.put(conn, xar);
// else throw a resource exception
}
} catch (RollbackException ex) {
String exception = LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_AN_EXCEPTION_WAS_CAUGHT_WHILE_ALLOCATING_A_CONNECTION_DUE_TO_0.toLocalizedString(ex.getMessage());
throw new ResourceException(exception, ex);
} catch (SystemException ex) {
throw new ResourceException(LocalizedStrings.FacetsJCAConnectionManagerImpl_FACETSJCACONNECTIONMANAGERIMPL_ALLOCATECONNECTION_SYSTEM_EXCEPTION_DUE_TO_0.toLocalizedString(ex.getMessage()), ex);
}
return conn.getConnection(subject, reqInfo);
}
use of javax.transaction.xa.XAResource in project jackrabbit by apache.
the class UserTransactionImpl method begin.
/**
* @see javax.transaction.UserTransaction#begin
*/
public void begin() throws NotSupportedException, SystemException {
if (status != Status.STATUS_NO_TRANSACTION) {
throw new IllegalStateException("Transaction already active");
}
try {
for (Iterator it = xaResources.keySet().iterator(); it.hasNext(); ) {
XAResource resource = (XAResource) it.next();
XidImpl xid = (XidImpl) xaResources.get(resource);
resource.start(xid, XAResource.TMNOFLAGS);
}
status = Status.STATUS_ACTIVE;
} catch (XAException e) {
throw new SystemException("Unable to begin transaction: " + "XA_ERR=" + e.errorCode);
}
}
use of javax.transaction.xa.XAResource in project aries by apache.
the class TxDBServlet method insertIntoTransaction.
/**
* This method demonstrates how to enlist JDBC connection into Transaction according OSGi enterprise specification.
*
* @param xads XADataSource
* @param tm TransactionManager
* @param value which will be inserted into table
* @param toCommit Specify if the transaction will be committed or rolledback
* @throws SQLException
* @throws GenericJTAException
*/
private void insertIntoTransaction(XADataSource xads, TransactionManager tm, String value, boolean toCommit) throws SQLException, GenericJTAException {
XAConnection xaConnection = xads.getXAConnection();
Connection connection = xaConnection.getConnection();
XAResource xaResource = xaConnection.getXAResource();
try {
tm.begin();
Transaction transaction = tm.getTransaction();
transaction.enlistResource(xaResource);
PreparedStatement insertStatement = connection.prepareStatement(INSERT_INTO_TABLE);
insertStatement.setString(1, value);
insertStatement.executeUpdate();
if (toCommit) {
transaction.commit();
} else {
transaction.rollback();
}
} catch (RollbackException e) {
throw new GenericJTAException(e);
} catch (SecurityException e) {
throw new GenericJTAException(e);
} catch (IllegalStateException e) {
throw new GenericJTAException(e);
} catch (HeuristicMixedException e) {
throw new GenericJTAException(e);
} catch (HeuristicRollbackException e) {
throw new GenericJTAException(e);
} catch (SystemException e) {
throw new GenericJTAException(e);
} catch (NotSupportedException e) {
throw new GenericJTAException(e);
}
}
Aggregations