Skip to content

Commit

Permalink
Merge pull request #12977 from Sanne/JTAPlatformLeak
Browse files Browse the repository at this point in the history
Reimplement the QuarkusJTAPlatform to avoid leaking the ORM registry
  • Loading branch information
gsmet authored Oct 27, 2020
2 parents 98d7956 + a33daea commit d1f9b48
Showing 1 changed file with 52 additions and 6 deletions.
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();
}

}

0 comments on commit d1f9b48

Please sign in to comment.