You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by Erik Wright <tw...@sympatico.ca> on 2002/12/03 20:23:09 UTC

Criteria surprises

Hello,

I have a question regarding the implementation of Criteria.

I'm developing an app that uses several databases (three at
the moment) - currently they are all hosted on one instance
of MySQL but in production this may not be the case.

The problem has to do with the multiple DBs. Criteria built
using the default constructor automatically select the
default database. As you can imagine, two times out of three
this is wrong in my scenario.

Is there a particular reason why this should be necessary?
My first instinct is that by default the Criteria shouldn't
care too much about what DB is being used until it comes
time to build the SQL query, and that this should then be
supplied by the Base Peer. At first thought, this change
should not affect the default behavior adversely in the
normal situation of calling the default Criteria constructor
(since BasePeer should always be able to determine the
proper DB). In unusual situations the developer is probably
already specifying a DB in the Criteria constructor.

I'm willing to look at making such a change myself, but I'd
like to get some feedback first... am I totally missing
something here?

- Erik


Re: Criteria surprises

Posted by "Henning P. Schmiedehausen" <hp...@intermeta.de>.
"Erik Wright" <tw...@sympatico.ca> writes:

>Hello,

>I have a question regarding the implementation of Criteria.

>I'm developing an app that uses several databases (three at
>the moment) - currently they are all hosted on one instance
>of MySQL but in production this may not be the case.

>The problem has to do with the multiple DBs. Criteria built
>using the default constructor automatically select the
>default database. As you can imagine, two times out of three
>this is wrong in my scenario.

>Is there a particular reason why this should be necessary?
>My first instinct is that by default the Criteria shouldn't
>care too much about what DB is being used until it comes
>time to build the SQL query, and that this should then be
>supplied by the Base Peer. At first thought, this change

You're right but with the current state and relation of the
BasePeer, it simply doesn't work that way. Sorry.

Please use the Criteria(String s) C'tor and supply the name of
the database. 

Alternatively, if you configured the symbolic names of your
db correct in the xml file and the .properties, the Criteria
automagically _should_ select the right DB.

I BTW use the same thing (three databases, one server, MySQL)
and have this:


torque.database.default=db1

torque.database.db1.adapter = mysql
torque.dsfactory.db1.factory= org.apache.torque.dsfactory.TorqueDataSourceFactory
torque.dsfactory.db1.connection.driver   = org.gjt.mm.mysql.Driver
torque.dsfactory.db1.connection.url      = jdbc:mysql://localhost:3306/FIRST_DATABASE
torque.dsfactory.db1.connection.user     = root
torque.dsfactory.db1.connection.password = 
torque.dsfactory.db1.pool.defaultMaxConnections=80
torque.dsfactory.db1.pool.maxExpiryTime=3600000
torque.dsfactory.db1.pool.connectionWaitTimeout=10000

torque.database.db2.adapter = mysql
torque.dsfactory.db2.factory= org.apache.torque.dsfactory.TorqueDataSourceFactory
torque.dsfactory.db2.connection.driver   = org.gjt.mm.mysql.Driver
torque.dsfactory.db2.connection.url      = jdbc:mysql://localhost:3306/SECOND_DATABASE
torque.dsfactory.db2.connection.user     = root
torque.dsfactory.db2.connection.password = 
torque.dsfactory.db2.pool.defaultMaxConnections=80
torque.dsfactory.db2.pool.maxExpiryTime=3600000
torque.dsfactory.db2.pool.connectionWaitTimeout=10000

torque.database.db3.adapter = mysql
torque.dsfactory.db3.factory= org.apache.torque.dsfactory.TorqueDataSourceFactory
torque.dsfactory.db3.connection.driver   = org.gjt.mm.mysql.Driver
torque.dsfactory.db3.connection.url      = jdbc:mysql://localhost:3306/THIRD_DATABASE
torque.dsfactory.db3.connection.user     = root
torque.dsfactory.db3.connection.password = 
torque.dsfactory.db3.pool.defaultMaxConnections=80
torque.dsfactory.db3.pool.maxExpiryTime=3600000
torque.dsfactory.db3.pool.connectionWaitTimeout=10000

in my database definition properties. In the XML file I have


<database name="db1">
[...tables from db1...]
</database>

<database name="db2">
[...tables from db2...]
</database>

<database name="db3">
[...tables from db3...]
</database>


and the resulting peers and stuff simply "work". You must use the Peer
supplied constants for the column names, however.

	Regards
		Henning



-- 
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen       -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH     hps@intermeta.de

Am Schwabachgrund 22  Fon.: 09131 / 50654-0   info@intermeta.de
D-91054 Buckenhof     Fax.: 09131 / 50654-20