use of javax.sql.ConnectionPoolDataSource in project narayana by jbosstm.
the class PerformanceTestCommitMarkableResource method testCommitMarkableResource.
// @org.junit.Ignore
@Test
public void testCommitMarkableResource() throws Exception {
System.out.println("testCommitMarkableResource: " + new Date());
ConnectionPoolDataSource dataSource = null;
DataSource recoveryDataSource = null;
if (dbType.equals("oracle")) {
// ORA-01795: maximum number of expressions in a list is 1000
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(1000);
Class clazz = Class.forName("oracle.jdbc.pool.OracleConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) clazz.newInstance();
clazz.getMethod("setDriverType", new Class[] { String.class }).invoke(dataSource, new Object[] { "thin" });
clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
clazz.getMethod("setNetworkProtocol", new Class[] { String.class }).invoke(dataSource, new Object[] { "tcp" });
clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "orcl" });
clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "dtf11" });
clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "dtf11" });
clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 1521 });
recoveryDataSource = (DataSource) dataSource;
} else if (dbType.equals("sybase")) {
// wide table support?
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(2000);
Class clazz = Class.forName("com.sybase.jdbc3.jdbc.SybConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) clazz.newInstance();
clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "192.168.1.5" });
clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "LOCALHOST" });
clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "sa" });
clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "sybase" });
clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 5000 });
Class clazz2 = Class.forName("com.sybase.jdbc3.jdbc.SybDataSource");
recoveryDataSource = (DataSource) clazz2.newInstance();
clazz2.getMethod("setServerName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "192.168.1.5" });
clazz2.getMethod("setDatabaseName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "LOCALHOST" });
clazz2.getMethod("setUser", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "sa" });
clazz2.getMethod("setPassword", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "sybase" });
clazz2.getMethod("setPortNumber", new Class[] { int.class }).invoke(recoveryDataSource, new Object[] { 5000 });
} else if (dbType.equals("h2")) {
// Smaller batch size as H2 uses a hashtable in the delete which is
// inefficent for bytearray clause
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(100);
dataSource = new JdbcDataSource();
((JdbcDataSource) dataSource).setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
recoveryDataSource = ((JdbcDataSource) dataSource);
} else if (dbType.equals("postgres")) {
dataSource = new PGConnectionPoolDataSource();
((PGConnectionPoolDataSource) dataSource).setPortNumber(5432);
((PGConnectionPoolDataSource) dataSource).setUser("dtf11");
((PGConnectionPoolDataSource) dataSource).setPassword("dtf11");
((PGConnectionPoolDataSource) dataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
((PGConnectionPoolDataSource) dataSource).setDatabaseName("jbossts");
recoveryDataSource = new PGSimpleDataSource();
((PGSimpleDataSource) recoveryDataSource).setPortNumber(5432);
((PGSimpleDataSource) recoveryDataSource).setUser("dtf11");
((PGSimpleDataSource) recoveryDataSource).setPassword("dtf11");
((PGSimpleDataSource) recoveryDataSource).setServerName("tywin.eng.hst.ams2.redhat.com");
((PGSimpleDataSource) recoveryDataSource).setDatabaseName("jbossts");
} else if (dbType.equals("mysql")) {
// com.mysql.jdbc.PacketTooBigException: Packet for query is too
// large (1318148 > 1048576). You can change this value on the
// server by setting the max_allowed_packet' variable
BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class).setCommitMarkableResourceRecordDeleteBatchSize(3500);
dataSource = new MysqlConnectionPoolDataSource();
// need paranoid as otherwise it sends a connection change user
((MysqlConnectionPoolDataSource) dataSource).setUrl("jdbc:mysql://tywin.eng.hst.ams2.redhat.com:3306/jbossts?user=dtf11&password=dtf11¶noid=true");
recoveryDataSource = (DataSource) dataSource;
} else if (dbType.equals("db2")) {
Class clazz = Class.forName("com.ibm.db2.jcc.DB2ConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) clazz.newInstance();
clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "BTDB1" });
clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "db2" });
clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "db2" });
clazz.getMethod("setDriverType", new Class[] { int.class }).invoke(dataSource, new Object[] { 4 });
clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 50001 });
Class clazz2 = Class.forName("com.ibm.db2.jcc.DB2DataSource");
recoveryDataSource = (DataSource) clazz2.newInstance();
clazz2.getMethod("setServerName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "tywin.eng.hst.ams2.redhat.com" });
clazz2.getMethod("setDatabaseName", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "BTDB1" });
clazz2.getMethod("setUser", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "db2" });
clazz2.getMethod("setPassword", new Class[] { String.class }).invoke(recoveryDataSource, new Object[] { "db2" });
clazz2.getMethod("setDriverType", new Class[] { int.class }).invoke(recoveryDataSource, new Object[] { 4 });
clazz2.getMethod("setPortNumber", new Class[] { int.class }).invoke(recoveryDataSource, new Object[] { 50001 });
} else if (dbType.equals("sqlserver")) {
Class clazz = Class.forName("com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource");
dataSource = (ConnectionPoolDataSource) clazz.newInstance();
clazz.getMethod("setServerName", new Class[] { String.class }).invoke(dataSource, new Object[] { "dev30.mw.lab.eng.bos.redhat.com" });
clazz.getMethod("setDatabaseName", new Class[] { String.class }).invoke(dataSource, new Object[] { "dballo01" });
clazz.getMethod("setUser", new Class[] { String.class }).invoke(dataSource, new Object[] { "dballo01" });
clazz.getMethod("setPassword", new Class[] { String.class }).invoke(dataSource, new Object[] { "dballo01" });
clazz.getMethod("setSendStringParametersAsUnicode", new Class[] { Boolean.class }).invoke(dataSource, new Object[] { false });
clazz.getMethod("setPortNumber", new Class[] { int.class }).invoke(dataSource, new Object[] { 3918 });
recoveryDataSource = (DataSource) dataSource;
}
PooledConnection pooledConnection = dataSource.getPooledConnection();
Utils.createTables(pooledConnection.getConnection());
doTest(new Handler(dataSource, recoveryDataSource), "_testCommitMarkableResource_" + dbType);
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class cdsXid method testDerby3799.
/**
* Regression test for a NullPointerException when trying to use the LOB
* stored procedures after closing and then getting a new logical
* connection. The problem was that the LOB stored procedure objects on the
* server side were closed and not reprepared.
* See Jira issue DERBY-3799.
*/
public void testDerby3799() throws SQLException {
ConnectionPoolDataSource cpDs = J2EEDataSource.getConnectionPoolDataSource();
PooledConnection pc = cpDs.getPooledConnection();
// Get first logical connection.
Connection con1 = pc.getConnection();
Statement stmt = con1.createStatement();
ResultSet rs = stmt.executeQuery("select dClob from derby3799");
assertTrue(rs.next());
rs.getString(1);
rs.close();
con1.close();
// Get second logical connection.
Connection con2 = pc.getConnection();
stmt = con2.createStatement();
rs = stmt.executeQuery("select dClob from derby3799");
assertTrue(rs.next());
// NPE happened here.
rs.getString(1);
con2.close();
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class cdsXid method testCreateInDatabaseName_Pooled.
/**
* Test that a connection to PoolDataSource can be established
* successfully while creating a database using setDatabaseName()
* with create=true
*
* @throws SQLException
*/
public void testCreateInDatabaseName_Pooled() throws SQLException {
// test with PooledConnection
ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
PooledConnection pc = cpds.getPooledConnection();
String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();
J2EEDataSource.setBeanProperty(cpds, "databaseName", dbName + ";create=true");
Connection c;
c = pc.getConnection();
c.setAutoCommit(false);
c.close();
pc.close();
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class cdsXid method testPooledReuseOnClose.
/**
* 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());
}
use of javax.sql.ConnectionPoolDataSource in project derby by apache.
the class cdsXid method testAllDataSources.
public void testAllDataSources() throws SQLException, Exception {
Connection dmc = getConnection();
CallableStatement cs = dmc.prepareCall("call checkConn2(?)");
cs.setString(1, "Nested");
try {
cs.execute();
fail("SQLException of 40XC0 should be thrown!");
} catch (SQLException sqle) {
assertSQLState("40XC0", sqle);
}
cs.setString(1, "Nested2");
cs.execute();
String EmptyMapValue = "OK";
String NullMapValue = "XJ081";
String MapMapValue = "0A000";
Object[] expectedValues = { ResultSet.HOLD_CURSORS_OVER_COMMIT, "XJ010", 2, true, false, EmptyMapValue, NullMapValue, MapMapValue };
assertConnectionOK(expectedValues, "DriverManager ", dmc);
if (usingEmbedded())
assertTenConnectionsUnique();
DataSource dscs = JDBCDataSource.getDataSource();
if (usingEmbedded())
assertToString(dscs);
DataSource ds = dscs;
assertConnectionOK(expectedValues, "DataSource", ds.getConnection());
ConnectionPoolDataSource dsp = J2EEDataSource.getConnectionPoolDataSource();
if (usingEmbedded())
assertToString(dsp);
PooledConnection pc = dsp.getPooledConnection();
// checks currently only implemented for embedded
if (usingEmbedded()) {
SecurityCheck.assertSourceSecurity(pc, "javax.sql.PooledConnection");
}
AssertEventCatcher aes1 = new AssertEventCatcher(1);
pc.addConnectionEventListener(aes1);
// DERBY-2531
// with Network Server / DerbyNetClient, the assertConnectionOK check
// returns a different connection object...
assertConnectionOK(expectedValues, "ConnectionPoolDataSource", pc.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes1.didConnectionClosedEventHappen());
assertFalse(aes1.didConnectionErrorEventHappen());
aes1.resetState();
assertConnectionOK(expectedValues, "ConnectionPoolDataSource", pc.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes1.didConnectionClosedEventHappen());
assertFalse(aes1.didConnectionErrorEventHappen());
aes1.resetState();
XADataSource dsx = J2EEDataSource.getXADataSource();
if (usingEmbedded())
assertToString(dsx);
// shutdown db and check all's still ok thereafter
TestConfiguration.getCurrent().shutdownDatabase();
dmc = getConnection();
cs = dmc.prepareCall("call checkConn2(?)");
// checks currently only implemented for embedded
if (usingEmbedded()) {
SecurityCheck.assertSourceSecurity(cs, "java.sql.CallableStatement");
}
cs.setString(1, "Nested");
try {
cs.execute();
fail("SQLException of 40XC0 should be thrown!");
} catch (SQLException sqle) {
assertSQLState("40XC0", sqle);
}
cs.setString(1, "Nested2");
cs.execute();
XAConnection xac = dsx.getXAConnection();
// checks currently only implemented for embedded
if (usingEmbedded()) {
SecurityCheck.assertSourceSecurity(xac, "javax.sql.XAConnection");
}
AssertEventCatcher aes3 = new AssertEventCatcher(3);
xac.addConnectionEventListener(aes3);
assertConnectionOK(expectedValues, "XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes3.didConnectionClosedEventHappen());
assertFalse(aes3.didConnectionErrorEventHappen());
aes3.resetState();
pc = dsp.getPooledConnection();
AssertEventCatcher aes2 = new AssertEventCatcher(2);
pc.addConnectionEventListener(aes2);
assertConnectionOK(expectedValues, "ConnectionPoolDataSource", pc.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes2.didConnectionClosedEventHappen());
assertFalse(aes2.didConnectionErrorEventHappen());
aes2.resetState();
// test "local" XAConnections
xac = dsx.getXAConnection();
AssertEventCatcher aes4 = new AssertEventCatcher(4);
xac.addConnectionEventListener(aes4);
assertConnectionOK(expectedValues, "XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes4.didConnectionClosedEventHappen());
assertFalse(aes4.didConnectionErrorEventHappen());
aes4.resetState();
assertConnectionOK(expectedValues, "XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes4.didConnectionClosedEventHappen());
assertFalse(aes4.didConnectionErrorEventHappen());
aes4.resetState();
xac.close();
// test "global" XAConnections
xac = dsx.getXAConnection();
AssertEventCatcher aes5 = new AssertEventCatcher(5);
xac.addConnectionEventListener(aes5);
XAResource xar = xac.getXAResource();
// checks currently only implemented for embedded
if (usingEmbedded()) {
SecurityCheck.assertSourceSecurity(xar, "javax.transaction.xa.XAResource");
}
Xid xid = new cdsXid(1, (byte) 35, (byte) 47);
xar.start(xid, XAResource.TMNOFLAGS);
Connection xacc = xac.getConnection();
xacc.close();
expectedValues[0] = ResultSet.CLOSE_CURSORS_AT_COMMIT;
if (usingEmbedded())
expectedValues[1] = "XJ058";
expectedValues[3] = false;
assertConnectionOK(expectedValues, "Global XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes5.didConnectionClosedEventHappen());
assertFalse(aes5.didConnectionErrorEventHappen());
aes5.resetState();
assertConnectionOK(expectedValues, "Global XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes5.didConnectionClosedEventHappen());
assertFalse(aes5.didConnectionErrorEventHappen());
aes5.resetState();
xar.end(xid, XAResource.TMSUCCESS);
expectedValues[0] = ResultSet.HOLD_CURSORS_OVER_COMMIT;
expectedValues[3] = true;
assertConnectionOK(expectedValues, "Switch to local XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes5.didConnectionClosedEventHappen());
assertFalse(aes5.didConnectionErrorEventHappen());
aes5.resetState();
assertConnectionOK(expectedValues, "Switch to local XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes5.didConnectionClosedEventHappen());
assertFalse(aes5.didConnectionErrorEventHappen());
aes5.resetState();
Connection backtoGlobal = xac.getConnection();
xar.start(xid, XAResource.TMJOIN);
expectedValues[0] = ResultSet.CLOSE_CURSORS_AT_COMMIT;
expectedValues[3] = false;
assertConnectionOK(expectedValues, "Switch to global XADataSource", backtoGlobal);
// Check if got connection closed event but not connection error event
assertTrue(aes5.didConnectionClosedEventHappen());
assertFalse(aes5.didConnectionErrorEventHappen());
aes5.resetState();
assertConnectionOK(expectedValues, "Switch to global XADataSource", xac.getConnection());
// Check if got connection closed event but not connection error event
assertTrue(aes5.didConnectionClosedEventHappen());
assertFalse(aes5.didConnectionErrorEventHappen());
aes5.resetState();
xar.end(xid, XAResource.TMSUCCESS);
xar.commit(xid, true);
xac.close();
}
Aggregations