tfischer2005/05/05 03:44:42
Modified:src/generator/src/templates/om Peer.vm
Log:
Gathered the code which deals with Booleans in criteria in an extra method.
This is no functional change, just a refactoring in order to have a central
place where the boolean problem is dealt with.
Revision ChangesPath
1.14 +49 -198 db-torque/src/generator/src/templates/om/Peer.vm
Index: Peer.vm
===
RCS file: /home/cvs/db-torque/src/generator/src/templates/om/Peer.vm,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- Peer.vm 31 Jan 2005 19:43:57 - 1.13
+++ Peer.vm 5 May 2005 10:44:42 - 1.14
@@ -246,8 +246,47 @@
public static ObjectKey doInsert(Criteria criteria, Connection con)
throws TorqueException
{
+correctBooleans(criteria);
+
+setDbName(criteria);
+
+if (con == null)
+{
+return BasePeer.doInsert(criteria);
+}
+else
+{
+return BasePeer.doInsert(criteria, con);
+}
+}
+
+/**
+ * Add all the columns needed to create a new object.
+ *
+ * @param criteria object containing the columns to add.
+ * @throws TorqueException Any exceptions caught during processing will
be
+ * rethrown wrapped into a TorqueException.
+ */
+public static void addSelectColumns(Criteria criteria)
+throws TorqueException
+{
#foreach ($col in $table.Columns)
#set ( $cup=$col.Name.toUpperCase() )
+criteria.addSelectColumn($cup);
+ #end
+}
+
+/**
+ * changes the boolean values in the criteria to the appropriate type,
+ * whenever a booleanchar or booleanint column is involved.
+ * This enables the user to create criteria using Boolean values
+ * for booleanchar or booleanint columns
+ * @param criteria the criteria in which the boolean values should be
corrected
+ */
+public static void correctBooleans(Criteria criteria)
+{
+#foreach ($col in $table.Columns)
+#set ( $cup=$col.Name.toUpperCase() )
#if($col.isBooleanInt())
// check for conversion from boolean to int
if (criteria.containsKey($cup))
@@ -280,33 +319,6 @@
}
#end
#end
-
-setDbName(criteria);
-
-if (con == null)
-{
-return BasePeer.doInsert(criteria);
-}
-else
-{
-return BasePeer.doInsert(criteria, con);
-}
-}
-
-/**
- * Add all the columns needed to create a new object.
- *
- * @param criteria object containing the columns to add.
- * @throws TorqueException Any exceptions caught during processing will
be
- * rethrown wrapped into a TorqueException.
- */
-public static void addSelectColumns(Criteria criteria)
-throws TorqueException
-{
- #foreach ($col in $table.Columns)
-#set ( $cup=$col.Name.toUpperCase() )
-criteria.addSelectColumn($cup);
- #end
}
/**
@@ -433,41 +445,7 @@
{
addSelectColumns(criteria);
}
-
- #foreach ($col in $table.Columns)
-#set ( $cup=$col.Name.toUpperCase() )
-#if($col.isBooleanInt())
-// check for conversion from boolean to int
-if (criteria.containsKey($cup))
-{
-Object possibleBoolean = criteria.get($cup);
-if (possibleBoolean instanceof Boolean)
-{
-criteria.add($cup, ((Boolean)
possibleBoolean).booleanValue() ? 1 : 0);
-}
- }
-#elseif ($col.isBooleanChar())
-// check for conversion from boolean to Y/N
-if (criteria.containsKey($cup))
-{
-Object possibleBoolean = criteria.get($cup);
-if (possibleBoolean instanceof Boolean)
-{
-criteria.add($cup, ((Boolean)
possibleBoolean).booleanValue() ? Y : N);
-}
- }
-#elseif ($col.isBit())
-// check for conversion from boolean to bit (1/0)
-if (criteria.containsKey($cup))
-{
-Object possibleBoolean = criteria.get($cup);
-if (possibleBoolean instanceof Boolean)
-{
-criteria.add($cup, ((Boolean)
possibleBoolean).booleanValue() ? 1 : 0);
-}
- }
-#end
- #end
+correctBooleans(criteria);
setDbName(criteria);
@@ -613,39 +591,11 @@
throws TorqueException
{
Criteria selectCriteria = new Criteria(DATABASE_NAME, 2);
+ correctBooleans(criteria);
+
#foreach ($col in $table.Columns)