Re: using a second database
On Apr 17, 2006, at 12:36 PM, Thomas Vandahl wrote: Yes, you can still do that. The name in the schema and the name in the Torque configuration have nothing to do with the real name of the database. This is usually specified in the JDBC-URL only. The other two names are just used to handle the matching of generated objects and configurations appropriately. I for example do this as well: The name of my schema is turbine and the name of my developer database is testdb. ok, so now I am confused! I played around with different settings and I thought I had it down: The db name in the schema.xml file is inserted into the create-db.sql script and into all generated BasePeer objects and the configuration name in the Torque.properties file needs to be the same as well. Hence, if we want folks to work in their own sandbox, we would have to have database name=sandbox1.../database torque.database.default=sandbox1 torque.dsfactory.sandbox1.factory=org.apache.torque.dsfactory.PerUserPoo lDataSourceFactory torque.dsfactory.sandbox1. ... I can see how you can work around that by enforcing manual creation of the db though. Maybe the lesser of the two not-so-evils? cheers, h. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using a second database
As I said below, you and Thomas are correct except for the creation of the database. If you want torque to create it, the name in the schema.xml file needs to be the same as the one specified in your connection URL. cheers, h. On Apr 18, 2006, at 11:54 AM, Guy Galil wrote: All you need to do is change the url string in your torque.properties file - each developer should have the url point to a different database: as long as in your schema your database name is db for developer 1 torque.dsfactory.db.connection.url =jdbc:mysql://someip:someport/sandbox1 for developer 2 torque.dsfactory.db.connection.url =jdbc:mysql://someip:someport/sandbox2 The database name in the schema and the objects is just a logical pointer to the settings in the properties file. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using a second database
Helge Weissig wrote: I may have not been very clear on the setup I have. Basically, I generate all Torque objects for the mysql database only and use the second one with straight SQL and BasePeer.executeQuery(sql, dbName) or BasePeer.executeStatement(sql, connection). I am not trying to use Table1Peer for both databases. But when I do String initSql = select cdcaux.ctenvinit('user.tablespace') from dual; BasePeer.executeQuery(initSql, oracle); the query is done in my mysql database, not the oracle one. As Greg said, the name of your database in the Torque configuration should match the one you defined in your schema-xml. I guess it shouldbe sufficient to generate at least one table object in a database called oracle and see what happens. BTW, why don't you use the Peers in your Oracle database? Bye, Thomas. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: using a second database
I don't believe you can get this sort of logic to work. Here's why: The database name in Torque actually refers to Torque's object space database and not any physical SQL Server database. The Torque db name is defined in your schema xml (name attribute on Database tag). This name is used as a key to tie a lot of information together. Behind the scenes, there is a fair amount of information embedded in the generated classes that is retrieved by the database name. For example, the object database space meta data that is contained in the Map classes is grouped by this database name. This means that even though it looks like the properties are just a name that tie in JDBC info together and you should be able to swap this in and out, they really aren't. To use all the capablities of Torque, the database name part of the properties should map to the schema name. That said, here's what I do to deal with this situation. I treat configuration information as being totally separate from application code. It's for configuration after all and so any code updates should not change it. So, while I may have a sample config file checked into the repository, I never have a real configuration property checked in. In my code, I initialize Torque by searching the class path for the configuration file. E.g.: URL url = this.getClass().getClassLoader().getResource( getDbParameterFileName()); // Note: Don't use new URI(url.toString()) // - Tomcat will not resolve this!. String path = url.getPath(); if ( path != null ! path.startsWith(/)) { path = /+path; } URI uri = new URI(url.getProtocol(),,path,null); return new File(uri); This lets me have different configuration files for various situations, like for junit testing under Eclipse, a development server using MySQL, and multiple production servers using different DB's but all using the same code. -Original Message- From: Helge Weissig [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 12, 2006 11:45 AM To: torque-user@db.apache.org Subject: using a second database Hi, I am trying to use a second database but am having trouble accessing it (or configuring it, not sure). Below is what I have so far, most of it taken straight from the 3.2 distribution. When I ask Torque to give me a connection to oracle, I get the mysql db connection. Also and unrelated, I use the generator to create the mysql DB and it seems that I need to use the same name in my DB schema as I do in the Torque.properties file for runtime. Is that correct? Is there a way around it? Having a group of developers develop on their own sandbox dbs and then switching the code to production would be a little easier if one would only have to change that DB name in one place and not in two and on several lines... thanks so much for any insight!! h. # defaults torque.applicationRoot = ${applicationRoot} # do I need this one??? torque.defaults.pool.maxWait = 1 torque.defaults.pool.maxIdle = 8 torque.defaults.pool.maxActive = 10 torque.defaults.pool.timeBetweenEvictionRunsMillis= 30 torque.defaults.pool.minEvictableIdleTimeMillis = 360 torque.defaults.connection.driver = com.mysql.jdbc.Driver torque.defaults.connection.url = jdbc:mysql://localhost:3306/test torque.defaults.connection.user = user1 torque.defaults.connection.password = password1 # first DB, works like a charm torque.database.default=test torque.database.test.adapter=mysql torque.dsfactory.test.factory=org.apache.torque.dsfactory.Shar edPoolData SourceFactory torque.dsfactory.test.pool.maxIdle=8 torque.dsfactory.test.pool.maxActive=10 torque.dsfactory.test.pool.testOnBorrow=true torque.dsfactory.test.pool.validationQuery=SELECT 1 torque.dsfactory.test.connection.driver = com.mysql.jdbc.Driver torque.dsfactory.test.connection.url = jdbc:mysql://localhost:3306/test torque.dsfactory.test.connection.user = user1 torque.dsfactory.test.connection.password = password1 # second DB torque.database.oracle.adapter=oracle torque.dsfactory.oracle.factory=org.apache.torque.dsfactory.Sh aredPoolDa taSourceFactory torque.dsfactory.oracle.pool.maxIdle=8 torque.dsfactory.oracle.pool.maxActive=10 torque.dsfactory.oracle.pool.testOnBorrow=true torque.dsfactory.oracle.pool.validationQuery=SELECT 1 torque.database.oracle.driver=oracle.jdbc.driver.OracleDriver torque.database.oracle.url=jdbc:oracle:thin:@sunfire:1521:actx torque.database.oracle.username=user2 torque.database.oracle.password=password2 torque.database.oracle.maxConnections=4 torque.database.oracle.expiryTime=360 torque.idbroker.clever.quantity=true torque.manager.useCache = true - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] Duke CE Privacy Statement Please be
Re: using a second database
On Apr 13, 2006, at 9:33 AM, Greg Monroe wrote: I don't believe you can get this sort of logic to work. Here's why: The database name in Torque actually refers to Torque's object space database and not any physical SQL Server database. The Torque db name is defined in your schema xml (name attribute on Database tag). This name is used as a key to tie a lot of information together. Thanks for the reply, Greg! Much appreciated! I may have not been very clear on the setup I have. Basically, I generate all Torque objects for the mysql database only and use the second one with straight SQL and BasePeer.executeQuery(sql, dbName) or BasePeer.executeStatement(sql, connection). I am not trying to use Table1Peer for both databases. But when I do String initSql = select cdcaux.ctenvinit('user.tablespace') from dual; BasePeer.executeQuery(initSql, oracle); the query is done in my mysql database, not the oracle one. [snip] That said, here's what I do to deal with this situation. I treat configuration information as being totally separate from application code. It's for configuration after all and so any code updates should not change it. So, while I may have a sample config file checked into the repository, I never have a real configuration property checked in. In my code, I initialize Torque by searching the class path for the configuration file. E.g.: URL url = this.getClass().getClassLoader().getResource( getDbParameterFileName()); // Note: Don't use new URI(url.toString()) // - Tomcat will not resolve this!. String path = url.getPath(); if ( path != null ! path.startsWith(/)) { path = /+path; } URI uri = new URI(url.getProtocol(),,path,null); return new File(uri); This lets me have different configuration files for various situations, like for junit testing under Eclipse, a development server using MySQL, and multiple production servers using different DB's but all using the same code. This is very useful for having multiple configurations. Thanks!! cheers, h. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: using a second database
On Apr 12, 2006, at 8:44 AM, Helge Weissig wrote: Hi, I am trying to use a second database but am having trouble accessing it (or configuring it, not sure). Below is what I have so far, most of it taken straight from the 3.2 distribution. When I ask Torque to give me a connection to oracle, I get the mysql db connection. [snip] # second DB torque.database.oracle.adapter=oracle torque.dsfactory.oracle.factory=org.apache.torque.dsfactory.SharedPool DataSourceFactory torque.dsfactory.oracle.pool.maxIdle=8 torque.dsfactory.oracle.pool.maxActive=10 torque.dsfactory.oracle.pool.testOnBorrow=true torque.dsfactory.oracle.pool.validationQuery=SELECT 1 torque.database.oracle.driver=oracle.jdbc.driver.OracleDriver torque.database.oracle.url=jdbc:oracle:thin:@sunfire:1521:actx torque.database.oracle.username=user2 torque.database.oracle.password=password2 torque.database.oracle.maxConnections=4 torque.database.oracle.expiryTime=360 OUCH!!! bad configuration!! This should read torque.dsfactory.oracle.connection.driver=oracle.jdbc.driver.OracleDrive r torque.dsfactory.oracle.connection.url=jdbc:oracle:thin:@sunfire: 1521:actx torque.dsfactory.oracle.connection.username=user2 torque.dsfactory.oracle.connection.password=password2 found out after removing the torque generator jars out of my runtime path an getting the torque logging to work. I'll add this as a FAQ. cheers, h. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]