Skip to content

Commit 1f89243

Browse files
committed
use internal Set for TransactionSynchronization objects in order to allow for equals/hashCode based replacement
1 parent 4c49cc7 commit 1f89243

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2010 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,9 +19,10 @@
1919
import java.util.ArrayList;
2020
import java.util.Collections;
2121
import java.util.HashMap;
22-
import java.util.LinkedList;
22+
import java.util.LinkedHashSet;
2323
import java.util.List;
2424
import java.util.Map;
25+
import java.util.Set;
2526

2627
import org.apache.commons.logging.Log;
2728
import org.apache.commons.logging.LogFactory;
@@ -79,8 +80,8 @@ public abstract class TransactionSynchronizationManager {
7980
private static final ThreadLocal<Map<Object, Object>> resources =
8081
new NamedThreadLocal<Map<Object, Object>>("Transactional resources");
8182

82-
private static final ThreadLocal<List<TransactionSynchronization>> synchronizations =
83-
new NamedThreadLocal<List<TransactionSynchronization>>("Transaction synchronizations");
83+
private static final ThreadLocal<Set<TransactionSynchronization>> synchronizations =
84+
new NamedThreadLocal<Set<TransactionSynchronization>>("Transaction synchronizations");
8485

8586
private static final ThreadLocal<String> currentTransactionName =
8687
new NamedThreadLocal<String>("Current transaction name");
@@ -256,7 +257,7 @@ public static void initSynchronization() throws IllegalStateException {
256257
throw new IllegalStateException("Cannot activate transaction synchronization - already active");
257258
}
258259
logger.trace("Initializing transaction synchronization");
259-
synchronizations.set(new LinkedList<TransactionSynchronization>());
260+
synchronizations.set(new LinkedHashSet<TransactionSynchronization>());
260261
}
261262

262263
/**
@@ -287,7 +288,7 @@ public static void registerSynchronization(TransactionSynchronization synchroniz
287288
* @see TransactionSynchronization
288289
*/
289290
public static List<TransactionSynchronization> getSynchronizations() throws IllegalStateException {
290-
List<TransactionSynchronization> synchs = synchronizations.get();
291+
Set<TransactionSynchronization> synchs = synchronizations.get();
291292
if (synchs == null) {
292293
throw new IllegalStateException("Transaction synchronization is not active");
293294
}
@@ -299,8 +300,9 @@ public static List<TransactionSynchronization> getSynchronizations() throws Ille
299300
}
300301
else {
301302
// Sort lazily here, not in registerSynchronization.
302-
OrderComparator.sort(synchs);
303-
return Collections.unmodifiableList(new ArrayList<TransactionSynchronization>(synchs));
303+
List<TransactionSynchronization> sortedSynchs = new ArrayList<TransactionSynchronization>(synchs);
304+
OrderComparator.sort(sortedSynchs);
305+
return Collections.unmodifiableList(sortedSynchs);
304306
}
305307
}
306308

0 commit comments

Comments
 (0)