You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2008/01/29 01:19:10 UTC
svn commit: r616121 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting:
functionTests/tests/jdbc4/DataSourceTest.java
functionTests/tests/jdbcapi/DataSourceTest.java junit/J2EEDataSource.java
junit/JDBCDataSource.java
Author: djd
Date: Mon Jan 28 16:19:07 2008
New Revision: 616121
URL: http://svn.apache.org/viewvc?rev=616121&view=rev
Log:
Partial cleanup of jdbcapi,jdbc4.DataSourceTest to use utility methods to obtain already configured data sources. The static database name field is not a correct approach since it will be set once when the class is loaded and thus incorrect if the test is executed in a decorator that changes then configuration. The utility methods return a correctly configured data source.
Clarify that the utility methods that return data sources return a new one.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java?rev=616121&r1=616120&r2=616121&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/DataSourceTest.java Mon Jan 28 16:19:07 2008
@@ -27,6 +27,7 @@
import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource;
import org.apache.derbyTesting.functionTests.tests.jdbcapi.AssertEventCatcher;
import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.J2EEDataSource;
import org.apache.derbyTesting.junit.JDBC;
import org.apache.derbyTesting.junit.JDBCDataSource;
import org.apache.derbyTesting.junit.TestConfiguration;
@@ -43,8 +44,6 @@
//Default DataSource that will be used by the tests
private DataSource ds = null;
- protected static String dbName =
- TestConfiguration.getCurrent().getDefaultDatabaseName();
/**
*
@@ -130,32 +129,17 @@
*/
public void testConnectionErrorEvent() throws SQLException, Exception
{
- Connection conn;
- ConnectionPoolDataSource ds;
- PooledConnection pc;
- Statement st;
AssertEventCatcher aes12 = new AssertEventCatcher(12);
//Get the correct ConnectionPoolDataSource object
- if (usingEmbedded())
- {
- ds = new EmbeddedConnectionPoolDataSource();
- ((EmbeddedConnectionPoolDataSource)ds).setDatabaseName(dbName);
- } else
- {
- ds = new ClientConnectionPoolDataSource();
- ((ClientConnectionPoolDataSource)ds).setDatabaseName(dbName);
- }
- pc = ds.getPooledConnection();
+ ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
+
+ PooledConnection pc = ds.getPooledConnection();
//Add a connection event listener to ConnectionPoolDataSource
pc.addConnectionEventListener(aes12);
- conn = pc.getConnection();
- st = conn.createStatement();
- //TAB1 does not exist and hence catch the expected exception
- try {
- st.executeUpdate("drop table TAB1");
- } catch (SQLException sqle) {
- assertSQLState("42Y55", sqle);
- }
+ Connection conn = pc.getConnection();
+
+ dropTable(conn, "TAB1");
+
//No event should have been generated at this point
assertFalse(aes12.didConnectionClosedEventHappen());
assertFalse(aes12.didConnectionErrorEventHappen());
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java?rev=616121&r1=616120&r2=616121&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/DataSourceTest.java Mon Jan 28 16:19:07 2008
@@ -199,32 +199,18 @@
*/
public void testConnectionErrorEvent() throws SQLException, Exception
{
- Connection conn;
- ConnectionPoolDataSource ds;
- PooledConnection pc;
- Statement st;
AssertEventCatcher aes12 = new AssertEventCatcher(12);
- //Get the correct ConnectionPoolDataSource object
- if (usingEmbedded())
- {
- ds = new EmbeddedConnectionPoolDataSource();
- ((EmbeddedConnectionPoolDataSource)ds).setDatabaseName(dbName);
- } else
- {
- ds = new ClientConnectionPoolDataSource();
- ((ClientConnectionPoolDataSource)ds).setDatabaseName(dbName);
- }
- pc = ds.getPooledConnection();
+
+ ConnectionPoolDataSource ds = J2EEDataSource.getConnectionPoolDataSource();
+
+ PooledConnection pc = ds.getPooledConnection();
//Add a connection event listener to ConnectionPoolDataSource
pc.addConnectionEventListener(aes12);
- conn = pc.getConnection();
- st = conn.createStatement();
- //TAB1 does not exist and hence catch the expected exception
- try {
- st.executeUpdate("drop table TAB1");
- } catch (SQLException sqle) {
- assertSQLState("42Y55", sqle);
- }
+ Connection conn = pc.getConnection();
+ Statement st = conn.createStatement();
+
+ dropTable(conn, "TAB1");
+
//No event should have been generated at this point
assertFalse(aes12.didConnectionClosedEventHappen());
assertFalse(aes12.didConnectionErrorEventHappen());
@@ -602,8 +588,7 @@
}
ConnectionPoolDataSource dsp =
- J2EEDataSource.getConnectionPoolDataSource();
- JDBCDataSource.setBeanProperty(dsp, "DatabaseName", dbName);
+ J2EEDataSource.getConnectionPoolDataSource();
if (usingEmbedded())
assertToString(dsp);
@@ -778,8 +763,7 @@
// verify that outstanding updates from a closed connection, obtained
// from a ConnectionPoolDataSource, are not committed, but rolled back.
ConnectionPoolDataSource dsp =
- J2EEDataSource.getConnectionPoolDataSource();
- JDBCDataSource.setBeanProperty(dsp, "DatabaseName", dbName);
+ J2EEDataSource.getConnectionPoolDataSource();
PooledConnection pc = dsp.getPooledConnection();
Connection c1 = pc.getConnection();
Statement s = c1.createStatement();
@@ -828,7 +812,6 @@
// verify that outstanding updates from a closed connection, obtained
// from an XADataSource, are not committed, but rolled back.
XADataSource dsx = J2EEDataSource.getXADataSource();
- JDBCDataSource.setBeanProperty(dsx, "DatabaseName", dbName);
XAConnection xac = dsx.getXAConnection();
Connection c1 = xac.getConnection();
Statement s = c1.createStatement();
@@ -1541,7 +1524,6 @@
// 3)start another global transaction
XADataSource dsx = J2EEDataSource.getXADataSource();
- JDBCDataSource.setBeanProperty(dsx, "DatabaseName", dbName);
XAConnection xac5 = dsx.getXAConnection();
Xid xid5a = new cdsXid(5, (byte) 119, (byte) 129);
Connection conn5 = xac5.getConnection();
@@ -1673,7 +1655,6 @@
// DataSource - bad connattr syntax
DataSource ds = JDBCDataSource.getDataSource();
- JDBCDataSource.setBeanProperty(ds, "databaseName", dbName);
JDBCDataSource.setBeanProperty(ds, "ConnectionAttributes", "bad");
try {
ds.getConnection();
@@ -1684,11 +1665,9 @@
else if (usingDerbyNetClient())
assertSQLState("XJ212", e);
}
- JDBCDataSource.clearStringBeanProperty(ds, "ConnectionAttributes");
// ConnectionPoolDataSource - bad connatr syntax
ConnectionPoolDataSource cpds = J2EEDataSource.getConnectionPoolDataSource();
- JDBCDataSource.setBeanProperty(cpds, "databaseName", dbName);
JDBCDataSource.setBeanProperty(cpds, "ConnectionAttributes", "bad");
try {
cpds.getPooledConnection();
@@ -1696,11 +1675,9 @@
} catch (SQLException e) {
assertSQLState("XJ028", e);
}
- JDBCDataSource.clearStringBeanProperty(cpds, "ConnectionAttributes");
// XADataSource - bad connattr syntax");
XADataSource xads = J2EEDataSource.getXADataSource();
- JDBCDataSource.setBeanProperty(xads, "databaseName", dbName);
JDBCDataSource.setBeanProperty(xads, "ConnectionAttributes", "bad");
try {
xads.getXAConnection();
@@ -1708,7 +1685,6 @@
} catch (SQLException e) {
assertSQLState("XJ028", e);
}
- JDBCDataSource.clearStringBeanProperty(xads, "ConnectionAttributes");
} // End testBadConnectionAttributeSyntax
/**
@@ -2236,7 +2212,6 @@
return;
// START XA HOLDABILITY TEST
XADataSource dscsx = J2EEDataSource.getXADataSource();
- JDBCDataSource.setBeanProperty(dscsx, "databaseName", dbName);
XAConnection xac = dscsx.getXAConnection();
XAResource xr = xac.getXAResource();
@@ -2589,7 +2564,6 @@
// Test holdability
ConnectionPoolDataSource ds =
J2EEDataSource.getConnectionPoolDataSource();
- JDBCDataSource.setBeanProperty(ds, "databaseName", dbName);
pc1 = ds.getPooledConnection();
assertPooledConnHoldability("PooledConnection", pc1);
pc1.close();
@@ -2608,7 +2582,6 @@
public void testDerby1144XADS() throws SQLException {
XADataSource xds = J2EEDataSource.getXADataSource();
- JDBCDataSource.setBeanProperty(xds, "databaseName", dbName);
// Test xa connection isolation
XAConnection xpc1 = xds.getXAConnection();
assertPooledConnIso("XAConnection", xpc1);
@@ -2799,15 +2772,12 @@
throws SQLException
{
DataSource ds = JDBCDataSource.getDataSource();
- JDBCDataSource.setBeanProperty(ds, "databaseName", dbName);
Connection cadmin = ds.getConnection();
CallableStatement cs = cadmin.prepareCall(
"CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)");
cs.setString(1, property);
cs.setString(2, value);
cs.execute();
-
- JDBCDataSource.setBeanProperty(ds, "databaseName", dbName);
cs.close();
cadmin.close();
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java?rev=616121&r1=616120&r2=616121&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/J2EEDataSource.java Mon Jan 28 16:19:07 2008
@@ -33,7 +33,7 @@
public class J2EEDataSource {
/**
- * Return a DataSource corresponding to the current
+ * Return a new DataSource corresponding to the current
* configuration. The getPooledConnection() method is configured
* to use the user name and password from the configuration.
*/
@@ -60,7 +60,7 @@
}
/**
- * Return an XA DataSource corresponding to the current
+ * Return a new XA DataSource corresponding to the current
* configuration. The getXAConnection() method is configured
* to use the user name and password from the configuration.
*/
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java?rev=616121&r1=616120&r2=616121&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/JDBCDataSource.java Mon Jan 28 16:19:07 2008
@@ -36,7 +36,7 @@
public class JDBCDataSource {
/**
- * Return a DataSource corresponding to the current
+ * Return a new DataSource corresponding to the current
* configuration. The getConnection() method will return
* a connection identical to TestConfiguration.openDefaultConnection().
*/
@@ -46,7 +46,7 @@
}
/**
- * Return a DataSource corresponding to the current
+ * Return a new DataSource corresponding to the current
* configuration except that the databse name is different.
*/
public static javax.sql.DataSource getDataSource(String dbName)