commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Fabulich <...@fabulich.com>
Subject Re: [VOTE] Release of DbUtils 1.2 RC3
Date Mon, 16 Mar 2009 15:02:54 GMT
sebb wrote:

> On 15/03/2009, Dan Fabulich <dan@fabulich.com> wrote:
>>  The problem gets even more complicated if we tried to write a generic
>> "IntegrationTestApp" to work against multiple vendors.  How would the
>> IntegrationTestApp know what column types are possible?  How would it manage
>> access to the DataSource in a vendor-agnostic way?  Would we have to add a
>> dozen (closed source?) DB drivers to our test classpath?
>
> I thought that DBUtils used JDBC, which is a common API?

We still have to call a vendor-specific constructor to cook up a 
DataSource.  (Well, I guess we could just skip the DataSource and use a 
Connection backed by a JDBC URL.)

And then there's the question of column types, though I suppose we could 
make those command-line arguments?  So I guess that leaves us with a test 
app that looks something like:

public class IntegrationTestApp {
   public static void main(String[] args) throws SQLException {
     if (args.length < 2) printUsageAndExit();
     String url = args[0];
     Connection conn = DriverManager.getConnection(url);
     QueryRunner runner = new QueryRunner();

     runner.update(conn, "DROP TABLE dbutilstest");

     StringBuffer sb = new StringBuffer("CREATE TABLE dbutilstest(");
     for (int i = 1; i < args.length; i++) {
       if (i != 1) sb.append(", ");
       sb.append("col").append(i).append(' ').append(args[i]);
     }
     sb.append(')');
     runner.update(conn, sb.toString());

     sb = new StringBuffer("INSERT INTO dbutilstest VALUES(");
     for (int i = 1; i < args.length; i++) {
       if (i != 1) sb.append(", ");
       sb.append('?');
     }
     sb.append(')');

     runner.update(conn, sb.toString(), new Object[args.length-1]);
   }
   private static void printUsageAndExit() {
     String className = IntegrationTestApp.class.getCanonicalName();
     System.err.println("usage: java " + className
         + " <jdbcUrl> columnType[...]");
     System.err.println("\nexample: java " + className
         + " jdbc:derby:/tmp/myDatabase;create=true varchar char bigint");
     System.exit(1);
   }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message