@Override public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { ConditionMessage.Builder message = ConditionMessage .forCondition("DataSourceAvailable"); if (hasBean(context, DataSource.class) || hasBean(context, XADataSource.class)) { return ConditionOutcome .match(message.foundExactly("existing data source bean")); } if (anyMatches(context, metadata, this.pooledCondition, this.embeddedCondition)) { return ConditionOutcome.match(message .foundExactly("existing auto-configured data source bean")); } return ConditionOutcome .noMatch(message.didNotFind("any existing data source bean").atAll()); }
/** * Creates a new instance of GemFireTransactionDataSource * * @param xaDS The XADataSource object for the database driver. * @param configs - The ConfiguredDataSourceProperties containing the datasource properties. * @throws SQLException */ public GemFireTransactionDataSource(XADataSource xaDS, ConfiguredDataSourceProperties configs) throws SQLException { super(configs); if ((xaDS == null) || (configs == null)) { throw new SQLException( LocalizedStrings.GemFireTransactionDataSource_GEMFIRETRANSACTIONDATASOURCEXADATASOURCE_CLASS_OBJECT_IS_NULL_OR_CONFIGUREDDATASOURCEPROPERTIES_OBJECT_IS_NULL .toLocalizedString()); } try { provider = new GemFireConnectionPoolManager(xaDS, configs, this); transManager = JNDIInvoker.getTransactionManager(); } catch (Exception ex) { String exception = "GemFireTransactionDataSource::Exception = " + ex; if (logger.isDebugEnabled()) { logger.debug(exception, ex); } throw new SQLException(exception); } }
@Bean(name = "mybatisDataSource") public DataSource getDataSource(@Autowired XADataSource xaDataSource, @Autowired TransactionManager transactionManager) { BasicManagedDataSource bds = new BasicManagedDataSource(); bds.setXaDataSourceInstance(xaDataSource); bds.setTransactionManager(transactionManager); bds.setMaxTotal(50); bds.setInitialSize(20); bds.setMaxWaitMillis(60000); bds.setMinIdle(6); bds.setLogAbandoned(true); bds.setRemoveAbandonedOnBorrow(true); bds.setRemoveAbandonedOnMaintenance(true); bds.setRemoveAbandonedTimeout(1800); bds.setTestWhileIdle(true); bds.setTestOnBorrow(false); bds.setTestOnReturn(false); bds.setValidationQuery("select 'x' "); bds.setValidationQueryTimeout(1); bds.setTimeBetweenEvictionRunsMillis(30000); bds.setNumTestsPerEvictionRun(20); return bds; }
@Bean(name = "dataSource") public DataSource getDataSource(@Autowired XADataSource xaDataSource, @Autowired TransactionManager transactionManager) { BasicManagedDataSource bds = new BasicManagedDataSource(); bds.setXaDataSourceInstance(xaDataSource); bds.setTransactionManager(transactionManager); bds.setMaxTotal(50); bds.setInitialSize(20); bds.setMaxWaitMillis(60000); bds.setMinIdle(6); bds.setLogAbandoned(true); bds.setRemoveAbandonedOnBorrow(true); bds.setRemoveAbandonedOnMaintenance(true); bds.setRemoveAbandonedTimeout(1800); bds.setTestWhileIdle(true); bds.setTestOnBorrow(false); bds.setTestOnReturn(false); bds.setValidationQuery("select 'x' "); bds.setValidationQueryTimeout(1); bds.setTimeBetweenEvictionRunsMillis(30000); bds.setNumTestsPerEvictionRun(20); return bds; }
/** * Returns a MySQL XA data source. Note that this method may fail at * run-time if {@code MysqlXADataSource} is not available on the classpath. * * @throws IllegalStateException If the data source cannot be created. * * @see org.alfasoftware.morf.jdbc.DatabaseType#getXADataSource(java.lang.String, * java.lang.String, java.lang.String) */ @Override public XADataSource getXADataSource(String jdbcUrl, String username, String password) { try { log.info("Initialising MySQL XA data source..."); XADataSource dataSource = (XADataSource) Class.forName("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource").newInstance(); dataSource.getClass().getMethod("setURL", String.class).invoke(dataSource, jdbcUrl); dataSource.getClass().getMethod("setUser", String.class).invoke(dataSource, username); dataSource.getClass().getMethod("setPassword", String.class).invoke(dataSource, password); //see http://www.atomikos.com/Documentation/KnownProblems#MySQL_XA_bug //did not have to set com.atomikos.icatch.serial_jta_transactions=false dataSource.getClass().getMethod("setPinGlobalTxToPhysicalConnection", boolean.class).invoke(dataSource, true); return dataSource; } catch (Exception e) { throw new IllegalStateException("Failed to create Oracle XA data source", e); } }
/** * Creates a pooled XA data source. * * @param properties the properties for the data source. * @throws SQLException if unsupported properties are supplied, or if data * source can not be created. * @return a new data source. */ @Override public XADataSource createXADataSource(Properties properties) throws SQLException { // Make copy of properties Properties propertiesCopy = new Properties(); if (properties != null) { propertiesCopy.putAll(properties); } // Verify that no unsupported standard options are used rejectUnsupportedOptions(propertiesCopy); // The integrated connection pool is H2 is not configurable rejectPoolingOptions(propertiesCopy); JdbcDataSource dataSource = new JdbcDataSource(); setupH2DataSource(dataSource, propertiesCopy); return dataSource; }
@Test public void shouldGetConnectionAndCommit() throws SQLException { Connection mockConnection = mock(Connection.class); XAConnection mockXaConnection = mock(XAConnection.class); given(mockXaConnection.getConnection()).willReturn(mockConnection); given(this.dataSource.getXAConnection()).willReturn(mockXaConnection); Properties properties = new Properties(); properties.put(TransactionalDriver.XADataSource, this.dataSource); Connection connection = this.dataSourceBean.getConnection(); assertThat(connection).isInstanceOf(ConnectionImple.class); connection.commit(); verify(this.dataSource, times(1)).getXAConnection(); verify(mockXaConnection, times(1)).getConnection(); verify(mockConnection, times(1)).commit(); }
public Connection openConnection(String databaseName) throws SQLException { JDBCDataSource.setBeanProperty(ds, "databaseName", databaseName); try { return ds.getXAConnection().getConnection(); } catch (SQLException e) { // Expected state for database not found. // For the client the generic 08004 is returned, // will just retry on that. String expectedState = config.getJDBCClient().isEmbedded() ? "XJ004" : "08004"; // If there is a database not found exception // then retry the connection request with // a new DataSource with the createDtabase property set. if (!expectedState.equals(e.getSQLState())) throw e; XADataSource tmpDs = singleUseDS("createDatabase", "create"); JDBCDataSource.setBeanProperty(tmpDs, "databaseName", databaseName); return tmpDs.getXAConnection().getConnection(); } }
protected void assertConSetOK(Object ds, String expectedSQLState, String dbName, String connAttrValue, String setter, String setValue) throws SQLException { JDBCDataSource.setBeanProperty(ds, "databaseName", dbName); JDBCDataSource.setBeanProperty(ds, setter, setValue); JDBCDataSource.setBeanProperty( ds, "ConnectionAttributes", connAttrValue); // check that the db exists; execute an unnecessary, but harmless, stmt try { if (ds instanceof javax.sql.ConnectionPoolDataSource) ((ConnectionPoolDataSource)ds).getPooledConnection(); else ((XADataSource)ds).getXAConnection(); fail("expected an sqlexception " + expectedSQLState); } catch (SQLException se) { assertSQLState(expectedSQLState, se); } JDBCDataSource.clearStringBeanProperty(ds, setter); JDBCDataSource.clearStringBeanProperty(ds, "ConnectionAttributes"); }
protected void assertConnectionWOUPFail( String expectedSqlState, String dbName, String user, String password) throws SQLException { XADataSource xads = J2EEDataSource.getXADataSource(); JDBCDataSource.setBeanProperty(xads, "databaseName", dbName); JDBCDataSource.setBeanProperty(xads, "user", user); JDBCDataSource.setBeanProperty(xads, "password", password); try { xads.getXAConnection(); fail("Connection should've been refused/failed"); } catch (SQLException e) { assertSQLState(expectedSqlState, e); } }
protected void assertShutdownWOUPOK( String dbName, String user, String password) throws SQLException { XADataSource xads = J2EEDataSource.getXADataSource(); JDBCDataSource.setBeanProperty(xads, "databaseName", dbName); JDBCDataSource.setBeanProperty( xads, "shutdownDatabase", "shutdown"); JDBCDataSource.setBeanProperty(xads, "user", user); JDBCDataSource.setBeanProperty(xads, "password", password); try { xads.getXAConnection(); fail ("expected a failed shutdown connection"); } catch (SQLException e) { // expect 08006 on successful shutdown assertSQLState("08006", e); } }
protected void assertShutdownWOUPFail( String expectedSqlState, String dbName, String user, String password) throws SQLException { XADataSource xads = J2EEDataSource.getXADataSource(); JDBCDataSource.setBeanProperty(xads, "shutdownDatabase", "shutdown"); JDBCDataSource.setBeanProperty(xads, "databaseName", dbName); JDBCDataSource.setBeanProperty(xads, "user", user); JDBCDataSource.setBeanProperty(xads, "password", password); try { xads.getXAConnection(); fail("expected failed shutdown"); } catch (SQLException e) { assertSQLState(expectedSqlState, e); } }
protected void assertSystemShutdownOK( String dbName, String user, String password) throws SQLException { XADataSource xads = J2EEDataSource.getXADataSource(); JDBCDataSource.setBeanProperty( xads, "shutdownDatabase", "shutdown"); JDBCDataSource.setBeanProperty(xads, "databaseName", dbName); JDBCDataSource.setBeanProperty(xads, "user", user); JDBCDataSource.setBeanProperty(xads, "password", password); try { xads.getXAConnection(); fail("expected system shutdown resulting in XJ015 error"); } catch (SQLException e) { // expect XJ015, system shutdown, on successful shutdown assertSQLState("XJ015", e); } }
protected void assertSystemShutdownFail( String expectedError, String dbName, String user, String password) throws SQLException { XADataSource xads = J2EEDataSource.getXADataSource(); JDBCDataSource.setBeanProperty( xads, "shutdownDatabase", "shutdown"); JDBCDataSource.setBeanProperty(xads, "databaseName", dbName); JDBCDataSource.setBeanProperty(xads, "user", user); JDBCDataSource.setBeanProperty(xads, "password", password); try { xads.getXAConnection(); fail("expected shutdown to fail"); } catch (SQLException e) { assertSQLState(expectedError, e); } }
public void assertConnectionFail(String dbName) throws SQLException { XADataSource xads = J2EEDataSource.getXADataSource(); // Reset to no user/password though client requires // a valid name, so reset to the default if (usingDerbyNetClient()) JDBCDataSource.setBeanProperty(xads, "user", "APP"); else JDBCDataSource.clearStringBeanProperty(xads, "user"); JDBCDataSource.clearStringBeanProperty(xads, "password"); JDBCDataSource.setBeanProperty(xads, "databaseName", dbName); try { xads.getXAConnection(); fail("expected connection to fail"); } catch (SQLException e) { assertSQLState("08004", e); } }
/** * Test that connections retrieved from {@code XADataSource} that are part * of a global XA transaction, behave as expected when {@code close()} is * called and the transaction is active. */ public void testCloseActiveConnection_XA_global() throws SQLException, XAException { XADataSource ds = J2EEDataSource.getXADataSource(); XAConnection xa = ds.getXAConnection(); XAResource xar = xa.getXAResource(); Xid xid = new cdsXid(1, (byte) 2, (byte) 3); xar.start(xid, XAResource.TMNOFLAGS); // auto-commit is always off in XA transactions, so we expect // getAutoCommit() to return false without having set it explicitly testCloseActiveConnection(xa.getConnection(), false, true); Connection c = xa.getConnection(); c.setAutoCommit(false); testCloseActiveConnection(c, false, true); xar.end(xid, XAResource.TMSUCCESS); }
/** * Test that a PooledConnection can be reused and closed * (separately) during the close event raised by the * closing of its logical connection. * DERBY-2142. * @throws SQLException * */ public void testPooledReuseOnClose() throws SQLException { // PooledConnection from a ConnectionPoolDataSource ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource(); subtestPooledReuseOnClose(cpds.getPooledConnection()); subtestPooledCloseOnClose(cpds.getPooledConnection()); // DERBY-3401 - removing a callback during a close causes problems. subtestPooledRemoveListenerOnClose(cpds.getPooledConnection()); subtestPooledAddListenerOnClose(cpds.getPooledConnection()); // PooledConnection from an XDataSource XADataSource xads = J2EEDataSource.getXADataSource(); subtestPooledReuseOnClose(xads.getXAConnection()); subtestPooledCloseOnClose(xads.getXAConnection()); // DERBY-3401 - removing a callback during a close causes problems. subtestPooledRemoveListenerOnClose(xads.getXAConnection()); subtestPooledAddListenerOnClose(xads.getXAConnection()); }
public void testSetSchemaInXAConnection() throws SQLException { // tests that set schema works correctly in an XA connection. XADataSource dsx = J2EEDataSource.getXADataSource(); XAConnection xac3 = dsx.getXAConnection(); Connection conn3 = xac3.getConnection(); Statement st3 = conn3.createStatement(); st3.execute("SET SCHEMA SCHEMA_Patricio"); st3.close(); PreparedStatement ps3 = conn3.prepareStatement("INSERT INTO Patricio VALUES (?, ?)"); ps3.setString(1, "Patricio"); ps3.setInt(2, 3); ps3.executeUpdate(); assertEquals(1, ps3.getUpdateCount()); ps3.close(); conn3.close(); xac3.close(); }
/** * check whether commit without statement will flow by checking its transaction id * on client. This test is run only for client where commits without an * active transactions will not flow to the server. * DERBY-4653 * * @throws SQLException **/ public void testConnectionFlowCommit() throws SQLException { ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource(); PooledConnection pc = ds.getPooledConnection(); Connection conn = pc.getConnection(); testConnectionFlowCommitWork(conn, 1); conn.close(); //Test for XADataSource XADataSource xs = J2EEDataSource.getXADataSource(); XAConnection xc = xs.getXAConnection(); conn = xc.getConnection(); testConnectionFlowCommitWork(conn, 1); conn.close(); //Test for DataSource DataSource jds = JDBCDataSource.getDataSource(); conn = jds.getConnection(); testConnectionFlowCommitWork(conn, 1); conn.close(); }
private static void dsConnectionRequests( String[] expectedValues, XADataSource ds) { try { ds.getXAConnection(); if (!expectedValues[0].equals("OK")) fail (" expected connection to fail, but was OK"); } catch (SQLException sqle) { assertSQLState(expectedValues[0], sqle); } dsConnectionRequest(expectedValues[1], ds, null, null); dsConnectionRequest(expectedValues[2], ds, "fred", null); dsConnectionRequest(expectedValues[3], ds, "fred", "wilma"); dsConnectionRequest(expectedValues[4], ds, null, "wilma"); dsConnectionRequest( expectedValues[5], ds, null, "databaseName=" + dbName); dsConnectionRequest( expectedValues[6], ds, "fred", "databaseName=" + dbName); dsConnectionRequest(expectedValues[7], ds, "fred", "databaseName=" + dbName + ";password=wilma"); dsConnectionRequest(expectedValues[8], ds, "fred", "databaseName=" + dbName + ";password=betty"); }
@Test public void shouldGetConnectionAndCommitWithCredentials() throws SQLException { String username = "testUsername"; String password = "testPassword"; Connection mockConnection = mock(Connection.class); XAConnection mockXaConnection = mock(XAConnection.class); given(mockXaConnection.getConnection()).willReturn(mockConnection); given(this.dataSource.getXAConnection(username, password)) .willReturn(mockXaConnection); Properties properties = new Properties(); properties.put(TransactionalDriver.XADataSource, this.dataSource); properties.put(TransactionalDriver.userName, username); properties.put(TransactionalDriver.password, password); Connection connection = this.dataSourceBean.getConnection(username, password); assertThat(connection).isInstanceOf(ConnectionImple.class); connection.commit(); verify(this.dataSource, times(1)).getXAConnection(username, password); verify(mockXaConnection, times(1)).getConnection(); verify(mockConnection, times(1)).commit(); }
@Test public void createJdbcResource() throws Exception { Properties jdbc = new Properties(); jdbc.setProperty("url", "jdbc:h2:mem:test"); jdbc.setProperty("user", "sa"); jdbc.setProperty("password", ""); XADataSource xaDs = dsf.createXADataSource(jdbc); DataSource ds = ManagedDataSourceBuilder.builder() .dataSource(xaDs) .transactionManager(tm) .name("h2") .build(); Assert.assertNotNull(ds); }
@Test public void testRecovery() throws Exception { CountDownLatch latch = new CountDownLatch(1); XADataSource xaDs = Mockito.mock(XADataSource.class); XAConnection xaCon = Mockito.mock(XAConnection.class); XAResource xaRes = Mockito.mock(XAResource.class); Connection con = Mockito.mock(Connection.class); Mockito.when(xaDs.getXAConnection()).thenReturn(xaCon); Mockito.when(xaCon.getXAResource()).thenReturn(xaRes); Mockito.when(xaCon.getConnection()).thenReturn(con); Mockito.when(xaRes.recover(anyInt())).thenAnswer(invocation -> { latch.countDown(); return new Xid[0]; }); Mockito.when(con.getAutoCommit()).thenReturn(true); Mockito.when(con.isValid(anyInt())).thenReturn(true); DataSource ds = ManagedDataSourceBuilder.builder() .dataSource(xaDs) .transactionManager(tm) .name("h2") .build(); assertNotNull(ds); assertTrue(latch.await(5, TimeUnit.SECONDS)); }
@Test public void testRecovery() throws Exception { CountDownLatch latch = new CountDownLatch(1); XADataSource xaDs = Mockito.mock(XADataSource.class); XAConnection xaCon = Mockito.mock(XAConnection.class); XAResource xaRes = Mockito.mock(XAResource.class); Connection con = Mockito.mock(Connection.class); Mockito.when(xaDs.getXAConnection()).thenReturn(xaCon); Mockito.when(xaCon.getXAResource()).thenReturn(xaRes); Mockito.when(xaCon.getConnection()).thenReturn(con); Mockito.when(xaRes.recover(TMSTARTRSCAN)).thenAnswer(invocation -> { latch.countDown(); return new Xid[0]; }); Mockito.when(con.getAutoCommit()).thenReturn(true); Mockito.when(con.isValid(anyInt())).thenReturn(true); DataSource ds = ManagedDataSourceBuilder.builder() .dataSource(xaDs) .transactionManager(tm) .name("h2") .build(); assertNotNull(ds); assertTrue(latch.await(5, TimeUnit.SECONDS)); }
@Test public void testRecovery() throws Exception { CountDownLatch latch = new CountDownLatch(1); XADataSource xaDs = Mockito.mock(XADataSource.class); XAConnection xaCon = Mockito.mock(XAConnection.class); XAResource xaRes = Mockito.mock(XAResource.class); Connection con = Mockito.mock(Connection.class); Mockito.when(xaDs.getXAConnection()).thenReturn(xaCon); Mockito.when(xaCon.getXAResource()).thenReturn(xaRes); Mockito.when(xaCon.getConnection()).thenReturn(con); Mockito.when(xaRes.recover(TMSTARTRSCAN + TMENDRSCAN)).thenAnswer(invocation -> { latch.countDown(); return new Xid[0]; }); Mockito.when(con.getAutoCommit()).thenReturn(true); Mockito.when(con.isValid(anyInt())).thenReturn(true); DataSource ds = ManagedDataSourceBuilder.builder() .dataSource(xaDs) .transactionManager(tm) .name("h2") .build(); assertNotNull(ds); assertTrue(latch.await(5, TimeUnit.SECONDS)); }
private static AbstractJdbcManagedConnectionFactory<?, ?, ?> create(CommonDataSource dataSource) { if (dataSource instanceof XADataSource) { return new XADataSourceMCF((XADataSource) dataSource); } else if (dataSource instanceof ConnectionPoolDataSource) { return new ConnectionPoolDataSourceMCF((ConnectionPoolDataSource) dataSource); } else if (dataSource instanceof DataSource) { return new LocalDataSourceMCF((DataSource) dataSource); } else { throw new UnsupportedOperationException(); } }
private DataSource wrap(XADataSource xaDs, int psCacheSize) throws Exception { return ManagedDataSourceBuilder.builder() .transactionManager(tm) .name("hsqlinvm") .dataSource(xaDs) .preparedStatementCacheSize(psCacheSize) .build(); }
private XADataSource createHsqlDataSource() throws SQLException, IOException { JDBCXADataSource ds = new JDBCXADataSource(); ds.setURL("jdbc:hsqldb:mem:target/testdb"); ds.setUser("sa"); ds.setPassword(""); return ds; }
private DataSource wrap(XADataSource xaDs, int psCacheSize) throws Exception { return ManagedDataSourceBuilder.builder() .transactionManager(tm) .name("h2invm") .dataSource(xaDs) .preparedStatementCacheSize(psCacheSize) .build(); }
private XADataSource createH2DataSource() { JdbcDataSource ds = new JdbcDataSource(); ds.setURL("jdbc:h2:mem:test"); ds.setUser("sa"); ds.setPassword(""); return ds; }
public Connection getConnection() throws SQLException { Context ctx = null; try { Object ds = this.datasource; if (ds == null || isAlwaysLookup()) { ctx = (props != null) ? new InitialContext(props): new InitialContext(); ds = ctx.lookup(url); if (!isAlwaysLookup()) { this.datasource = ds; } } if (ds == null) { throw new SQLException( "There is no object at the JNDI URL '" + url + "'"); } if (ds instanceof XADataSource) { return (((XADataSource) ds).getXAConnection().getConnection()); } else if (ds instanceof DataSource) { return ((DataSource) ds).getConnection(); } else { throw new SQLException("Object at JNDI URL '" + url + "' is not a DataSource."); } } catch (Exception e) { this.datasource = null; throw new SQLException( "Could not retrieve datasource via JNDI url '" + url + "' " + e.getClass().getName() + ": " + e.getMessage()); } finally { if (ctx != null) { try { ctx.close(); } catch(Exception ignore) {} } } }
/** * This function returns the datasource with connection pooling and transaction participation * capabilities. * * @param configMap a map containing configurations required for datasource. * @throws DataSourceCreateException * @return ??? */ public static DataSource getTranxDataSource(Map configMap, List props) throws DataSourceCreateException { ConfiguredDataSourceProperties configs = createDataSourceProperties(configMap); String xaClassName = configs.getXADSClass(); if (xaClassName == null) { logger.error(LocalizedMessage.create( LocalizedStrings.DataSourceFactory_DATASOURCEFACTORYGETTRANXDATASOURCEXADATASOURCE_CLASS_NAME_FOR_THE_RESOURCEMANAGER_IS_NOT_AVAILABLE)); throw new DataSourceCreateException( LocalizedStrings.DataSourceFactory_DATASOURCEFACTORYGETTRANXDATASOURCEXADATASOURCE_CLASS_NAME_FOR_THE_RESOURCEMANAGER_IS_NOT_AVAILABLE .toLocalizedString()); } if (TEST_CONNECTION_HOST != null) { props.add(new ConfigProperty("serverName", TEST_CONNECTION_HOST, "java.lang.String")); } if (TEST_CONNECTION_PORT != null) { props.add(new ConfigProperty("portNumber", TEST_CONNECTION_PORT, "int")); } try { Class cl = ClassPathLoader.getLatest().forName(xaClassName); Object Obj = cl.newInstance(); invokeAllMethods(cl, Obj, props); return new GemFireTransactionDataSource((XADataSource) Obj, configs); } catch (Exception ex) { String exception = LocalizedStrings.DataSourceFactory_DATASOURCEFACTORY_GETTRANXDATASOURCE_EXCEPTION_IN_CREATING_GEMFIRETRANSACTIONDATASOURCE__EXCEPTION_STRING_0 .toLocalizedString(new Object[] {ex}); logger.error(LocalizedMessage.create( LocalizedStrings.DataSourceFactory_DATASOURCEFACTORY_GETTRANXDATASOURCE_EXCEPTION_IN_CREATING_GEMFIRETRANSACTIONDATASOURCE__EXCEPTION_STRING_0, ex), ex); throw new DataSourceCreateException(exception, ex); } }
/** * Constructor initializes the ConnectionPoolCacheImpl properties. */ public TranxPoolCacheImpl(XADataSource xads, ConnectionEventListener eventListner, ConfiguredDataSourceProperties configs) throws PoolException { super(eventListner, configs); m_xads = xads; initializePool(); }
/** * Returns an Oracle XA data source. Note that this method may fail at * run-time if {@code OracleXADataSource} is not available on the classpath. * * @throws IllegalStateException If the data source cannot be created. * * @see org.alfasoftware.morf.jdbc.DatabaseType#getXADataSource(java.lang.String, * java.lang.String, java.lang.String) */ @Override public XADataSource getXADataSource(String jdbcUrl, String username, String password) { try { log.info("Initialising Oracle XA data source..."); XADataSource dataSource = (XADataSource) Class.forName("oracle.jdbc.xa.client.OracleXADataSource").newInstance(); dataSource.getClass().getMethod("setURL", String.class).invoke(dataSource, jdbcUrl); dataSource.getClass().getMethod("setUser", String.class).invoke(dataSource, username); dataSource.getClass().getMethod("setPassword", String.class).invoke(dataSource, password); return dataSource; } catch (Exception e) { throw new IllegalStateException("Failed to create Oracle XA data source", e); } }
/** * Returns a SQL Server XA data source. Note that this method may fail at * run-time if {@code SQLServerXADataSource} is not available on the classpath. * * @throws IllegalStateException If the data source cannot be created. * * @see org.alfasoftware.morf.jdbc.DatabaseType#getXADataSource(java.lang.String, * java.lang.String, java.lang.String) */ @Override public XADataSource getXADataSource(String jdbcUrl, String username, String password) { try { log.info("Initialising SQL Server XA data source..."); XADataSource dataSource = (XADataSource) Class.forName("com.microsoft.sqlserver.jdbc.SQLServerXADataSource").newInstance(); dataSource.getClass().getMethod("setURL", String.class).invoke(dataSource, jdbcUrl); dataSource.getClass().getMethod("setUser", String.class).invoke(dataSource, username); dataSource.getClass().getMethod("setPassword", String.class).invoke(dataSource, password); return dataSource; } catch (Exception e) { throw new IllegalStateException("Failed to create SQL Server XA data source", e); } }