Hi,

This patch adds an "adapter" property to Torque.properties.  The patch solves 
the problem that only about 15 or so JDBC drivers are currently allowed in 
Torque; no additional drivers can be used without recoding DBFactory.java.  
This was apparently implemented because each driver is mapped to a specific 
adapter.

With this patch any driver can be used as long as the adapter is explicitly 
stated.  For example:

torque.database.default=mydb

torque.database.mydb.driver = com.newatlanta.jturbo.Driver
torque.database.mydb.url = jdbc:JTurbo://localhost/databasename
torque.database.mydb.username = 
torque.database.mydb.password = 

# NEW PROPERTY
torque.database.mydb.adapter=MSSQL

(note: I'm entering the JTurbo syntax from memory, may be slightly off)

One caveat is that the adapter is internally mapped to a driver not the 
database.  But I thought specifying the adapter relative to a database was 
clearer to the user.  A consequence is that specifying the adapter for one 
database sets it for all databases in the app that use the same driver.  
(seemed okay to me).

Additional (but not implemented) functionality would be to have a "default" 
adapter that is used when no adapter is hard coded and no adapter is 
specified.  

Reference: 
http://www.mail-archive.com/turbine-torque-user%
40jakarta.apache.org/msg00105.html

Best, WILL

P.S.  Tested this with "ant test"-- no problemo.

------------------------------------
Will Glass-Husain  <[EMAIL PROTECTED]>
Forio Business Simulations
office: (415) 440-7500
mobile: (415) 235-4293
cvs diff DBFactory.java (in directory 
D:\Will\Forio\repo\jakarta-turbine-torque\src\java\org\apache\torque\adapter)
Index: DBFactory.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/adapter/DBFactory.java,v

retrieving revision 1.26
diff -r1.26 DBFactory.java
66a67
>  * @author <a href="mailto:[EMAIL PROTECTED]";>Will Glass-Husain</a>
107a109,110
> 
>             // Add the the hard-coded drivers and adapters
109a113,116
>           // Add any additional driver mappings specified in the config file
>         initializeAdaptersFromConfigFile(configuration);
> 
> 
171a179
> 
172a181,222
> 
>     /**
>      * Set a adapter for a given database, allowing users
>      * to choose a driver not associated with a adaptor in the code. .  Property 
>should be
>      * listed as:
>      *
>      * <code>
>      * <p>torque.database.<databasename>.adapter=<adapter>
>      * </code>
>      *
>      * <p>This property is intended to be used only for drivers not already
>      * mapped to an adapter.  Also, note that changing an adaptor for a database
>      * with a particular driver changes it for all databases with the same driver.
>      */
>      private static void initializeAdaptersFromConfigFile(Configuration 
>configuration)
>      {
> 
>         Iterator i = configuration.getKeys();
> 
>         while (i.hasNext())
>         {
>             String key = (String) i.next();
>             if (key.startsWith("database.") && key.endsWith(".adapter"))
>             {
>                     // get database name assuming format "database.NAME.adapter"
>                     String dbname = key.substring(9,key.indexOf(".adapter"));
> 
>                     // check for database driver property
>                     String driver = null;
>                     if (configuration.containsKey("database." + dbname + ".driver"))
>                         driver = configuration.getString("database." + dbname + 
>".driver");
> 
>                     String adapter = configuration.getString(key);
> 
>                if (driver != null) {
>                         driverToAdapterMap.put(driver,adapter);
>                         category.debug("Mapping driver: " + driver + " to adapter: " 
>+ adapter);
>                     }
>             } //if
>         } // while
> 
>      }
--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to