final boolean wrapInTransaction = wrapInTransaction();
if ( wrapInTransaction ) {
TransactionManager transactionManager = getTransactionManager();
try {
final Session session;
final StatelessSession statelessSession;
if ( sessionAwareRunnable != null ) {
session = factory.openSession();
statelessSession = null;
}
else {
session = null;
statelessSession = factory.openStatelessSession();
}
transactionManager.begin();
if ( sessionAwareRunnable != null ) {
sessionAwareRunnable.run( session );
}
else {
statelessSessionAwareRunnable.run( statelessSession );
}
transactionManager.commit();
if ( sessionAwareRunnable != null ) {
session.close();
}
else {
statelessSession.close();
}
}
catch (Throwable e) {
errorHandler.handleException( log.massIndexerUnexpectedErrorMessage() , e);
try {