// Path: connector/genericconnector-api/src/main/java/ch/maxant/generic_jca_adapter/TransactionAssistanceFactory.java
// public static interface CommitRollbackRecoveryCallback extends CommitRollbackCallback {
//         
//     /** The container will call this function during
//      * recovery which should call the EIS and must return 
//      * transaction IDs which are known to be incomplete (not 
//      * yet committed or rolled back). Note that if the 
//      * Resource Adapter is configured to manage transaction
//      * state internally, then this method will not
//      * be called and can have an empty implementation. */
//     String[] getTransactionsInNeedOfRecovery();
// 
//     /** Builder enabling use of Java 8 SAMs */ 
//     public static class Builder {
//         private CommitRollbackFunction commit;
//         private CommitRollbackFunction rollback;
//         private RecoveryFunction recovery;
//         public Builder withCommit(CommitRollbackFunction commit){
//             this.commit = commit;
//             return this;
//         }
//         public Builder withRollback(CommitRollbackFunction rollback){
//             this.rollback = rollback;
//             return this;
//         }
//         public Builder withRecovery(RecoveryFunction recovery){
//             this.recovery = recovery;
//             return this;
//         }
//         public CommitRollbackRecoveryCallback build(){
//             Objects.requireNonNull(commit, "Please call withCommit(...)");
//             Objects.requireNonNull(rollback, "Please call withRollback(...)");
//             //recovery is optional, since you can configure adapter to handle state internally
//                 
//             return new CommitRollbackRecoveryCallback(){
// 	private static final long serialVersionUID = 1L;
// 	@Override
//                 public void commit(String txid) throws Exception {
//                     commit.apply(txid);
//                 }
//                 @Override
//                 public void rollback(String txid) throws Exception {
//                     rollback.apply(txid);
//                 }
//                 @Override
//                 public String[] getTransactionsInNeedOfRecovery() {
//                     if(recovery == null){
//                         return new String[0];
//                     }else{
//                         return recovery.getTransactionsInNeedOfRecovery();
//                     }
//                 }
//             };
//         }
//             
//         public static interface RecoveryFunction {
//             String[] getTransactionsInNeedOfRecovery();
//         }
//             
//         public static interface CommitRollbackFunction {
//             void apply(String txid) throws Exception;
//         }
//     }
// }


import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.resource.NotSupportedException;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.ConnectionEventListener;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
import ch.maxant.generic_jca_adapter.TransactionAssistanceFactory.CommitRollbackRecoveryCallback;

/*
   Copyright 2015 Ant Kutschera

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */
package ch.maxant.generic_jca_adapter;




/**
 * There is an assumption here that instances of this class are not thread safe
 * in that they can only be used one at a time.  EXECUTE-COMMIT or EXECUTE-ROLLBACK.
 * The class contains logic to ensure this.
 */
public class ManagedTransactionAssistance implements ManagedConnection, Serializable {

    private static final long serialVersionUID = 1L;

    private final Logger log = Logger.getLogger(this.getClass().getName());

    private PrintWriter logWriter;

    private List<ConnectionEventListener> listeners = new ArrayList<ConnectionEventListener>();

    private TransactionAssistant connection;

    /** was the call to EXECUTE successful? (tristate, null means ready for new connection) */
    private Boolean executeWasSuccessful;

    /** the current transaction ID */
    private String currentTxId;


// Path: connector/genericconnector-api/src/main/java/ch/maxant/generic_jca_adapter/TransactionAssistanceFactory.java
// public static interface CommitRollbackRecoveryCallback extends CommitRollbackCallback {
//         
//     /** The container will call this function during
//      * recovery which should call the EIS and must return 
//      * transaction IDs which are known to be incomplete (not 
//      * yet committed or rolled back). Note that if the 
//      * Resource Adapter is configured to manage transaction
//      * state internally, then this method will not
//      * be called and can have an empty implementation. */
//     String[] getTransactionsInNeedOfRecovery();
// 
//     /** Builder enabling use of Java 8 SAMs */ 
//     public static class Builder {
//         private CommitRollbackFunction commit;
//         private CommitRollbackFunction rollback;
//         private RecoveryFunction recovery;
//         public Builder withCommit(CommitRollbackFunction commit){
//             this.commit = commit;
//             return this;
//         }
//         public Builder withRollback(CommitRollbackFunction rollback){
//             this.rollback = rollback;
//             return this;
//         }
//         public Builder withRecovery(RecoveryFunction recovery){
//             this.recovery = recovery;
//             return this;
//         }
//         public CommitRollbackRecoveryCallback build(){
//             Objects.requireNonNull(commit, "Please call withCommit(...)");
//             Objects.requireNonNull(rollback, "Please call withRollback(...)");
//             //recovery is optional, since you can configure adapter to handle state internally
//                 
//             return new CommitRollbackRecoveryCallback(){
// 	private static final long serialVersionUID = 1L;
// 	@Override
//                 public void commit(String txid) throws Exception {
//                     commit.apply(txid);
//                 }
//                 @Override
//                 public void rollback(String txid) throws Exception {
//                     rollback.apply(txid);
//                 }
//                 @Override
//                 public String[] getTransactionsInNeedOfRecovery() {
//                     if(recovery == null){
//                         return new String[0];
//                     }else{
//                         return recovery.getTransactionsInNeedOfRecovery();
//                     }
//                 }
//             };
//         }
//             
//         public static interface RecoveryFunction {
//             String[] getTransactionsInNeedOfRecovery();
//         }
//             
//         public static interface CommitRollbackFunction {
//             void apply(String txid) throws Exception;
//         }
//     }
// }


// Path: connector/genericconnector-impl/src/main/java/ch/maxant/generic_jca_adapter/ManagedTransactionAssistance.java
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.resource.NotSupportedException;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.ConnectionEventListener;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
import ch.maxant.generic_jca_adapter.TransactionAssistanceFactory.CommitRollbackRecoveryCallback;

/*
   Copyright 2015 Ant Kutschera

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

 */
package ch.maxant.generic_jca_adapter;




/**
 * There is an assumption here that instances of this class are not thread safe
 * in that they can only be used one at a time.  EXECUTE-COMMIT or EXECUTE-ROLLBACK.
 * The class contains logic to ensure this.
 */
public class ManagedTransactionAssistance implements ManagedConnection, Serializable {

    private static final long serialVersionUID = 1L;

    private final Logger log = Logger.getLogger(this.getClass().getName());

    private PrintWriter logWriter;

    private List<ConnectionEventListener> listeners = new ArrayList<ConnectionEventListener>();

    private TransactionAssistant connection;

    /** was the call to EXECUTE successful? (tristate, null means ready for new connection) */
    private Boolean executeWasSuccessful;

    /** the current transaction ID */
    private String currentTxId;


    private CommitRollbackRecoveryCallback commitRollbackRecoveryCallback;
