// Path: connector/genericconnector-atomikos-api/src/main/java/ch/maxant/generic_jca_adapter/TransactionConfigurator.java
// public final class TransactionConfigurator {
// 
// 	private TransactionConfigurator() {}
// 	
// 	private static Map<String, RecoverableMSResource> resources = new HashMap<String, RecoverableMSResource>();
// 	
// 	/** one time configuration required for setting up a microservice in a transactional environment. */
// 	public static void setup(String jndiName, final CommitRollbackCallback commitRollbackCallback){
//     	UserTransactionServiceImp utsi = new UserTransactionServiceImp();
//         MicroserviceXAResource ms = new MicroserviceXAResource(jndiName, commitRollbackCallback);
// 		RecoverableMSResource resource = new RecoverableMSResource(ms);
// 		resources.put(jndiName, resource);
// 		utsi.registerResource(resource);
// 	}
// 
// 	/** when your application shutsdown, you should unregister all services that were setup using {@link #setup(String, CommitRollbackHandler)} 
// 	 * or {@link #setup(String, CommitRollbackHandler, long, File)} */
// 	public static void unregisterMicroserviceResourceFactory(String name) {
//     	UserTransactionServiceImp utsi = new UserTransactionServiceImp();
// 		utsi.removeResource(resources.remove(name));
// 	}
// 	
// 	/** @return the {@link CommitRollbackCallback} registered during setup, or null, if none found (eg never registered, or unregistered). */
// 	static CommitRollbackCallback getCommitRollbackCallback(String jndiName){
// 		RecoverableMSResource rr = resources.get(jndiName);
// 		if(rr != null){
// 			return rr.getMicroserviceResource().getUnderlyingConnection();
// 		}
// 		return null;
// 	}
// 	
// }
// 
// Path: connector/genericconnector-api/src/main/java/ch/maxant/generic_jca_adapter/CommitRollbackCallback.java
// public interface CommitRollbackCallback extends Serializable {
// 
//     /** The container will call this function 
//      * to commit a transaction that was successful.
//      * The implementation of this method should
//      * call the EIS in order to commit
//      * the transaction. */
//     void commit(String txid) throws Exception;
//     
//     /** The container will call this function 
//      * to rollback an unsuccessful transaction.
//      * The implementation of this method should
//      * call the EIS in order to rollback
//      * the transaction. */
//     void rollback(String txid) throws Exception;
// 	
// }


import javax.naming.NamingException;
import ch.maxant.generic_jca_adapter.TransactionConfigurator;
import ch.maxant.generic_jca_adapter.CommitRollbackCallback;
import ch.maxant.jca_demo.bookingsystem.BookingSystemWebServiceService;
import ch.maxant.jca_demo.letterwriter.LetterWebServiceService;
/*
   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.demo;



public abstract class BaseMain {

	protected static void setupCommitRollbackHandlerForMicroserviceWhichIsCalled() throws NamingException {
    	{//setup microservices that we want to call within a transaction
    		
    		CommitRollbackCallback bookingCommitRollbackCallback = new CommitRollbackCallback() {
				private static final long serialVersionUID = 1L;
				@Override
    			public void rollback(String txid) throws Exception {
    				new BookingSystemWebServiceService().getBookingSystemPort().cancelTickets(txid);
    			}
    			@Override
    			public void commit(String txid) throws Exception {
    				new BookingSystemWebServiceService().getBookingSystemPort().bookTickets(txid);
    			}
    		};
    		TransactionConfigurator.setup("xa/bookingService", bookingCommitRollbackCallback);

// Path: connector/genericconnector-atomikos-api/src/main/java/ch/maxant/generic_jca_adapter/TransactionConfigurator.java
// public final class TransactionConfigurator {
// 
// 	private TransactionConfigurator() {}
// 	
// 	private static Map<String, RecoverableMSResource> resources = new HashMap<String, RecoverableMSResource>();
// 	
// 	/** one time configuration required for setting up a microservice in a transactional environment. */
// 	public static void setup(String jndiName, final CommitRollbackCallback commitRollbackCallback){
//     	UserTransactionServiceImp utsi = new UserTransactionServiceImp();
//         MicroserviceXAResource ms = new MicroserviceXAResource(jndiName, commitRollbackCallback);
// 		RecoverableMSResource resource = new RecoverableMSResource(ms);
// 		resources.put(jndiName, resource);
// 		utsi.registerResource(resource);
// 	}
// 
// 	/** when your application shutsdown, you should unregister all services that were setup using {@link #setup(String, CommitRollbackHandler)} 
// 	 * or {@link #setup(String, CommitRollbackHandler, long, File)} */
// 	public static void unregisterMicroserviceResourceFactory(String name) {
//     	UserTransactionServiceImp utsi = new UserTransactionServiceImp();
// 		utsi.removeResource(resources.remove(name));
// 	}
// 	
// 	/** @return the {@link CommitRollbackCallback} registered during setup, or null, if none found (eg never registered, or unregistered). */
// 	static CommitRollbackCallback getCommitRollbackCallback(String jndiName){
// 		RecoverableMSResource rr = resources.get(jndiName);
// 		if(rr != null){
// 			return rr.getMicroserviceResource().getUnderlyingConnection();
// 		}
// 		return null;
// 	}
// 	
// }
// 
// Path: connector/genericconnector-api/src/main/java/ch/maxant/generic_jca_adapter/CommitRollbackCallback.java
// public interface CommitRollbackCallback extends Serializable {
// 
//     /** The container will call this function 
//      * to commit a transaction that was successful.
//      * The implementation of this method should
//      * call the EIS in order to commit
//      * the transaction. */
//     void commit(String txid) throws Exception;
//     
//     /** The container will call this function 
//      * to rollback an unsuccessful transaction.
//      * The implementation of this method should
//      * call the EIS in order to rollback
//      * the transaction. */
//     void rollback(String txid) throws Exception;
// 	
// }


// Path: demo/genericconnector-demo-springboot-atomikos/src/main/java/ch/maxant/generic_jca_adapter/demo/BaseMain.java
import javax.naming.NamingException;
import ch.maxant.generic_jca_adapter.TransactionConfigurator;
import ch.maxant.generic_jca_adapter.CommitRollbackCallback;
import ch.maxant.jca_demo.bookingsystem.BookingSystemWebServiceService;
import ch.maxant.jca_demo.letterwriter.LetterWebServiceService;

/*
   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.demo;



public abstract class BaseMain {

	protected static void setupCommitRollbackHandlerForMicroserviceWhichIsCalled() throws NamingException {
    	{//setup microservices that we want to call within a transaction
    		
    		CommitRollbackCallback bookingCommitRollbackCallback = new CommitRollbackCallback() {
				private static final long serialVersionUID = 1L;
				@Override
    			public void rollback(String txid) throws Exception {
    				new BookingSystemWebServiceService().getBookingSystemPort().cancelTickets(txid);
    			}
    			@Override
    			public void commit(String txid) throws Exception {
    				new BookingSystemWebServiceService().getBookingSystemPort().bookTickets(txid);
    			}
    		};
    		TransactionConfigurator.setup("xa/bookingService", bookingCommitRollbackCallback);

    		CommitRollbackCallback letterCommitRollbackCallback = new CommitRollbackCallback() {