/** * Reactivate transaction synchronization for the current thread * and resume all given synchronizations. * @param suspendedSynchronizations a List of TransactionSynchronization objects */ private void doResumeSynchronization(List<TransactionSynchronization> suspendedSynchronizations) { TransactionSynchronizationManager.initSynchronization(); for (TransactionSynchronization synchronization : suspendedSynchronizations) { synchronization.resume(); TransactionSynchronizationManager.registerSynchronization(synchronization); } }
/** * Trigger {@code flush} callbacks on all currently registered synchronizations. * @throws RuntimeException if thrown by a {@code flush} callback * @see TransactionSynchronization#flush() */ public static void triggerFlush() { for (TransactionSynchronization synchronization : TransactionSynchronizationManager.getSynchronizations()) { synchronization.flush(); } }
@Override public void beforeCompletion() { if (shouldUnbindAtCompletion()) { TransactionSynchronizationManager.unbindResource(this.resourceKey); this.holderActive = false; if (shouldReleaseBeforeCompletion()) { releaseResource(this.resourceHolder, this.resourceKey); } } }
public void bindSession() { this.timeoutInProgress = false; this.errorInProgress = false; TransactionSynchronizationManager.bindResource(this.sessionFactory, this.sessionHolder); }
@Override protected void doInTransactionWithoutResult(TransactionStatus status) throws RuntimeException { TransactionSynchronizationManager.registerSynchronization(synch); } });
@Override public void flush() { if (TransactionSynchronizationManager.isSynchronizationActive()) { TransactionSynchronizationUtils.triggerFlush(); } } }
/** * Convenience method for determining if a transaction is active for the * current {@link Thread}. * @return {@code true} if a transaction is currently active */ public static boolean inTransaction() { return TransactionSynchronizationManager.isActualTransactionActive(); }
/** * Suspend all current synchronizations and deactivate transaction * synchronization for the current thread. * @return the List of suspended TransactionSynchronization objects */ private List<TransactionSynchronization> doSuspendSynchronization() { List<TransactionSynchronization> suspendedSynchronizations = TransactionSynchronizationManager.getSynchronizations(); for (TransactionSynchronization synchronization : suspendedSynchronizations) { synchronization.suspend(); } TransactionSynchronizationManager.clearSynchronization(); return suspendedSynchronizations; }
/** * Trigger {@code beforeCommit} callbacks on all currently registered synchronizations. * @param readOnly whether the transaction is defined as read-only transaction * @throws RuntimeException if thrown by a {@code beforeCommit} callback * @see TransactionSynchronization#beforeCommit(boolean) */ public static void triggerBeforeCommit(boolean readOnly) { for (TransactionSynchronization synchronization : TransactionSynchronizationManager.getSynchronizations()) { synchronization.beforeCommit(readOnly); } }
@Override public void clear() { super.clear(); this.transactionActive = false; this.savepointsSupported = null; this.savepointCounter = 0; }
/** * Specify the transaction timeout to use for transactional wrapping, in <b>seconds</b>. * Default is none, using the transaction manager's default timeout. * @see org.springframework.transaction.TransactionDefinition#getTimeout() * @see #setReceiveTimeout */ public void setTransactionTimeout(int transactionTimeout) { this.transactionDefinition.setTimeout(transactionTimeout); }
@Override public <T> T execute(TransactionDefinition definition, TransactionCallback<T> callback) throws TransactionException { this.definition = definition; this.status = new SimpleTransactionStatus(); return callback.doInTransaction(this.status); }
/** * Trigger {@code afterCommit} callbacks on all currently registered synchronizations. * @throws RuntimeException if thrown by a {@code afterCommit} callback * @see TransactionSynchronizationManager#getSynchronizations() * @see TransactionSynchronization#afterCommit() */ public static void triggerAfterCommit() { invokeAfterCommit(TransactionSynchronizationManager.getSynchronizations()); }
/** * Trigger {@code afterCompletion} callbacks on all currently registered synchronizations. * @param completionStatus the completion status according to the * constants in the TransactionSynchronization interface * @see TransactionSynchronizationManager#getSynchronizations() * @see TransactionSynchronization#afterCompletion(int) * @see TransactionSynchronization#STATUS_COMMITTED * @see TransactionSynchronization#STATUS_ROLLED_BACK * @see TransactionSynchronization#STATUS_UNKNOWN */ public static void triggerAfterCompletion(int completionStatus) { List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations(); invokeAfterCompletion(synchronizations, completionStatus); }
@Override public boolean equals(Object other) { return (this == other || (super.equals(other) && (!(other instanceof TransactionTemplate) || getTransactionManager() == ((TransactionTemplate) other).getTransactionManager()))); }
@Override public void afterCommit() { if (!shouldReleaseBeforeCompletion()) { processResourceAfterCommit(this.resourceHolder); } }
/** * Check if there is a resource for the given key bound to the current thread. * @param key the key to check (usually the resource factory) * @return if there is a value bound to the current thread * @see ResourceTransactionManager#getResourceFactory() */ public static boolean hasResource(Object key) { Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key); Object value = doGetResource(actualKey); return (value != null); }
/** * This implementation triggers flush callbacks, * assuming that they will flush all affected ORM sessions. * @see org.springframework.transaction.support.TransactionSynchronization#flush() */ @Override public void flush() { TransactionSynchronizationUtils.triggerFlush(); }
@Override public void resume() { if (this.holderActive) { TransactionSynchronizationManager.bindResource(this.dataSource, this.connectionHolder); } }
public void bindEntityManager() { this.timeoutInProgress = false; this.errorInProgress = false; TransactionSynchronizationManager.bindResource(this.emFactory, this.emHolder); }