db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Dudziak <to...@first.gmd.de>
Subject New utility class for db creation
Date Wed, 21 Jan 2004 14:00:16 GMT
Hi folks,

I just added a new class that allows to create (e.g. "create
database") and initialize (e.g. "create table") a database from java using
torque and the torque schemas. Usage is something like this:

String               srcDir    = "resources/ojb";
String               schemas   = "*-schema.xml";
PersistenceBroker    broker    = 
ConnectionRepository connRep   = 
TorqueDBHandling     dbHandler = new 
TorqueDBHandling(connRep.getDescriptor(broker.getPBKey()), srcDir, 


I figured such a class might be useful to further automate the unit tests
and eventually make them independent of each other (e.g. by creating
and populating the database prior to each test).
I didn't exactly know where to put the class but I thought the
broker.platforms subpackage is a good place as similar implementations
might be necessary for other platforms supported by OJB (e.g. MsAccess and
Informix are not supported by Torque so they would need specific
creation/initialization stuff) which then could be hidden by a
Platform.getDbHandler and a DbHandler interface where the actual
implementation is chosen by the PlatformImpls.

I'll probably add stuff to populate the db from strings or files (xml,
csv), as well.

One problem that remains is that for most jdbc drivers the jdbc url to
create a database is different from the url to manipulate an existing
db. E.g. when using the ant sql task with mysql you would do this to
create a db:

<?xml version="1.0" encoding="UTF-8"?>
<project default="main" basedir="." name="build-db">
    <path id="project.class.path">
        <fileset dir="lib" casesensitive="no">
          <include name="**/*.jar"/>
          <include name="**/*.zip"/>

    <target name="main">
        <sql classpathref="project.class.path"
        drop database if exists testdb;
        create database testdb;

(note the missing database name in the url). As the database url is driver
specific (or at least platform specific), there is some testing necessary
to determine these urls for the torque-supported platforms.


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

View raw message