1 17 package org.apache.servicemix.eip; 18 19 import javax.resource.spi.ConnectionManager ; 20 import javax.resource.spi.ManagedConnectionFactory ; 21 import javax.sql.DataSource ; 22 import javax.sql.XADataSource ; 23 import javax.transaction.TransactionManager ; 24 25 import org.apache.activemq.broker.BrokerService; 26 import org.apache.derby.jdbc.EmbeddedXADataSource; 27 import org.apache.geronimo.connector.outbound.GenericConnectionManager; 28 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.NoPool; 29 import org.apache.geronimo.connector.outbound.connectionmanagerconfig.XATransactions; 30 import org.apache.geronimo.transaction.context.GeronimoTransactionManager; 31 import org.apache.geronimo.transaction.context.TransactionContextManager; 32 import org.apache.geronimo.transaction.manager.TransactionManagerImpl; 33 import org.apache.geronimo.transaction.manager.XidFactoryImpl; 34 import org.apache.servicemix.client.DefaultServiceMixClient; 35 import org.apache.servicemix.jbi.container.JBIContainer; 36 import org.apache.servicemix.jbi.nmr.flow.Flow; 37 import org.apache.servicemix.jbi.nmr.flow.jca.JCAFlow; 38 import org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow; 39 import org.apache.servicemix.store.Store; 40 import org.apache.servicemix.store.jdbc.JdbcStoreFactory; 41 import org.apache.servicemix.tck.ExchangeCompletedListener; 42 import org.tranql.connector.AllExceptionsAreFatalSorter; 43 import org.tranql.connector.jdbc.AbstractXADataSourceMCF; 44 45 public abstract class AbstractEIPTransactionalTest extends AbstractEIPTest { 46 47 protected BrokerService broker; 48 protected TransactionManager tm; 49 protected DataSource dataSource; 50 protected Store store; 51 52 protected void setUp() throws Exception { 53 broker = new BrokerService(); 55 broker.setUseJmx(false); 56 broker.setPersistent(false); 57 broker.addConnector("tcp://localhost:61616"); 58 broker.start(); 59 60 TransactionManagerImpl exTransactionManager = new TransactionManagerImpl(600, new XidFactoryImpl(), null, null); 61 TransactionContextManager transactionContextManager = new TransactionContextManager(exTransactionManager, exTransactionManager); 62 tm = (TransactionManager ) new GeronimoTransactionManager(transactionContextManager); 63 64 ConnectionManager cm = new GenericConnectionManager( 66 new XATransactions(true, true), 67 new NoPool(), 68 false, 69 null, 70 transactionContextManager, 71 "connectionManager", 72 GenericConnectionManager.class.getClassLoader()); 73 ManagedConnectionFactory mcf = new DerbyDataSourceMCF("target/testdb"); 74 dataSource = (DataSource ) mcf.createConnectionFactory(cm); 75 76 JdbcStoreFactory storeFactory = new JdbcStoreFactory(); 77 storeFactory.setDataSource(dataSource); 78 storeFactory.setTransactional(true); 79 store = storeFactory.open("store"); 80 81 JCAFlow jcaFlow = new JCAFlow(); 82 jcaFlow.setTransactionContextManager(transactionContextManager); 83 84 jbi = new JBIContainer(); 85 jbi.setFlows(new Flow[] { new SedaFlow(), jcaFlow }); 86 jbi.setEmbedded(true); 87 jbi.setUseMBeanServer(false); 88 jbi.setCreateMBeanServer(false); 89 jbi.setTransactionManager(tm); 90 jbi.setAutoEnlistInTransaction(true); 91 listener = new ExchangeCompletedListener(); 92 jbi.addListener(listener); 93 jbi.init(); 94 jbi.start(); 95 96 client = new DefaultServiceMixClient(jbi); 97 } 98 99 protected void tearDown() throws Exception { 100 listener.assertExchangeCompleted(); 101 jbi.shutDown(); 102 broker.stop(); 103 } 104 105 protected void configurePattern(EIPEndpoint endpoint) { 106 endpoint.setStore(store); 107 } 108 109 public static class DerbyDataSourceMCF extends AbstractXADataSourceMCF { 110 private static final long serialVersionUID = 7971682207810098396L; 111 protected DerbyDataSourceMCF(String dbName) { 112 super(createXADS(dbName), new AllExceptionsAreFatalSorter()); 113 } 114 public String getPassword() { 115 return null; 116 } 117 public String getUserName() { 118 return null; 119 } 120 protected static XADataSource createXADS(String dbName) { 121 EmbeddedXADataSource xads = new EmbeddedXADataSource(); 122 xads.setDatabaseName(dbName); 123 xads.setCreateDatabase("create"); 124 return xads; 125 } 126 } 127 128 } 129 | Popular Tags |