use of org.apache.derby.client.ClientXADataSourceInterface in project derby by apache.
the class cdsXid method testClientMessageTextConnectionAttribute.
/**
* Check that messageText connection attribute functions correctly.
* retrievemessagetext was tested in checkdriver, and derbynet/testij,
* but not tested for datasources, and in datasourcepermissions_net,
* but as it has nothing to do with permissions/authentication,
* this test seems a better place for it.
*
* There is a corresponding fixture for clientDataSource in DataSourceTest
*
* @throws SQLException
*/
public void testClientMessageTextConnectionAttribute() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
String retrieveMessageTextProperty = "retrieveMessageText";
// with ConnectionPoolDataSource
// ConnectionPoolDataSource - retrieveMessageTextProperty
ClientConnectionPoolDataSourceInterface cpds;
Class<?> clazz;
if (JDBC.vmSupportsJNDI()) {
clazz = Class.forName("org.apache.derby.jdbc.ClientConnectionPoolDataSource");
cpds = (ClientConnectionPoolDataSourceInterface) clazz.getConstructor().newInstance();
} else {
clazz = Class.forName("org.apache.derby.jdbc.BasicClientConnectionPoolDataSource40");
cpds = (ClientConnectionPoolDataSourceInterface) clazz.getConstructor().newInstance();
}
cpds.setPortNumber(TestConfiguration.getCurrent().getPort());
cpds.setDatabaseName(dbName);
cpds.setConnectionAttributes(retrieveMessageTextProperty + "=false");
PooledConnection cpConn = cpds.getPooledConnection();
assertMessageText(cpConn.getConnection(), "false");
cpConn.close();
cpds.setConnectionAttributes(retrieveMessageTextProperty + "=true");
cpConn = cpds.getPooledConnection();
assertMessageText(cpConn.getConnection(), "true");
cpds.setConnectionAttributes(null);
cpConn.close();
// now with XADataSource
ClientXADataSourceInterface xads;
if (JDBC.vmSupportsJNDI()) {
clazz = Class.forName("org.apache.derby.jdbc.ClientXADataSource");
xads = (ClientXADataSourceInterface) clazz.getConstructor().newInstance();
} else {
clazz = Class.forName("org.apache.derby.jdbc.BasicClientXADataSource40");
xads = (ClientXADataSourceInterface) clazz.getConstructor().newInstance();
}
// XADataSource - retrieveMessageTextProperty
xads.setPortNumber(TestConfiguration.getCurrent().getPort());
xads.setDatabaseName(dbName);
xads.setConnectionAttributes(retrieveMessageTextProperty + "=false");
XAConnection xaConn = xads.getXAConnection();
assertMessageText(xaConn.getConnection(), "false");
xaConn.close();
xads.setConnectionAttributes(retrieveMessageTextProperty + "=true");
xaConn = xads.getXAConnection();
assertMessageText(xaConn.getConnection(), "true");
xaConn.close();
xads.setConnectionAttributes(null);
}
use of org.apache.derby.client.ClientXADataSourceInterface in project derby by apache.
the class cdsXid method testClientDSConnectionAttributes.
// End testBadConnectionAttributeSyntax
/**
* Check that database name set using setConnectionAttributes is not used
* by ClientDataSource. This method tests DERBY-1130.
*
* @throws SQLException
*/
public void testClientDSConnectionAttributes() throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
if (usingEmbedded())
return;
// now with ConnectionPoolDataSource
ClientConnectionPoolDataSourceInterface cpds;
Class<?> clazz;
if (JDBC.vmSupportsJNDI()) {
clazz = Class.forName("org.apache.derby.jdbc.ClientConnectionPoolDataSource");
cpds = (ClientConnectionPoolDataSourceInterface) clazz.getConstructor().newInstance();
} else {
clazz = Class.forName("org.apache.derby.jdbc.BasicClientConnectionPoolDataSource40");
cpds = (ClientConnectionPoolDataSourceInterface) clazz.getConstructor().newInstance();
}
cpds.setPortNumber(TestConfiguration.getCurrent().getPort());
// ConnectionPoolDataSource - EMPTY
dsCPConnectionRequests(new String[] { "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001" }, cpds);
// ConnectionPoolDataSource
// - connectionAttributes=databaseName=<valid dbname>
cpds.setConnectionAttributes("databaseName=" + dbName);
dsCPConnectionRequests(new String[] { "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001" }, cpds);
cpds.setConnectionAttributes(null);
// Test that database name specified in connection attributes is
// not used
// ConnectionPoolDataSource - databaseName=wombat and
// connectionAttributes=databaseName=kangaroo
cpds.setConnectionAttributes("databaseName=kangaroo");
cpds.setDatabaseName(dbName);
dsCPConnectionRequests(new String[] { "OK", "08001", "OK", "OK", "08001", "08001", "OK", "OK", "OK" }, cpds);
cpds.setConnectionAttributes(null);
cpds.setDatabaseName(null);
// now with XADataSource
ClientXADataSourceInterface xads;
if (JDBC.vmSupportsJNDI()) {
clazz = Class.forName("org.apache.derby.jdbc.ClientXADataSource");
xads = (ClientXADataSourceInterface) clazz.getConstructor().newInstance();
} else {
clazz = Class.forName("org.apache.derby.jdbc.BasicClientXADataSource40");
xads = (ClientXADataSourceInterface) clazz.getConstructor().newInstance();
}
xads.setPortNumber(TestConfiguration.getCurrent().getPort());
// XADataSource - EMPTY
dsXAConnectionRequests(new String[] { "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001" }, xads);
// XADataSource - connectionAttributes=databaseName=<valid dbname>
xads.setConnectionAttributes("databaseName=wombat");
dsXAConnectionRequests(new String[] { "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001", "08001" }, xads);
xads.setConnectionAttributes(null);
// Test that database name specified in connection attributes is not used
// XADataSource - databaseName=wombat and
// connectionAttributes=databaseName=kangaroo
xads.setConnectionAttributes("databaseName=kangaroo");
xads.setDatabaseName("wombat");
dsXAConnectionRequests(new String[] { "OK", "08001", "OK", "OK", "08001", "08001", "OK", "OK", "OK" }, xads);
xads.setConnectionAttributes(null);
xads.setDatabaseName(null);
}
Aggregations