On 16/03/2009, Dan Fabulich <d...@fabulich.com> wrote:
> sebb wrote:
>
>
> > On 15/03/2009, Dan Fabulich <d...@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.)

The vendor-specific DataSource code could be provided as examples too.

>  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);
>
>   }
>  }

Yes, that's the sort of thing I meant.
Works with Derby (after changing varchar=>varchar(32) likewise for char).

This could be extended to be a more extensive test of the features of
DBUtils against real databases.

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

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

Reply via email to