package io.quarkus.hibernate.orm.runtime.customized;

import javax.transaction.TransactionManager;
import javax.transaction.UserTransaction;

import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform;

public final class QuarkusJtaPlatform extends AbstractJtaPlatform {

    public static final QuarkusJtaPlatform INSTANCE = new QuarkusJtaPlatform();

    private QuarkusJtaPlatform() {
        //nothing
    }

    @Override
    protected TransactionManager locateTransactionManager() {
        return com.arjuna.ats.jta.TransactionManager.transactionManager();
    }

    @Override
    protected UserTransaction locateUserTransaction() {
        return com.arjuna.ats.jta.UserTransaction.userTransaction();
    }

}

@@ -47,16 +47,138 @@
 mized;%0A%0A
+import javax.transaction.Synchronization;%0Aimport javax.transaction.SystemException;%0Aimport javax.transaction.Transaction;%0A
 import j
@@ -319,24 +319,299 @@
 nternal.
-Abstract
+JtaSynchronizationStrategy;%0Aimport org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerAccess;%0Aimport org.hibernate.engine.transaction.jta.platform.internal.TransactionManagerBasedSynchronizationStrategy;%0Aimport org.hibernate.engine.transaction.jta.platform.spi.
 JtaPlatf
@@ -658,24 +658,19 @@
 orm 
-extend
+implement
 s 
-Abstract
 JtaP
@@ -676,16 +676,42 @@
 Platform
+, TransactionManagerAccess
  %7B%0A%0A    
@@ -803,241 +803,854 @@
 ate 
-QuarkusJtaPlatform() %7B%0A        //nothing%0A    %7D%0A%0A    @Override%0A    protected TransactionManager locateTransactionManager() %7B%0A        return com.arjuna.ats.jta.TransactionManager.transactionManager();%0A    %7D%0A%0A    @Override%0A    protected
+final JtaSynchronizationStrategy tmSynchronizationStrategy = new TransactionManagerBasedSynchronizationStrategy(%0A            this);%0A    private volatile TransactionManager transactionManager;%0A    private volatile UserTransaction userTransaction;%0A%0A    private QuarkusJtaPlatform() %7B%0A        //nothing%0A    %7D%0A%0A    @Override%0A    public TransactionManager retrieveTransactionManager() %7B%0A        TransactionManager transactionManager = this.transactionManager;%0A        if (transactionManager == null) %7B%0A            transactionManager = com.arjuna.ats.jta.TransactionManager.transactionManager();%0A            this.transactionManager = transactionManager;%0A        %7D%0A        return transactionManager;%0A    %7D%0A%0A    @Override%0A    public TransactionManager getTransactionManager() %7B%0A        return retrieveTransactionManager();%0A    %7D%0A%0A    @Override%0A    public
  Use
@@ -1666,13 +1666,15 @@
 ion 
-locat
+retriev
 eUse
@@ -1702,65 +1702,873 @@
     
-return com.arjuna.ats.jta.UserTransaction.userTransaction
+UserTransaction userTransaction = this.userTransaction;%0A        if (this.userTransaction == null) %7B%0A            userTransaction = com.arjuna.ats.jta.UserTransaction.userTransaction();%0A            this.userTransaction = userTransaction;%0A        %7D%0A        return userTransaction;%0A    %7D%0A%0A    @Override%0A    public Object getTransactionIdentifier(final Transaction transaction) %7B%0A        return transaction;%0A    %7D%0A%0A    @Override%0A    public void registerSynchronization(Synchronization synchronization) %7B%0A        this.tmSynchronizationStrategy.registerSynchronization(synchronization);%0A    %7D%0A%0A    @Override%0A    public boolean canRegisterSynchronization() %7B%0A        return this.tmSynchronizationStrategy.canRegisterSynchronization();%0A    %7D%0A%0A    @Override%0A    public int getCurrentStatus() throws SystemException %7B%0A        return this.retrieveTransactionManager().getStatus
 ();%0A

Reimplement the QuarkusJTAPlatform to avoid leaking the ORM registry