// Path: components/jta/common/src/main/java/com/kumuluz/ee/jta/common/utils/TxUtils.java
// public class TxUtils {
// 
//     public static Boolean isActive(TransactionManager transactionManager) {
// 
//         try {
//             Transaction tx = transactionManager.getTransaction();
// 
//             return tx != null && JtaProvider.TRANSACTION_ACTIVE_STATUS.contains(tx.getStatus());
//         } catch (SystemException e) {
//             throw new CannotRetrieveTxException(e);
//         }
//     }
// }


import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import com.kumuluz.ee.jta.common.JtaProvider;
import com.kumuluz.ee.jta.common.utils.TxUtils;
import javax.sql.XAConnection;
import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import javax.transaction.xa.XAResource;
import java.sql.*;
        jtaPreInvoke();

        return xaConnection.unwrap(iface);
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {

        checkIfValid();
        jtaPreInvoke();

        return xaConnection.isWrapperFor(iface);
    }

    private void checkIfValid() throws SQLException {

        if (isClosed) throw new SQLException("The connection is closed");
        if (xaConnection == null) throw new SQLException("The connection is invalid");
    }

    private void jtaPreInvoke() throws SQLException {

        if (isEnlistedInJTA) return;

        try {

            if (transactionManager == null) {
                transactionManager = JtaProvider.getInstance().getTransactionManager();
            }

// Path: components/jta/common/src/main/java/com/kumuluz/ee/jta/common/utils/TxUtils.java
// public class TxUtils {
// 
//     public static Boolean isActive(TransactionManager transactionManager) {
// 
//         try {
//             Transaction tx = transactionManager.getTransaction();
// 
//             return tx != null && JtaProvider.TRANSACTION_ACTIVE_STATUS.contains(tx.getStatus());
//         } catch (SystemException e) {
//             throw new CannotRetrieveTxException(e);
//         }
//     }
// }


// Path: components/jta/common/src/main/java/com/kumuluz/ee/jta/common/datasources/JtaXAConnectionWrapper.java
import java.util.Collections;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
import com.kumuluz.ee.jta.common.JtaProvider;
import com.kumuluz.ee.jta.common.utils.TxUtils;
import javax.sql.XAConnection;
import javax.transaction.RollbackException;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
import javax.transaction.TransactionManager;
import javax.transaction.xa.XAResource;
import java.sql.*;

        jtaPreInvoke();

        return xaConnection.unwrap(iface);
    }

    @Override
    public boolean isWrapperFor(Class<?> iface) throws SQLException {

        checkIfValid();
        jtaPreInvoke();

        return xaConnection.isWrapperFor(iface);
    }

    private void checkIfValid() throws SQLException {

        if (isClosed) throw new SQLException("The connection is closed");
        if (xaConnection == null) throw new SQLException("The connection is invalid");
    }

    private void jtaPreInvoke() throws SQLException {

        if (isEnlistedInJTA) return;

        try {

            if (transactionManager == null) {
                transactionManager = JtaProvider.getInstance().getTransactionManager();
            }

            if (TxUtils.isActive(transactionManager)) {