dlr 01/08/13 15:32:43
Modified: src/java/org/apache/torque Torque.java
Log:
Used IDGeneratorFactory to create list of IdGenerator types. Now fully supporting
XML schemas with column attributes of idMethod="native".
Revision Changes Path
1.5 +45 -29 jakarta-turbine-torque/src/java/org/apache/torque/Torque.java
Index: Torque.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -u -r1.4 -r1.5
--- Torque.java 2001/08/10 12:23:01 1.4
+++ Torque.java 2001/08/13 22:32:43 1.5
@@ -57,12 +57,12 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+
import org.apache.torque.adapter.DB;
import org.apache.torque.adapter.DBFactory;
import org.apache.torque.map.DatabaseMap;
import org.apache.torque.map.TableMap;
-import org.apache.torque.oid.AutoIncrementIdGenerator;
-import org.apache.torque.oid.SequenceIdGenerator;
+import org.apache.torque.oid.IDGeneratorFactory;
import org.apache.torque.oid.IDBroker;
import org.apache.torque.pool.ConnectionPool;
import org.apache.torque.pool.DBConnection;
@@ -78,7 +78,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Magn�s ��r Torfason</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Rafal Krzewski</a>
- * @version $Id: Torque.java,v 1.4 2001/08/10 12:23:01 knielsen Exp $
+ * @version $Id: Torque.java,v 1.5 2001/08/13 22:32:43 dlr Exp $
*/
public class Torque
{
@@ -217,46 +217,62 @@
public static DatabaseMap getDatabaseMap(String name)
throws TorqueException
{
- if ( name == null )
+ if (name == null)
{
throw new TorqueException ("DatabaseMap name was null!");
}
// Quick (non-sync) check for the map we want.
- DatabaseMap map = (DatabaseMap)dbMaps.get(name);
- if ( map == null )
+ DatabaseMap map = (DatabaseMap) dbMaps.get(name);
+ if (map == null)
{
// Map not there...
- synchronized( dbMaps )
+ synchronized (dbMaps)
{
// ... sync and look again to avoid race condition.
- map = (DatabaseMap)dbMaps.get(name);
- if ( map == null )
+ map = (DatabaseMap) dbMaps.get(name);
+ if (map == null)
{
// Still not there. Create and add.
- map = new DatabaseMap(name);
+ map = initDatabaseMap(name);
+ }
+ }
+ }
+ return map;
+ }
+
+ /**
+ * Creates and initializes the mape for the named database.
+ * Assumes that <code>dbMaps</code> member is sync'd.
+ *
+ * @param name The name of the database to map.
+ * @return The desired map.
+ */
+ private static final DatabaseMap initDatabaseMap(String name)
+ throws TorqueException
+ {
+ DatabaseMap map = new DatabaseMap(name);
- // Add info about IDBroker's table.
- setupIdTable(map);
- // setup other id generators
- try
- {
- DB db = DBFactory.create(
- getDatabaseProperty(name, "driver") );
- map.addIdGenerator(TableMap.AUTOINCREMENT,
- new AutoIncrementIdGenerator(db) );
- map.addIdGenerator(TableMap.SEQUENCE,
- new SequenceIdGenerator(db) );
- }
- catch (java.lang.InstantiationException e)
- {
- throw new TorqueException(e);
- }
+ // Add info about IDBroker's table.
+ setupIdTable(map);
- dbMaps.put(name, map);
- }
+ // Setup other ID generators for this map.
+ try
+ {
+ DB db = DBFactory.create(getDatabaseProperty(name, "driver"));
+ for (int i = 0; i < IDGeneratorFactory.ID_GENERATOR_METHODS.length;
+ i++)
+ {
+ map.addIdGenerator(IDGeneratorFactory.ID_GENERATOR_METHODS[i],
+ IDGeneratorFactory.create(db));
}
}
+ catch (java.lang.InstantiationException e)
+ {
+ throw new TorqueException(e);
+ }
+ dbMaps.put(name, map);
+
return map;
}
@@ -286,7 +302,7 @@
*
* @param map the DataBaseMap to setup.
*/
- private static void setupIdTable(DatabaseMap map)
+ private static final void setupIdTable(DatabaseMap map)
{
map.setIdTable("ID_TABLE");
TableMap tMap = map.getIdTable();
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]