[jboss-svn-commits] JBL Code SVN: r26382 - in labs/jbosstm/trunk/qa: config and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue May 5 14:25:28 EDT 2009
Author: jhalliday
Date: 2009-05-05 14:25:28 -0400 (Tue, 05 May 2009)
New Revision: 26382
Modified:
labs/jbosstm/trunk/qa/build.xml
labs/jbosstm/trunk/qa/config/JBossTS_JTS_JacORB_QA.xml
labs/jbosstm/trunk/qa/run-dtf-local.xml
labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JNDIManager.java
Log:
Refactored JNDIManager to use reflection for configuration of XADatasources and tweaked build to allow different drivers to be used at runtime. JBTM-543
Modified: labs/jbosstm/trunk/qa/build.xml
===================================================================
--- labs/jbosstm/trunk/qa/build.xml 2009-05-05 17:53:56 UTC (rev 26381)
+++ labs/jbosstm/trunk/qa/build.xml 2009-05-05 18:25:28 UTC (rev 26382)
@@ -42,6 +42,7 @@
<fileset id="mssql.drivers" dir="${driver.home}/mssql2005_sqljdbc_2.0/enu/">
<include name="sqljdbc.jar"/>
+ <include name="sqljdbc4.jar"/>
</fileset>
<!-- 8.1.408 is broken, use something more recent. -->
@@ -64,7 +65,7 @@
</fileset>
<!-- you should not need to configure anything below here -->
-
+
<property name="driver.url" value="http://reports.qa.atl.jboss.com/jdbc-drivers/"/>
<property name="org.jboss.jbossts.qa.server_manager_location" location="ext/jboss-server-manager-0.1.1.GA.jar"/>
@@ -78,36 +79,38 @@
<fileset refid="ibmdb2.drivers"/>
<fileset refid="sybase.drivers"/>
</path>
-
+
<target name="get.drivers">
-
+
<mkdir dir="${driver.home}/oracle_10_2_0_4"/>
<get src="${driver.url}/ojdbc14.jar"
dest="${driver.home}/oracle_10_2_0_4/ojdbc14.jar"/>
-
+
<mkdir dir="${driver.home}/mssql2005_sqljdbc_2.0/enu"/>
<get src="${driver.url}/sqljdbc_2.0/enu/sqljdbc.jar"
dest="${driver.home}/mssql2005_sqljdbc_2.0/enu/sqljdbc.jar"/>
-
+ <get src="${driver.url}/sqljdbc_2.0/enu/sqljdbc4.jar"
+ dest="${driver.home}/mssql2005_sqljdbc_2.0/enu/sqljdbc4.jar"/>
+
<get src="http://jdbc.postgresql.org/download/postgresql-8.3-604.jdbc3.jar"
dest="${driver.home}/postgresql-8.3-603.jdbc3.jar"/>
-
+
<get src="${driver.url}/mysql-connector-java-5.1.7-bin.jar"
dest="${driver.home}/mysql-connector-java-5.1.7-bin.jar"/>
-
+
<mkdir dir="${driver.home}/DB2_v9"/>
<get src="${driver.url}/DB2_v9/db2jcc.jar"
dest="${driver.home}/DB2_v9/db2jcc.jar"/>
<get src="${driver.url}/DB2_v9/db2jcc_license_cu.jar"
dest="${driver.home}/DB2_v9/db2jcc_license_cu.jar"/>
-
+
<mkdir dir="${driver.home}/jConnect-6_0/classes"/>
<get src="${driver.url}/jConnect-6_0/classes/jconn3.jar"
dest="${driver.home}/jConnect-6_0/classes/jconn3.jar"/>
-
+
</target>
-
+
<target name="buildtype">
<available file="${jbossts.install.lib}/jbossjts.jar" property="buildtype" value="jts"/>
<available file="${jbossts.install.lib}/jts.jar" property="buildtype" value="jts"/>
@@ -180,7 +183,7 @@
<fileset file="tests/build/java.policy"/>
<fileset file="${org.jboss.jbossts.qa.server_manager_location}"/>
</copy>
- <copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/lib" failonerror="${have.dbdrivers}">
+ <copy todir="${org.jboss.jbossts.qa.dist.buildroot}/qa/lib/all_dbdrivers/" failonerror="${have.dbdrivers}">
<fileset refid="oracle.drivers"/>
<fileset refid="mssql.drivers"/>
<fileset refid="pgsql.drivers"/>
Modified: labs/jbosstm/trunk/qa/config/JBossTS_JTS_JacORB_QA.xml
===================================================================
--- labs/jbosstm/trunk/qa/config/JBossTS_JTS_JacORB_QA.xml 2009-05-05 17:53:56 UTC (rev 26381)
+++ labs/jbosstm/trunk/qa/config/JBossTS_JTS_JacORB_QA.xml 2009-05-05 18:25:28 UTC (rev 26382)
@@ -37,6 +37,7 @@
<jar name="$(DTF_HOME)/lib/ext/fscontext.jar"/>
<jar name="$(DTF_HOME)/lib/ext/providerutil.jar"/>
+ <jar name="$(PRODUCT.DIR)/qa/lib/selected_dbdriver/*.jar"/>
<!-- These are no longer required:
<jar name="$(ORB_HOME)/lib/avalon-framework-4.1.5.jar"/>
Modified: labs/jbosstm/trunk/qa/run-dtf-local.xml
===================================================================
--- labs/jbosstm/trunk/qa/run-dtf-local.xml 2009-05-05 17:53:56 UTC (rev 26381)
+++ labs/jbosstm/trunk/qa/run-dtf-local.xml 2009-05-05 18:25:28 UTC (rev 26382)
@@ -28,7 +28,7 @@
1) Run the top level JBossTS ant build: ant jts
2) Run the qa build: cd qa; ant
2) Run the tests: ant -f run-dtf-local.xml
-
+
For general tests plus JDBC (e.g. use on hudson):
cd qa
ant get.drivers dist
@@ -46,7 +46,7 @@
<pathelement location="${working.dir}/lib/ext/junit.jar"/>
<pathelement location="ext/jdom.jar"/>
</path>
-
+
<!-- a faster subset of the tests for smoke testing. aim to keep to under one hour total. -->
<target name="express">
@@ -76,9 +76,9 @@
<antcall target="junit-tests"><param name="tests" value="crashrecovery06"/></antcall>
<!-- crashrecovery12 : 7 tests, 5 minutes -->
<antcall target="junit-tests"><param name="tests" value="crashrecovery12"/></antcall>
-
+
</target>
-
+
<!-- General tests.
Some groups take a really long time and are disabled by default.
The remaining tests should take a combined time of around 4hrs or so.
@@ -142,7 +142,7 @@
<antcall target="junit-tests"><param name="tests" value="crashrecovery12"/></antcall>
</target>
-
+
<!-- long running crash rec test groups (the ones disabled in the 'junit' target) -->
<target name="junit-longer">
<antcall target="junit-tests"><param name="tests" value="crashrecovery02_2"/></antcall>
@@ -150,6 +150,17 @@
<antcall target="junit-tests"><param name="tests" value="crashrecovery08"/></antcall>
</target>
+ <!-- copy the selected db driver out of the available set into the classpath.
+ Drivers are placed into the pool by build.xml and into the classpath by config/<product>.xml
+ -->
+ <target name="install-dbdriver">
+ <delete dir="build/qa/lib/selected_dbdriver"/>
+ <mkdir dir="build/qa/lib/selected_dbdriver"/>
+ <copy todir="build/qa/lib/selected_dbdriver">
+ <fileset dir="build/qa/lib/all_dbdrivers/" includes="${files}"/>
+ </copy>
+ </target>
+
<!-- JDBC tests.
You'll need a qa/config/jdbc_profiles/<hostname>/JDBCProfiles file for your machine to run these ones,
although using the 'default' one is also an option.
@@ -158,24 +169,35 @@
-->
<target name="junit-jdbc">
- <antcall target="junit-tests"><param name="tests" value="jdbcresources01-oracle_thin_jndi"/></antcall>
+ <antcall target="install-dbdriver"><param name="files" value="ojdbc14.jar"/></antcall>
+ <antcall target="junit-tests"><param name="tests" value="jdbcresources01-oracle_thin_jndi"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources02-oracle_thin_jndi"/></antcall>
-
+
+ <!-- mssql needs different .jar for jdk 1.5 vs. 1.6 runtime -->
+ <condition property="mssql.driver" value="sqljdbc4.jar">
+ <equals arg1="${java.specification.version}" arg2="1.6"/>
+ </condition>
+ <property name="mssql.driver" value="sqljdbc.jar"/>
+ <antcall target="install-dbdriver"><param name="files" value="${mssql.driver}"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources01_mssqlserver_jndi"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources02_mssqlserver_jndi"/></antcall>
+ <antcall target="install-dbdriver"><param name="files" value="db2*"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources01-ibmdb2_jndi"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources02-ibmdb2_jndi"/></antcall>
+ <antcall target="install-dbdriver"><param name="files" value="postgresql-8.3-603.jdbc3.jar"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources01-pgsql_jndi"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources02-pgsql_jndi"/></antcall>
+ <antcall target="install-dbdriver"><param name="files" value="mysql-connector-java-5.1.7-bin.jar"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources01-mysql_jndi"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources02-mysql_jndi"/></antcall>
+ <antcall target="install-dbdriver"><param name="files" value="jconn3.jar"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources01-sybase_jndi"/></antcall>
<antcall target="junit-tests"><param name="tests" value="jdbcresources02-sybase_jndi"/></antcall>
-
+
</target>
<target name="junit-tests">
Modified: labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JNDIManager.java
===================================================================
--- labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JNDIManager.java 2009-05-05 17:53:56 UTC (rev 26381)
+++ labs/jbosstm/trunk/qa/tests/src/org/jboss/jbossts/qa/Utils/JNDIManager.java 2009-05-05 18:25:28 UTC (rev 26382)
@@ -32,22 +32,13 @@
import com.arjuna.ats.internal.jdbc.DynamicClass;
-//import com.microsoft.jdbcx.sqlserver.SQLServerDataSource;
-import com.microsoft.sqlserver.jdbc.*;
-
-import com.sybase.jdbc3.jdbc.SybXADataSource;
-
-import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
-import com.mysql.jdbc.jdbc2.optional.MysqlXADataSource;
-import org.postgresql.xa.PGXADataSource;
-import com.ibm.db2.jcc.DB2XADataSource;
-
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.XADataSource;
import java.util.Hashtable;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
-
public class JNDIManager
{
public static void main(String[] args)
@@ -70,6 +61,9 @@
throw new Exception("Driver or binding was not specified");
}
+ // We use reflection to configure the data source so as to avoid a compile or runtime
+ // dependency on all the drivers. see JBTM-543
+
if (driver.equals("com.arjuna.ats.jdbc.TransactionalDriver"))
{
if ((dynamicClass == null) || (databaseURL == null))
@@ -84,19 +78,6 @@
xaDataSourceToBind = xaDataSource;
}
- /*
- else if (driver.equals ("COM.cloudscape.core.JDBCDriver"))
- {
- if (databaseName == null)
- throw new Exception ("DatabaseName was not specified for profile: " + profileName);
-
- COM.cloudscape.core.XaDataSource specificXaDataSource = (COM.cloudscape.core.XaDataSource )COM.cloudscape.core.DataSourceFactory.getXADataSource();
- specificXaDataSource.setDatabaseName (databaseName);
- specificXaDataSource.setCreateDatabase ("create"); // create db if not present
-
- xaDataSourceToBind = (XADataSource )specificXaDataSource;
- }
- */
else if (driver.equals("oracle.jdbc.driver.OracleDriver"))
{
if (databaseName == null)
@@ -104,55 +85,34 @@
throw new Exception("DatabaseName was not specified for profile: " + profileName);
}
- Class c = Class.forName("oracle.jdbc.xa.client.OracleXADataSource");
- oracle.jdbc.xa.client.OracleXADataSource specificXaDataSource = (oracle.jdbc.xa.client.OracleXADataSource) c.newInstance();
- specificXaDataSource.setDatabaseName(databaseName);
- specificXaDataSource.setServerName(host);
- specificXaDataSource.setPortNumber((new Integer(port)).intValue());
- specificXaDataSource.setDriverType("thin");
+ XADataSourceReflectionWrapper wrapper = new XADataSourceReflectionWrapper("oracle.jdbc.xa.client.OracleXADataSource");
- xaDataSourceToBind = specificXaDataSource;
- }
- /*
- else if (driver.equals("com.microsoft.jdbc.sqlserver.SQLServerDriver"))
- {
- // old MS SQL 2005 JDBC driver
+ wrapper.setProperty("databaseName", databaseName);
+ wrapper.setProperty("serverName", host);
+ wrapper.setProperty("portNumber", Integer.valueOf(port));
+ wrapper.setProperty("driverType", "thin");
- if (databaseName == null)
- {
- throw new Exception("DatabaseName was not specified for profile: " + profileName);
- }
-
- SQLServerDataSource specificXaDataSource = new SQLServerDataSource();
- specificXaDataSource.setDatabaseName(databaseName);
- specificXaDataSource.setServerName(host);
- specificXaDataSource.setPortNumber((new Integer(port)).intValue());
- specificXaDataSource.setSelectMethod("cursor");
- specificXaDataSource.setSendStringParametersAsUnicode(false);
- xaDataSourceToBind = specificXaDataSource;
+ xaDataSourceToBind = wrapper.getWrappedXADataSource();
}
- */
else if( driver.equals("com.microsoft.sqlserver.jdbc.SQLServerDriver")) {
- // new MS SQL 2005 driver
- SQLServerXADataSource specificXaDataSource = new SQLServerXADataSource();
- specificXaDataSource.setServerName(host);
- specificXaDataSource.setPortNumber(Integer.parseInt(port));
- specificXaDataSource.setDatabaseName(databaseName);
- //ds.setUser("jbossts1");
- //ds.setPassword("jbossts1");
- specificXaDataSource.setSendStringParametersAsUnicode(false);
- xaDataSourceToBind = specificXaDataSource;
+ XADataSourceReflectionWrapper wrapper = new XADataSourceReflectionWrapper("com.microsoft.sqlserver.jdbc.SQLServerXADataSource");
+
+ wrapper.setProperty("databaseName", databaseName);
+ wrapper.setProperty("serverName", host);
+ wrapper.setProperty("portNumber", Integer.valueOf(port));
+ wrapper.setProperty("sendStringParametersAsUnicode", false);
+
+ xaDataSourceToBind = wrapper.getWrappedXADataSource();
}
else if( driver.equals("org.postgresql.Driver")) {
- PGXADataSource specificXaDataSource = new PGXADataSource();
- specificXaDataSource.setServerName(host);
- specificXaDataSource.setDatabaseName(databaseName);
- //specificXaDataSource.setUser("test");
- //specificXaDataSource.setPassword("testpass");
+ XADataSourceReflectionWrapper wrapper = new XADataSourceReflectionWrapper("org.postgresql.xa.PGXADataSource");
- xaDataSourceToBind = specificXaDataSource;
+ wrapper.setProperty("databaseName", databaseName);
+ wrapper.setProperty("serverName", host);
+
+ xaDataSourceToBind = wrapper.getWrappedXADataSource();
}
else if( driver.equals("com.mysql.jdbc.Driver")) {
@@ -162,48 +122,37 @@
// doing this config on a per connection basis instead is
// possible but would require lots of code changes :-(
- MysqlXADataSource specificXaDataSource = new MysqlXADataSource();
- specificXaDataSource.setDatabaseName(databaseName);
- specificXaDataSource.setServerName(host);
+ XADataSourceReflectionWrapper wrapper = new XADataSourceReflectionWrapper("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
- specificXaDataSource.setPinGlobalTxToPhysicalConnection(true); // Bad Things happen if you forget this bit.
+ wrapper.setProperty("databaseName", databaseName);
+ wrapper.setProperty("serverName", host);
+ wrapper.setProperty("pinGlobalTxToPhysicalConnection", true); // Bad Things happen if you forget this bit.
- xaDataSourceToBind = specificXaDataSource;
+ xaDataSourceToBind = wrapper.getWrappedXADataSource();
}
else if( driver.equals("com.ibm.db2.jcc.DB2Driver")) {
// for DB2 version 8.2
- DB2XADataSource specificXaDataSource = new DB2XADataSource();
- specificXaDataSource.setDriverType(4);
- specificXaDataSource.setDatabaseName(databaseName);
- specificXaDataSource.setServerName(host);
- specificXaDataSource.setPortNumber(Integer.parseInt(port));
- //specificXaDataSource.setUser("jbossts");
- //specificXaDataSource.setPassword("jbossts");
+ XADataSourceReflectionWrapper wrapper = new XADataSourceReflectionWrapper("com.ibm.db2.jcc.DB2XADataSource");
- xaDataSourceToBind = specificXaDataSource;
+ wrapper.setProperty("databaseName", databaseName);
+ wrapper.setProperty("serverName", host);
+ wrapper.setProperty("driverType", 4);
+ wrapper.setProperty("portNumber", Integer.valueOf(port));
+
+ xaDataSourceToBind = wrapper.getWrappedXADataSource();
}
else if( driver.equals("com.sybase.jdbc3.jdbc.SybDriver")) {
- SybXADataSource specificXaDataSource = new SybXADataSource();
+ XADataSourceReflectionWrapper wrapper = new XADataSourceReflectionWrapper("com.sybase.jdbc3.jdbc.SybXADataSource");
- specificXaDataSource.setServerName(host);
- specificXaDataSource.setPortNumber(Integer.parseInt(port));
- specificXaDataSource.setDatabaseName(databaseName);
- //ds.setUser("jbossts0");
- //ds.setPassword("jbossts0");
+ wrapper.setProperty("databaseName", databaseName);
+ wrapper.setProperty("serverName", host);
+ wrapper.setProperty("portNumber", Integer.valueOf(port));
- xaDataSourceToBind = specificXaDataSource;
+ xaDataSourceToBind = wrapper.getWrappedXADataSource();
}
- /*else if (driver.equals("COM.FirstSQL.Dbcp.DbcpXADataSource"))
- {
- COM.FirstSQL.Dbcp.DbcpXADataSource specificXaDataSource = new COM.FirstSQL.Dbcp.DbcpXADataSource();
- specificXaDataSource.setServerName(host);
- specificXaDataSource.setPortNumber((new Integer(port)).intValue());
- xaDataSourceToBind = specificXaDataSource;
- }
- */
else
{
throw new Exception("JDBC2 driver " + driver + " not recognised");
@@ -217,7 +166,7 @@
Hashtable env = new Hashtable();
String initialCtx = System.getProperty("Context.INITIAL_CONTEXT_FACTORY");
String bindingsLocation = System.getProperty("Context.PROVIDER_URL");
-
+
if (bindingsLocation != null)
{
env.put(Context.PROVIDER_URL, bindingsLocation);
@@ -246,4 +195,35 @@
System.out.println("Failed");
}
}
-};
+}
+
+class XADataSourceReflectionWrapper {
+ private XADataSource xaDataSource;
+ XADataSourceReflectionWrapper(String classname) {
+ try {
+ xaDataSource = (XADataSource)Class.forName(classname).newInstance();
+ } catch(Exception e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ public void setProperty(String name, Object value)
+ throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
+ name = "set"+name.substring(0,1).toUpperCase()+name.substring(1);
+
+ Class type = value.getClass();
+ if(value instanceof Integer) {
+ type = Integer.TYPE;
+ }
+ if(value instanceof Boolean) {
+ type = Boolean.TYPE;
+ }
+
+ Method method = xaDataSource.getClass().getMethod(name, type);
+ method.invoke(xaDataSource, value);
+ }
+
+ public XADataSource getWrappedXADataSource() {
+ return xaDataSource;
+ }
+}
More information about the jboss-svn-commits
mailing list