db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Greg Monroe" <Greg.Mon...@DukeCE.com>
Subject RE: multiple databases and addDescendingOrderByColumn
Date Fri, 31 Mar 2006 15:53:32 GMT
Depends on what you mean by "work for".  If you mean
something like: Can I have multiple applications (e.g.
separate webapps) that use the same code to access different
SQL Server Databases.  The answer is yes.

The thing to understand here is that Torque's Database
name is simply a key used to logically tie various Torque
related items together. It has nothing to do with the SQL
server Database name except to tie the JDBC info (which has
the SQL DB name in it's URL) to the classes.

In the case of multiple applications, you can just call
Torque.init() in each application with different properties
that point to whatever JDBC data source you want.  These can
be defined in a static Torque.properties or be dynamically
generated/modified by your application.

If you mean, can I have a single application that accesses
multiple SQL DB's using a single set of Torque classes, the
answer is "probably, but you'll have to test it..". 

The way to do this would be to handle the connections in
your own code.  So instead of calling the no argument
methods in the Record and Peer objects, (e.g.
tableRecord.save(), TablePeer.doSelect()), you need to use
the methods that have the Connection argument (e.g. 
tableRecord.save(conn), TablePeer.doSelect(conn) ). The SQL
connection is where the link between Torque and the SQL DB
defined to JDBC are tied together.

I say test because this is all theoretical and not a case that
has had a lot of usage to shake out any bugs.

FWIW, one way that you might use Torque to help you manage your
connections is to define the different SQL DB's in the Torque
properties JDBC settings with different Torque Database names.
You should then be able to use the Torque.getConnection(dbName)
method to get pooled connections to pass to the various methods.

Remember that you'll still have to close these connections in
your code.

Good luck.

> -----Original Message-----
> From: John Dunne [mailto:imirish@alldunne.com] 
> Sent: Friday, March 31, 2006 3:41 AM
> To: Apache Torque Users List
> Subject: multiple databases and addDescendingOrderByColumn
> Is it possible to create a set of torque class files (from a 
> schema.xml 
> file) that will work for multiple copies of schematically (?) 
> identical 
> databases? The problem I have is a nullpointerexception 
> whenever I call 
> addDescendingOrderByColumn on the database other than the one 
> specified 
> in the name property of the database xml element in schema.xml.
> For example
>       Criteria crit = new Criteria(databasename);
>       crit.addDescendingOrderByColumn(TablenamePeer.STARTTIME);
>       List l = TablenamePeer.doSelect(crit);
> will generate a null pointer exception if 
> databasename!=default db name 
> i.e. the database name specified in the schema.xml. I've 
> tried replacing 
> the name property with * and comma deliminating all databases 
> names, no 
> success.... Any assistance would be gratefully welcome.
> John.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org

Duke CE Privacy Statement
Please be advised that this e-mail and any files transmitted with it are confidential communication
or may otherwise be privileged or confidential and are intended solely for the individual
or entity to whom they are addressed.  If you are not the intended recipient you may not rely
on the contents of this email or any attachments, and we ask that you  please not read, copy
or retransmit this communication, but reply to the sender and destroy the email, its contents,
and all copies thereof immediately.  Any unauthorized dissemination, distribution or copying
of this communication is strictly prohibited.

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

View raw message