Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 550fbf4

Browse files
committed
fix for issue #1
1 parent 82687bd commit 550fbf4

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/main/java/com/davidkarlsen/commonstransaction/spring/CommonsTransactionPlatformTransactionManager.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.springframework.transaction.support.AbstractPlatformTransactionManager;
1616
import org.springframework.transaction.support.DefaultTransactionStatus;
1717
import org.springframework.transaction.support.ResourceTransactionManager;
18+
import org.springframework.transaction.support.TransactionSynchronizationManager;
1819
import org.springframework.util.Assert;
1920

2021
/**
@@ -68,7 +69,13 @@ protected boolean isExistingTransaction( Object transaction )
6869
throw new TransactionSystemException( e.getMessage(), e );
6970
}
7071
}
71-
72+
73+
@Override
74+
protected void doCleanupAfterCompletion( Object transaction )
75+
{
76+
TransactionSynchronizationManager.unbindResourceIfPossible( getResourceFactory() );
77+
}
78+
7279
/**
7380
* {@inheritDoc}
7481
*/
@@ -87,6 +94,7 @@ protected void doCommit( DefaultTransactionStatus status )
8794
}
8895
}
8996

97+
9098
/**
9199
* {@inheritDoc}
92100
*/
@@ -96,12 +104,16 @@ protected Object doGetTransaction()
96104
{
97105
try
98106
{
99-
String txId;
100-
synchronized ( fileResourceManager )
101-
{
102-
txId = fileResourceManager.generatedUniqueTxId();
107+
String txId = (String) TransactionSynchronizationManager.getResource( getResourceFactory() );
108+
109+
if ( txId == null ) {
110+
synchronized ( fileResourceManager )
111+
{
112+
txId = fileResourceManager.generatedUniqueTxId();
113+
TransactionSynchronizationManager.bindResource( getResourceFactory(), txId );
114+
}
115+
log.debug( "Created txId: " + txId );
103116
}
104-
log.debug( "Created txId: " + txId );
105117

106118
return txId;
107119
}

0 commit comments

Comments
 (0)