-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12977 from Sanne/JTAPlatformLeak
Reimplement the QuarkusJTAPlatform to avoid leaking the ORM registry
- Loading branch information
Showing
1 changed file
with
52 additions
and
6 deletions.
There are no files selected for viewing
58 changes: 52 additions & 6 deletions
58
...runtime/src/main/java/io/quarkus/hibernate/orm/runtime/customized/QuarkusJtaPlatform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,72 @@ | ||
package io.quarkus.hibernate.orm.runtime.customized; | ||
|
||
import javax.transaction.Synchronization; | ||
import javax.transaction.SystemException; | ||
import javax.transaction.Transaction; | ||
import javax.transaction.TransactionManager; | ||
import javax.transaction.UserTransaction; | ||
|
||
import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform; | ||
import org.hibernate.engine.transaction.jta.platform.internal.JtaSynchronizationStrategy; | ||
import org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerAccess; | ||
import org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy; | ||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; | ||
|
||
public final class QuarkusJtaPlatform extends AbstractJtaPlatform { | ||
public final class QuarkusJtaPlatform implements JtaPlatform, TransactionManagerAccess { | ||
|
||
public static final QuarkusJtaPlatform INSTANCE = new QuarkusJtaPlatform(); | ||
|
||
private final JtaSynchronizationStrategy tmSynchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy( | ||
this); | ||
private volatile TransactionManager transactionManager; | ||
private volatile UserTransaction userTransaction; | ||
|
||
private QuarkusJtaPlatform() { | ||
//nothing | ||
} | ||
|
||
@Override | ||
protected TransactionManager locateTransactionManager() { | ||
return com.arjuna.ats.jta.TransactionManager.transactionManager(); | ||
public TransactionManager retrieveTransactionManager() { | ||
TransactionManager transactionManager = this.transactionManager; | ||
if (transactionManager == null) { | ||
transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager(); | ||
this.transactionManager = transactionManager; | ||
} | ||
return transactionManager; | ||
} | ||
|
||
@Override | ||
public TransactionManager getTransactionManager() { | ||
return retrieveTransactionManager(); | ||
} | ||
|
||
@Override | ||
public UserTransaction retrieveUserTransaction() { | ||
UserTransaction userTransaction = this.userTransaction; | ||
if (this.userTransaction == null) { | ||
userTransaction = com.arjuna.ats.jta.UserTransaction.userTransaction(); | ||
this.userTransaction = userTransaction; | ||
} | ||
return userTransaction; | ||
} | ||
|
||
@Override | ||
public Object getTransactionIdentifier(final Transaction transaction) { | ||
return transaction; | ||
} | ||
|
||
@Override | ||
public void registerSynchronization(Synchronization synchronization) { | ||
this.tmSynchronizationStrategy.registerSynchronization(synchronization); | ||
} | ||
|
||
@Override | ||
public boolean canRegisterSynchronization() { | ||
return this.tmSynchronizationStrategy.canRegisterSynchronization(); | ||
} | ||
|
||
@Override | ||
protected UserTransaction locateUserTransaction() { | ||
return com.arjuna.ats.jta.UserTransaction.userTransaction(); | ||
public int getCurrentStatus() throws SystemException { | ||
return this.retrieveTransactionManager().getStatus(); | ||
} | ||
|
||
} |