jmcnally 01/12/09 18:59:54
Modified: src/java/org/apache/torque Torque.java
src/java/org/apache/torque/util BasePeer.java
src/templates/om MapBuilder.vm Peer.vm
Log:
these changes allow the column constants in Peer classes to be referenced before
Torque has been initialized. Torque still needs to be initialized before methods
are called on the Peer classes. This change allows serialized instances to be
unserialized prior to initializing Torque. This situation arises in normal
shutdown and restart of the catalina servlet engine.
The changes in MapBuilder are to remove the getTable and get<columnName> methods
.
Limit the MapBuilders use to building maps, not storing the same information
contained in the maps after the maps are created.
Revision Changes Path
1.41 +52 -21 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.40
retrieving revision 1.41
diff -u -r1.40 -r1.41
--- Torque.java 2001/11/15 00:16:17 1.40
+++ Torque.java 2001/12/10 02:59:54 1.41
@@ -60,6 +60,8 @@
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
+import java.util.List;
+import java.util.Vector;
import java.util.Properties;
import org.apache.commons.collections.ExtendedProperties;
import org.apache.log4j.Category;
@@ -73,6 +75,7 @@
import org.apache.torque.oid.IDBroker;
import org.apache.torque.pool.ConnectionPool;
import org.apache.torque.pool.DBConnection;
+import org.apache.torque.util.BasePeer;
/**
* The implementation of Torque.
@@ -81,7 +84,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.40 2001/11/15 00:16:17 dlr Exp $
+ * @version $Id: Torque.java,v 1.41 2001/12/10 02:59:54 jmcnally Exp $
*/
public class Torque
{
@@ -129,11 +132,39 @@
private static Monitor monitor;
/**
- * Initializes Torque.
+ * flag to set to true once this class has been initialized
*/
- public static void init()
+ private static boolean isInit = false;
+
+ /**
+ * Store mapbuilder classnames for peers that have been referenced prior
+ * to Torque being initialized. This can happen if torque om/peer objects
+ * are serialized then unserialized prior to Torque being reinitialized.
+ * This condition exists in a normal catalina restart.
+ */
+ private static List mapBuilders = new Vector();
+
+ /**
+ * Initialization of Torque with a properties file.
+ *
+ * @param configFile The path to the configuration file.
+ */
+ public static void init(String configFile)
+ throws Exception
+ {
+ ExtendedProperties c = new ExtendedProperties(configFile);
+ init(c);
+ }
+
+ /**
+ * Initialization of Torque with a properties file.
+ *
+ * @param configFile The path to the configuration file.
+ */
+ public static void init(ExtendedProperties c)
throws Exception
{
+ Torque.setConfiguration(c);
if (configuration == null)
{
throw new Exception("Torque cannot be initialized without " +
@@ -171,6 +202,16 @@
pools = new HashMap();
DBFactory.init(configuration);
+ isInit = true;
+ for ( Iterator i=mapBuilders.iterator(); i.hasNext(); )
+ {
+ //this will add any maps in this builder to the proper database map
+ BasePeer.getMapBuilder((String)i.next());
+ }
+ // any further mapBuilders will be called/built on demand
+ mapBuilders = null;
+
+
// Create monitor thread
monitor = new Monitor();
// Indicate that this is a system thread. JVM will quit only when there
@@ -181,17 +222,9 @@
monitor.start();
}
- /**
- * Initialization of Torque with a properties file.
- *
- * @param configFile The path to the configuration file.
- */
- public static void init(String configFile)
- throws Exception
+ public static boolean isInit()
{
- ExtendedProperties c = new ExtendedProperties(configFile);
- Torque.setConfiguration(c);
- Torque.init();
+ return isInit;
}
/**
@@ -391,14 +424,7 @@
if (dbMaps == null)
{
- try
- {
- Torque.init();
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ throw new TorqueException("Torque was not initialized properly.");
}
synchronized (dbMaps)
@@ -452,6 +478,11 @@
return map;
}
+
+ public static void registerMapBuilder(String className)
+ {
+ mapBuilders.add(className);
+ }
/**
* Returns the specified property of the given database, or the empty
1.19 +2 -1
jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java
Index: BasePeer.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/util/BasePeer.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- BasePeer.java 2001/11/05 15:04:42 1.18
+++ BasePeer.java 2001/12/10 02:59:54 1.19
@@ -110,7 +110,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Frank Y. Kim</a>
* @author <a href="mailto:[EMAIL PROTECTED]">John D. McNally</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Brett McLaughlin</a>
- * @version $Id: BasePeer.java,v 1.18 2001/11/05 15:04:42 jvanzyl Exp $
+ * @version $Id: BasePeer.java,v 1.19 2001/12/10 02:59:54 jmcnally Exp $
*/
public abstract class BasePeer implements java.io.Serializable
{
@@ -1886,6 +1886,7 @@
*
*/
public static MapBuilder getMapBuilder()
+ throws Exception
{
return getMapBuilder(DEFAULT_MAP_BUILDER.trim());
}
1.6 +9 -7 jakarta-turbine-torque/src/templates/om/MapBuilder.vm
Index: MapBuilder.vm
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/MapBuilder.vm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- MapBuilder.vm 2001/10/29 04:07:26 1.5
+++ MapBuilder.vm 2001/12/10 02:59:54 1.6
@@ -25,6 +25,7 @@
/**
* Item
+ * @deprecated use ${table.JavaName}Peer.TABLE_NAME constant
*/
public static String getTable( )
{
@@ -38,6 +39,7 @@
/**
* ${table.Name}.$cup
+ * @deprecated use ${table.JavaName}Peer.${table.Name}.$cup constant
*/
public static String get${tfc}_${cfc}()
{
@@ -45,6 +47,7 @@
}
#end
+
/**
* The database map.
*/
@@ -78,8 +81,8 @@
{
dbMap = Torque.getDatabaseMap("$table.Database.Name");
- dbMap.addTable(getTable());
- TableMap tMap = dbMap.getTable(getTable());
+ dbMap.addTable("$table.Name");
+ TableMap tMap = dbMap.getTable("$table.Name");
#if ($table.IdMethod == "native")
tMap.setPrimaryKeyMethod(TableMap.NATIVE);
@@ -108,22 +111,21 @@
#set ( $tfc=$table.JavaName )
#set ( $cfc=$col.JavaName )
#set ( $cup=$col.Name.toUpperCase() )
-
#if($col.isPrimaryKey())
#if($col.isForeignKey())
tMap.addForeignPrimaryKey (
- get${tfc}_${cfc}(), $col.JavaObject , "$col.RelatedTableName" ,
+ "${table.Name}.$cup", $col.JavaObject , "$col.RelatedTableName" ,
"$col.RelatedColumnName" );
#else
- tMap.addPrimaryKey ( get${tfc}_${cfc}(), $col.JavaObject );
+ tMap.addPrimaryKey ( "${table.Name}.$cup", $col.JavaObject );
#end
#else
#if($col.isForeignKey())
tMap.addForeignKey (
- get${tfc}_${cfc}(), $col.JavaObject , "$col.RelatedTableName" ,
+ "${table.Name}.$cup", $col.JavaObject , "$col.RelatedTableName" ,
"$col.RelatedColumnName" );
#else
- tMap.addColumn ( get${tfc}_${cfc}(), $col.JavaObject );
+ tMap.addColumn ( "${table.Name}.$cup", $col.JavaObject );
#end
#end
#end
1.12 +46 -19 jakarta-turbine-torque/src/templates/om/Peer.vm
Index: Peer.vm
===================================================================
RCS file: /home/cvs/jakarta-turbine-torque/src/templates/om/Peer.vm,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Peer.vm 2001/12/07 01:55:57 1.11
+++ Peer.vm 2001/12/10 02:59:54 1.12
@@ -34,19 +34,19 @@
{
#if (!$table.isAlias())
- /** the mapbuilder for this class */
- protected static final ${table.JavaName}MapBuilder mapBuilder =
-
(${table.JavaName}MapBuilder)getMapBuilder(${table.JavaName}MapBuilder.CLASS_NAME);
-
- /** the table name for this class */
- public static final String TABLE_NAME = mapBuilder.getTable();
-
+ /** the default database name for this class */
+ public static final String DATABASE_NAME = "$table.Database.Name";
+
+ /** the table name for this class */
+ public static final String TABLE_NAME = "$table.Name";
+
/**
* @returns the map builder for this peer
*/
public static MapBuilder getMapBuilder()
+ throws Exception
{
- return(mapBuilder);
+ return getMapBuilder(${table.JavaName}MapBuilder.CLASS_NAME);
}
#foreach ($col in $table.Columns)
@@ -54,9 +54,35 @@
#set ( $cfc=$col.JavaName )
#set ( $cup=$col.Name.toUpperCase() )
/** the column name for the $cup field */
- public static final String $cup = mapBuilder.get${tfc}_${cfc}();
+ public static final String $cup;
+#end
+
+ static
+ {
+#foreach ($col in $table.Columns)
+ #set ( $tfc=$table.JavaName )
+ #set ( $cfc=$col.JavaName )
+ #set ( $cup=$col.Name.toUpperCase() )
+ $cup = "${table.Name}.$cup";
#end
+ if (Torque.isInit())
+ {
+ try
+ {
+ getMapBuilder();
+ }
+ catch (Exception e)
+ {
+ category.error("Could not initialize Peer", e);
+ }
+ }
+ else
+ {
+ Torque.registerMapBuilder(${table.JavaName}MapBuilder.CLASS_NAME);
+ }
+ }
+
#end ## ends if (!$table.isAlias())
/** number of columns for this peer */
@@ -215,7 +241,7 @@
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
- criteria.setDbName(mapBuilder.getDatabaseMap().getName());
+ criteria.setDbName(DATABASE_NAME);
}
return BasePeer.doInsert( criteria );
}
@@ -382,7 +408,7 @@
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
- criteria.setDbName(mapBuilder.getDatabaseMap().getName());
+ criteria.setDbName(DATABASE_NAME);
}
return BasePeer.doSelect(criteria);
}
@@ -499,7 +525,7 @@
public static void doUpdate(Criteria criteria, DBConnection dbCon) throws
Exception
{
Criteria selectCriteria = new
- Criteria(mapBuilder.getDatabaseMap().getName(), 2);
+ Criteria(DATABASE_NAME, 2);
#foreach ($col in $table.Columns)
#set ( $cup=$col.Name.toUpperCase() )
#if($col.isBooleanInt())
@@ -549,7 +575,7 @@
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
- criteria.setDbName(mapBuilder.getDatabaseMap().getName());
+ criteria.setDbName(DATABASE_NAME);
}
BasePeer.doUpdate( selectCriteria, criteria );
}
@@ -626,7 +652,7 @@
// another value so == check is okay and faster
if ( criteria.getDbName() == Torque.getDefaultDB() )
{
- criteria.setDbName(mapBuilder.getDatabaseMap().getName());
+ criteria.setDbName(DATABASE_NAME);
}
BasePeer.doDelete ( criteria );
}
@@ -750,7 +776,7 @@
$table.JavaName retVal = null;
try
{
- db = Torque.getConnection( mapBuilder.getDatabaseMap().getName() );
+ db = Torque.getConnection( DATABASE_NAME );
retVal = ${retrieveMethod}( pk, db );
}
finally
@@ -819,7 +845,7 @@
$table.JavaName retVal = null;
try
{
- db = Torque.getConnection( mapBuilder.getDatabaseMap().getName() );
+ db = Torque.getConnection( DATABASE_NAME );
retVal = retrieveByPK(
#set ( $comma = false )
#foreach ($col in $table.PrimaryKeys)
@@ -938,7 +964,7 @@
// another value so == check is okay and faster
if ( c.getDbName() == Torque.getDefaultDB() )
{
- c.setDbName(mapBuilder.getDatabaseMap().getName());
+ c.setDbName(DATABASE_NAME);
}
${table.JavaName}Peer.addSelectColumns(c);
@@ -1098,7 +1124,7 @@
// so == check is okay and faster
if ( c.getDbName() == Torque.getDefaultDB() )
{
- c.setDbName(mapBuilder.getDatabaseMap().getName());
+ c.setDbName(DATABASE_NAME);
}
addSelectColumns(c);
@@ -1253,8 +1279,9 @@
* need.
*/
protected static TableMap getTableMap()
+ throws Exception
{
- return mapBuilder.getDatabaseMap().getTable(TABLE_NAME);
+ return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
}
#end ## ends if (!$table.isAlias())
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>