Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 17029 invoked from network); 21 Jan 2004 14:16:47 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 21 Jan 2004 14:16:47 -0000 Received: (qmail 27609 invoked by uid 500); 21 Jan 2004 14:16:43 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 27380 invoked by uid 500); 21 Jan 2004 14:16:42 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 27367 invoked from network); 21 Jan 2004 14:16:42 -0000 Received: from unknown (HELO mail.fridayfives.net) (209.137.167.162) by daedalus.apache.org with SMTP; 21 Jan 2004 14:16:42 -0000 Received: from kamajii.forthill.int (localhost [127.0.0.1]) by localhost (Postfix) with SMTP id 5DA4D1F426 for ; Wed, 21 Jan 2004 09:16:43 -0500 (EST) Received: from [192.168.1.30] (kite.forthill.int [192.168.1.30]) by mail.fridayfives.net (Postfix) with ESMTP id 068301F425 for ; Wed, 21 Jan 2004 09:16:43 -0500 (EST) Mime-Version: 1.0 (Apple Message framework v609) In-Reply-To: References: Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Brian McCallister Subject: Re: New utility class for db creation Date: Wed, 21 Jan 2004 09:19:52 -0500 To: "OJB Developers List" X-Mailer: Apple Mail (2.609) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N This is great, I have been executing the torque generated SQL directly against in-memory hsqldb for unit tests. Will be very happy to go from the torque schema instead! -Brian On Jan 21, 2004, at 9:00 AM, Thomas Dudziak wrote: > 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 = > PersistenceBrokerFactory.defaultPersistenceBroker(); > ConnectionRepository connRep = > MetadataManager.getInstance().connectionRepository(); > TorqueDBHandling dbHandler = new > TorqueDBHandling(connRep.getDescriptor(broker.getPBKey()), srcDir, > schemas); > > dbHandler.createDB(); > dbHandler.createTables(); > > 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: > > > > > > > > > > > > driver="com.mysql.jdbc.Driver" > url="jdbc:mysql://localhost/" > userid="root" > password=""> > 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. > > Tom > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org > For additional commands, e-mail: ojb-dev-help@db.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org