private void attemptToRegisterJtaSync() {
if ( synchronizationRegistered ) {
return;
}
final JtaPlatform jtaPlatform = getTransactionEnvironment().getJtaPlatform();
if ( jtaPlatform == null ) {
// if no jta platform was registered we wont be able to register a jta synchronization
return;
}
// Has the local transaction (Hibernate facade) taken on the responsibility of driving the transaction inflow?
if ( currentHibernateTransaction.isInitiator() ) {
return;
}
if ( ! transactionContext.shouldAutoJoinTransaction() ) {
if ( currentHibernateTransaction.getJoinStatus() != JoinStatus.MARKED_FOR_JOINED ) {
if (isDebugging) {
LOG.debug( "Skipping JTA sync registration due to auto join checking" );
}
return;
}
}
// IMPL NOTE : At this point the local callback is the "maybe" one. The only time that needs to change is if
// we are able to successfully register the transaction synchronization in which case the local callback would become
// non driving. To that end, the following checks are simply opt outs where we are unable to register the
// synchronization
// Can we resister a synchronization
if ( !jtaPlatform.canRegisterSynchronization() ) {
if (isTracing) {
LOG.trace( "registered JTA platform says we cannot currently register synchronization; skipping" );
}
return;
}
// Should we resister a synchronization
if ( ! transactionFactory().isJoinableJtaTransaction( this, currentHibernateTransaction ) ) {
if (isTracing) {
LOG.trace( "TransactionFactory reported no JTA transaction to join; skipping Synchronization registration" );
}
return;
}
jtaPlatform.registerSynchronization( new RegisteredSynchronization( getSynchronizationCallbackCoordinator() ) );
getSynchronizationCallbackCoordinator().synchronizationRegistered();
synchronizationRegistered = true;
if (isDebugging) {
LOG.debug( "successfully registered Synchronization" );
}