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;
}
}
Aggregations