Search in sources :

Example 1 with NamedXAResourceFactory

use of org.apache.geronimo.transaction.manager.NamedXAResourceFactory in project aries by apache.

the class Recovery method recover.

public static boolean recover(final String name, final XADataSource dataSource, final RecoverableTransactionManager transactionManager) throws IOException {
    if (name != null && name.length() > 0) {
        transactionManager.registerNamedXAResourceFactory(new NamedXAResourceFactory() {

            public String getName() {
                return name;
            }

            public NamedXAResource getNamedXAResource() throws SystemException {
                try {
                    final XAConnection connection = dataSource.getXAConnection();
                    LOGGER.debug("new namedXAResource's connection: " + connection);
                    return new ConnectionAndWrapperNamedXAResource(connection.getXAResource(), getName(), connection);
                } catch (Exception e) {
                    SystemException se = new SystemException("Failed to create ConnectionAndWrapperNamedXAResource, " + e.getLocalizedMessage());
                    se.initCause(e);
                    LOGGER.error(se.getLocalizedMessage(), se);
                    throw se;
                }
            }

            public void returnNamedXAResource(NamedXAResource namedXaResource) {
                if (namedXaResource instanceof ConnectionAndWrapperNamedXAResource) {
                    try {
                        LOGGER.debug("closing returned namedXAResource's connection: " + ((ConnectionAndWrapperNamedXAResource) namedXaResource).connection);
                        ((ConnectionAndWrapperNamedXAResource) namedXaResource).connection.close();
                    } catch (Exception ignored) {
                        LOGGER.debug("failed to close returned namedXAResource: " + namedXaResource, ignored);
                    }
                }
            }
        });
        return true;
    } else {
        LOGGER.warn("Unable to recover XADataSource: aries.xa.name property not set");
        return false;
    }
}
Also used : SystemException(javax.transaction.SystemException) WrapperNamedXAResource(org.apache.geronimo.transaction.manager.WrapperNamedXAResource) NamedXAResource(org.apache.geronimo.transaction.manager.NamedXAResource) SystemException(javax.transaction.SystemException) IOException(java.io.IOException) NamedXAResourceFactory(org.apache.geronimo.transaction.manager.NamedXAResourceFactory) XAConnection(javax.sql.XAConnection)

Aggregations

IOException (java.io.IOException)1 XAConnection (javax.sql.XAConnection)1 SystemException (javax.transaction.SystemException)1 NamedXAResource (org.apache.geronimo.transaction.manager.NamedXAResource)1 NamedXAResourceFactory (org.apache.geronimo.transaction.manager.NamedXAResourceFactory)1 WrapperNamedXAResource (org.apache.geronimo.transaction.manager.WrapperNamedXAResource)1