Browse Source

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

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3128 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/head
Juergen Hoeller 16 years ago
parent
commit
b6a298d8b3
  1. 4
      org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebSphereUowTransactionManager.java
  2. 4
      org.springframework.transaction/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java
  3. 20
      org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java

4
org.springframework.transaction/src/main/java/org/springframework/transaction/jta/WebSphereUowTransactionManager.java

@ -352,7 +352,9 @@ public class WebSphereUowTransactionManager extends JtaTransactionManager @@ -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));
}
}
}
}

4
org.springframework.transaction/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java

@ -1,5 +1,5 @@ @@ -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 @@ -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.

20
org.springframework.transaction/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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);

Loading…
Cancel
Save