/*
 *  Copyright (c) 2014-2017 Kumuluz and/or its affiliates
 *  and other contributors as indicated by the @author tags and
 *  the contributor list.
 *
 *  Licensed under the MIT License (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  https://opensource.org/licenses/MIT
 *
 *  The software is provided "AS IS", WITHOUT WARRANTY OF ANY KIND, express or
 *  implied, including but not limited to the warranties of merchantability,
 *  fitness for a particular purpose and noninfringement. in no event shall the
 *  authors or copyright holders be liable for any claim, damages or other
 *  liability, whether in an action of contract, tort or otherwise, arising from,
 *  out of or in connection with the software or the use or other dealings in the
 *  software. See the License for the specific language governing permissions and
 *  limitations under the License.
*/
package com.kumuluz.ee.jta.narayana;

import com.arjuna.ats.jta.common.JTAEnvironmentBean;
import com.arjuna.ats.jta.common.jtaPropertyManager;
import com.kumuluz.ee.jta.common.JtaProvider;
import io.agroal.api.transaction.TransactionIntegration;
import io.agroal.narayana.NarayanaTransactionIntegration;

import javax.transaction.*;

/**
 * @author Marcos Koch Salvador
 * @since 2.3.0
 */
public class NarayanaJtaProvider extends JtaProvider {

    private final JTAEnvironmentBean jtaEnvironment;

    public NarayanaJtaProvider() {
        jtaEnvironment = jtaPropertyManager.getJTAEnvironmentBean();
    }

    @Override
    public UserTransaction getUserTransaction() {
        return jtaEnvironment.getUserTransaction();
    }

    @Override
    public TransactionManager getTransactionManager() {
        return jtaEnvironment.getTransactionManager();
    }

    @Override
    public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() {
        return jtaEnvironment.getTransactionSynchronizationRegistry();
    }

    @Override
    public TransactionIntegration getTransactionIntegration(String jndiName) {
        return new NarayanaTransactionIntegration(getTransactionManager(), getTransactionSynchronizationRegistry(),
                jndiName);
    }

}

@@ -1286,16 +1286,64 @@
 ction.*;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -1500,16 +1500,103 @@
 ronment;
+%0A    private final Map%3CString, NarayanaTransactionIntegration%3E transactionIntegrations;
 %0A%0A    pu
@@ -1689,24 +1689,75 @@
 mentBean();%0A
+        transactionIntegrations = new HashMap%3C%3E();%0A
     %7D%0A%0A    @
@@ -2275,32 +2275,33 @@
 jndiName) %7B%0A
+%0A
         
 return new N
@@ -2288,22 +2288,119 @@
         
-return
+if (!transactionIntegrations.containsKey(jndiName)) %7B%0A            transactionIntegrations.put(jndiName,
  new Nar
@@ -2451,16 +2451,36 @@
 nager(),
+%0A                   
  getTran
@@ -2512,16 +2512,28 @@
 istry(),
+ jndiName));
 %0A       
@@ -2533,24 +2533,27 @@
         
+%7D%0A%0A
         
 jndiName
@@ -2544,16 +2544,51 @@
         
+return transactionIntegrations.get(
 jndiName

Allow multiple calls to getTransactionIntegration with the same JNDI name