avoid Synchronization List preparations upfront if possible (SPR-6999)

This commit is contained in:
Juergen Hoeller 2010-03-22 14:23:02 +00:00
parent 4c0744ee54
commit 19b4618fb5
3 changed files with 16 additions and 12 deletions

View File

@ -352,7 +352,9 @@ public class WebSphereUowTransactionManager extends JtaTransactionManager
if (status.isNewSynchronization()) {
List<TransactionSynchronization> synchronizations = TransactionSynchronizationManager.getSynchronizations();
TransactionSynchronizationManager.clear();
uowManager.registerInterposedSynchronization(new JtaAfterCompletionSynchronization(synchronizations));
if (!synchronizations.isEmpty()) {
uowManager.registerInterposedSynchronization(new JtaAfterCompletionSynchronization(synchronizations));
}
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -970,7 +970,7 @@ public abstract class AbstractPlatformTransactionManager implements PlatformTran
// invoke the afterCompletion callbacks immediately
invokeAfterCompletion(synchronizations, completionStatus);
}
else {
else if (!synchronizations.isEmpty()) {
// Existing transaction that we participate in, controlled outside
// of the scope of this Spring transaction manager -> try to register
// an afterCompletion callback with the existing (JTA) transaction.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -287,16 +287,21 @@ public abstract class TransactionSynchronizationManager {
* @see TransactionSynchronization
*/
public static List<TransactionSynchronization> getSynchronizations() throws IllegalStateException {
if (!isSynchronizationActive()) {
List<TransactionSynchronization> synchs = synchronizations.get();
if (synchs == null) {
throw new IllegalStateException("Transaction synchronization is not active");
}
List<TransactionSynchronization> synchs = synchronizations.get();
// Sort lazily here, not in registerSynchronization.
OrderComparator.sort(synchs);
// Return unmodifiable snapshot, to avoid ConcurrentModificationExceptions
// while iterating and invoking synchronization callbacks that in turn
// might register further synchronizations.
return Collections.unmodifiableList(new ArrayList<TransactionSynchronization>(synchs));
if (synchs.isEmpty()) {
return Collections.emptyList();
}
else {
// Sort lazily here, not in registerSynchronization.
OrderComparator.sort(synchs);
return Collections.unmodifiableList(new ArrayList<TransactionSynchronization>(synchs));
}
}
/**
@ -359,9 +364,6 @@ public abstract class TransactionSynchronizationManager {
* flush mode of a Hibernate Session to "FlushMode.NEVER" upfront.
* @see org.springframework.transaction.TransactionDefinition#isReadOnly()
* @see TransactionSynchronization#beforeCommit(boolean)
* @see org.hibernate.Session#flush
* @see org.hibernate.Session#setFlushMode
* @see org.hibernate.FlushMode#NEVER
*/
public static boolean isCurrentTransactionReadOnly() {
return (currentTransactionReadOnly.get() != null);