// 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 javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ResourceAdapterAssociation;
import javax.security.auth.Subject;
import ch.maxant.generic_jca_adapter.TransactionAssistanceFactory.CommitRollbackRecoveryCallback;
import java.io.File;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.resource.ResourceException;
import javax.resource.spi.ConfigProperty;
import javax.resource.spi.ConnectionDefinition;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionFactory;

                        log.log(Level.SEVERE, msg);
                        throw new RuntimeException(msg);
                    }else{
                        log.log(Level.INFO, "Transaction state for '" + id + "' will be written in new directory '" + recoveryStatePersistenceDirectoryFile.getAbsolutePath() + "'");
                    }
                }else{
                    log.log(Level.INFO, "Transaction state for '" + id + "' will be written in existing directory '" + recoveryStatePersistenceDirectoryFile.getAbsolutePath() + "'");
                }
            }
        }else{
            log.log(Level.WARNING, "The '" + id + "' adapter will NOT track transaction state internally. The associated EIS MUST be able to return incomplete transactions and you MUST provide an implementation of CommitRollbackRecoveryCallback#getTransactionsInNeedOfRecovery()!");
        }
        initialised = true;
    }
    
    @Override
    public Object createConnectionFactory() throws ResourceException {
        lazyInit();
        throw new ResourceException("This resource adapter doesn't support non-managed environments");
    }

    @Override
    public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {
        lazyInit();
        return new TransactionAssistanceFactoryImpl(this, cxManager);
    }

    @Override
    public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
        lazyInit();

// 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/ManagedTransactionAssistanceFactory.java
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ResourceAdapterAssociation;
import javax.security.auth.Subject;
import ch.maxant.generic_jca_adapter.TransactionAssistanceFactory.CommitRollbackRecoveryCallback;
import java.io.File;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.resource.ResourceException;
import javax.resource.spi.ConfigProperty;
import javax.resource.spi.ConnectionDefinition;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionFactory;

                        log.log(Level.SEVERE, msg);
                        throw new RuntimeException(msg);
                    }else{
                        log.log(Level.INFO, "Transaction state for '" + id + "' will be written in new directory '" + recoveryStatePersistenceDirectoryFile.getAbsolutePath() + "'");
                    }
                }else{
                    log.log(Level.INFO, "Transaction state for '" + id + "' will be written in existing directory '" + recoveryStatePersistenceDirectoryFile.getAbsolutePath() + "'");
                }
            }
        }else{
            log.log(Level.WARNING, "The '" + id + "' adapter will NOT track transaction state internally. The associated EIS MUST be able to return incomplete transactions and you MUST provide an implementation of CommitRollbackRecoveryCallback#getTransactionsInNeedOfRecovery()!");
        }
        initialised = true;
    }
    
    @Override
    public Object createConnectionFactory() throws ResourceException {
        lazyInit();
        throw new ResourceException("This resource adapter doesn't support non-managed environments");
    }

    @Override
    public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException {
        lazyInit();
        return new TransactionAssistanceFactoryImpl(this, cxManager);
    }

    @Override
    public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException {
        lazyInit();

        CommitRollbackRecoveryCallback callback = ((GenericResourceAdapter)this.resourceAdapter).getCommitRollbackRecoveryCallback(id);
