You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by se...@apache.org on 2004/08/26 07:16:03 UTC
cvs commit: db-torque/src/generator/src/java/org/apache/torque/engine/database/model TypeMap.java
seade 2004/08/25 22:16:03
Modified: src/generator/src/templates/om Tag: TORQUE_3_1_BRANCH
ObjectWithManager.vm Peer.vm Object.vm
src/generator/src/java/org/apache/torque/engine/database/model
Tag: TORQUE_3_1_BRANCH TypeMap.java
Log:
Hennings Findbugs patch.
This is mainly working around things like new String() (replacing it
with ""), new Boolean(true) (replacing it with Boolean.TRUE).
Also cleanup of constructs like this:
if (foo) {
#if ($templateFoo)
do something
#end
}
which results in
if (foo) {
}
when $templateFoo is false.
Revision Changes Path
No revision
No revision
1.5.2.2 +3 -3 db-torque/src/generator/src/templates/om/ObjectWithManager.vm
Index: ObjectWithManager.vm
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/templates/om/ObjectWithManager.vm,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- ObjectWithManager.vm 22 Jan 2004 01:06:50 -0000 1.5.2.1
+++ ObjectWithManager.vm 26 Aug 2004 05:16:02 -0000 1.5.2.2
@@ -873,7 +873,7 @@
#elseif ($cjtype == "double")
return new Double(get${cfc}());
#elseif ($cjtype == "boolean")
- return new Boolean(get${cfc}());
+ return Boolean.valueOf(get${cfc}());
#elseif ($cjtype == "short")
return new Short(get${cfc}());
#elseif ($cjtype == "byte")
@@ -913,7 +913,7 @@
#elseif ($cjtype == "double")
return new Double(get${cfc}());
#elseif ($cjtype == "boolean")
- return new Boolean(get${cfc}());
+ return Boolean.valueOf(get${cfc}());
#elseif ($cjtype == "short")
return new Short(get${cfc}());
#elseif ($cjtype == "byte")
@@ -952,7 +952,7 @@
#elseif ($cjtype == "double")
return new Double(get${cfc}());
#elseif ($cjtype == "boolean")
- return new Boolean(get${cfc}());
+ return Boolean.valueOf(get${cfc}());
#elseif ($cjtype == "short")
return new Short(get${cfc}());
#elseif ($cjtype == "byte")
1.5.2.5 +65 -212 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.5.2.4
retrieving revision 1.5.2.5
diff -u -r1.5.2.4 -r1.5.2.5
--- Peer.vm 23 Aug 2004 11:49:04 -0000 1.5.2.4
+++ Peer.vm 26 Aug 2004 05:16:02 -0000 1.5.2.5
@@ -255,14 +255,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, 1);
- }
- else
- {
- criteria.add($cup, 0);
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? 1 : 0);
}
}
#elseif ($col.isBooleanChar())
@@ -272,14 +265,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "Y");
- }
- else
- {
- criteria.add($cup, "N");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "Y" : "N");
}
}
#elseif ($col.isBit())
@@ -289,27 +275,15 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "1");
- }
- else
- {
- criteria.add($cup, "0");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "1" : "0");
}
}
#end
#end
- // Set the correct dbName if it has not been overridden
- // criteria.getDbName will return the same object if not set to
- // another value so == check is okay and faster
- if (criteria.getDbName() == Torque.getDefaultDB())
- {
- criteria.setDbName(DATABASE_NAME);
- }
- if (con == null)
+ setDbName(criteria);
+
+ if (con == null)
{
return BasePeer.doInsert(criteria);
}
@@ -468,14 +442,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, 1);
- }
- else
- {
- criteria.add($cup, 0);
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? 1 : 0);
}
}
#elseif ($col.isBooleanChar())
@@ -485,14 +452,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "Y");
- }
- else
- {
- criteria.add($cup, "N");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "Y" : "N");
}
}
#elseif ($col.isBit())
@@ -502,27 +462,15 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "1");
- }
- else
- {
- criteria.add($cup, "0");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "1" : "0");
}
}
#end
#end
- // Set the correct dbName if it has not been overridden
- // criteria.getDbName will return the same object if not set to
- // another value so == check is okay and faster
- if (criteria.getDbName() == Torque.getDefaultDB())
- {
- criteria.setDbName(DATABASE_NAME);
- }
- // BasePeer returns a List of Value (Village) arrays. The array
+ setDbName(criteria);
+
+ // BasePeer returns a List of Value (Village) arrays. The array
// order follows the order columns were placed in the Select clause.
if (con == null)
{
@@ -673,14 +621,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, 1);
- }
- else
- {
- criteria.add($cup, 0);
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? 1 : 0);
}
}
#elseif ($col.isBooleanChar())
@@ -690,14 +631,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "Y");
- }
- else
- {
- criteria.add($cup, "N");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "Y" : "N");
}
}
#elseif ($col.isBit())
@@ -707,14 +641,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "1");
- }
- else
- {
- criteria.add($cup, "0");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "1" : "0");
}
}
#end
@@ -723,14 +650,9 @@
#end
#end
- // Set the correct dbName if it has not been overridden
- // criteria.getDbName will return the same object if not set to
- // another value so == check is okay and faster
- if (criteria.getDbName() == Torque.getDefaultDB())
- {
- criteria.setDbName(DATABASE_NAME);
- }
- if (con == null)
+ setDbName(criteria);
+
+ if (con == null)
{
BasePeer.doUpdate(selectCriteria, criteria);
}
@@ -775,14 +697,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, 1);
- }
- else
- {
- criteria.add($cup, 0);
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? 1 : 0);
}
}
#elseif ($col.isBooleanChar())
@@ -792,14 +707,7 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "Y");
- }
- else
- {
- criteria.add($cup, "N");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "Y" : "N");
}
}
#elseif ($col.isBit())
@@ -809,26 +717,14 @@
Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- criteria.add($cup, "1");
- }
- else
- {
- criteria.add($cup, "0");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "1" : "0");
}
}
#end
#end
- // Set the correct dbName if it has not been overridden
- // criteria.getDbName will return the same object if not set to
- // another value so == check is okay and faster
- if (criteria.getDbName() == Torque.getDefaultDB())
- {
- criteria.setDbName(DATABASE_NAME);
- }
+ setDbName(criteria);
+
if (con == null)
{
BasePeer.doDelete(criteria);
@@ -1297,27 +1193,21 @@
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected static List doSelectJoin${joinColumnId}(Criteria c)
+ protected static List doSelectJoin${joinColumnId}(Criteria criteria)
throws TorqueException
{
- // Set the correct dbName if it has not been overridden
- // c.getDbName will return the same object if not set to
- // another value so == check is okay and faster
- if (c.getDbName() == Torque.getDefaultDB())
- {
- c.setDbName(DATABASE_NAME);
- }
+ setDbName(criteria);
- ${table.JavaName}Peer.addSelectColumns(c);
+ ${table.JavaName}Peer.addSelectColumns(criteria);
int offset = numColumns + 1;
- ${joinClassName}Peer.addSelectColumns(c);
+ ${joinClassName}Peer.addSelectColumns(criteria);
#set ( $lfMap = $fk.LocalForeignMapping )
#foreach ($columnName in $fk.LocalColumns)
#set ( $column = $table.getColumn($columnName) )
#set ( $columnFk = $joinTable.getColumn( $lfMap.get($columnName) ) )
- c.addJoin(${table.JavaName}Peer.$column.Name.toUpperCase(),
+ criteria.addJoin(${table.JavaName}Peer.$column.Name.toUpperCase(),
${joinClassName}Peer.$columnFk.Name.toUpperCase());
#end
@@ -1326,59 +1216,38 @@
#set ( $cup=$col.Name.toUpperCase() )
#if($col.isBooleanInt())
// check for conversion from boolean to int
- if (c.containsKey($cup))
+ if (criteria.containsKey($cup))
{
- Object possibleBoolean = c.get($cup);
+ Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- c.add($cup, 1);
- }
- else
- {
- c.add($cup, 0);
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? 1 : 0);
}
}
#elseif ($col.isBooleanChar())
// check for conversion from boolean to Y/N
if ( c.containsKey($cup) )
{
- Object possibleBoolean = c.get($cup);
+ Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- c.add($cup, "Y");
- }
- else
- {
- c.add($cup, "N");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "Y" : "N");
}
}
#elseif ($col.isBit())
// check for conversion from boolean to bit (1/0)
if (c.containsKey($cup))
{
- Object possibleBoolean = c.get($cup);
+ Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- c.add($cup, "1");
- }
- else
- {
- c.add($cup, "0");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "1" : "0");
}
}
#end
#end
- List rows = BasePeer.doSelect(c);
+ List rows = BasePeer.doSelect(criteria);
List results = new ArrayList();
for (int i = 0; i < rows.size(); i++)
@@ -1417,13 +1286,13 @@
break;
}
}
+ #if ($objectIsCaching)
if (newObject)
{
- #if ($objectIsCaching)
obj2.init${collThisTable}();
obj2.add${collThisTableMs}(obj1);
- #end
}
+ #end
results.add(obj1);
}
return results;
@@ -1481,18 +1350,12 @@
* @throws TorqueException Any exceptions caught during processing will be
* rethrown wrapped into a TorqueException.
*/
- protected static List doSelectJoinAllExcept${excludeString}(Criteria c)
+ protected static List doSelectJoinAllExcept${excludeString}(Criteria criteria)
throws TorqueException
{
- // Set the correct dbName if it has not been overridden
- // c.getDbName will return the same object if not set to another value
- // so == check is okay and faster
- if (c.getDbName() == Torque.getDefaultDB())
- {
- c.setDbName(DATABASE_NAME);
- }
+ setDbName(criteria);
- addSelectColumns(c);
+ addSelectColumns(criteria);
int offset2 = numColumns + 1;
#set ( $index = 2 )
#foreach ($fk in $table.ForeignKeys)
@@ -1503,7 +1366,7 @@
#if (!$joinClassName.equals($excludeClassName))
#set ( $new_index = $index + 1 )
- ${joinClassName}Peer.addSelectColumns(c);
+ ${joinClassName}Peer.addSelectColumns(criteria);
int offset$new_index = offset$index + ${joinClassName}Peer.numColumns;
#set ( $index = $new_index )
#end
@@ -1513,59 +1376,38 @@
#set ( $cup=$col.Name.toUpperCase() )
#if($col.isBooleanInt())
// check for conversion from boolean to int
- if (c.containsKey($cup))
+ if (criteria.containsKey($cup))
{
- Object possibleBoolean = c.get($cup);
+ Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- c.add($cup, 1);
- }
- else
- {
- c.add($cup, 0);
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? 1 : 0);
}
}
#elseif ($col.isBooleanChar())
// check for conversion from boolean to Y/N
- if ( c.containsKey($cup) )
+ if ( criteria.containsKey($cup) )
{
- Object possibleBoolean = c.get($cup);
+ Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- c.add($cup, "Y");
- }
- else
- {
- c.add($cup, "N");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "Y" : "N");
}
}
#elseif ($col.isBit())
// check for conversion from boolean to bit (1/0)
- if (c.containsKey($cup))
+ if (criteria.containsKey($cup))
{
- Object possibleBoolean = c.get($cup);
+ Object possibleBoolean = criteria.get($cup);
if (possibleBoolean instanceof Boolean)
{
- if (((Boolean) possibleBoolean).booleanValue())
- {
- c.add($cup, "1");
- }
- else
- {
- c.add($cup, "0");
- }
+ criteria.add($cup, ((Boolean) possibleBoolean).booleanValue() ? "1" : "0");
}
}
#end
#end
- List rows = BasePeer.doSelect(c);
+ List rows = BasePeer.doSelect(criteria);
List results = new ArrayList();
for (int i = 0; i < rows.size(); i++)
@@ -1636,13 +1478,13 @@
break;
}
}
+ #if ($objectIsCaching)
if (newObject)
{
- #if ($objectIsCaching)
obj${index}.init${collThisTable}();
obj${index}.add${collThisTableMs}(obj1);
- #end
}
+ #end
#end
#end
#end
@@ -1671,4 +1513,15 @@
return Torque.getDatabaseMap(DATABASE_NAME).getTable(TABLE_NAME);
}
#end ## ends if (!$table.isAlias())
+
+ private static void setDbName(Criteria crit)
+ {
+ // Set the correct dbName if it has not been overridden
+ // crit.getDbName will return the same object if not set to
+ // another value so == check is okay and faster
+ if (crit.getDbName() == Torque.getDefaultDB())
+ {
+ crit.setDbName(DATABASE_NAME);
+ }
+ }
}
1.7.2.4 +3 -3 db-torque/src/generator/src/templates/om/Object.vm
Index: Object.vm
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/templates/om/Object.vm,v
retrieving revision 1.7.2.3
retrieving revision 1.7.2.4
diff -u -r1.7.2.3 -r1.7.2.4
--- Object.vm 14 Aug 2004 12:02:33 -0000 1.7.2.3
+++ Object.vm 26 Aug 2004 05:16:02 -0000 1.7.2.4
@@ -917,7 +917,7 @@
#elseif ($cjtype == "double")
return new Double(get${cfc}());
#elseif ($cjtype == "boolean")
- return new Boolean(get${cfc}());
+ return Boolean.valueOf(get${cfc}());
#elseif ($cjtype == "short")
return new Short(get${cfc}());
#elseif ($cjtype == "byte")
@@ -957,7 +957,7 @@
#elseif ($cjtype == "double")
return new Double(get${cfc}());
#elseif ($cjtype == "boolean")
- return new Boolean(get${cfc}());
+ return Boolean.valueOf(get${cfc}());
#elseif ($cjtype == "short")
return new Short(get${cfc}());
#elseif ($cjtype == "byte")
@@ -996,7 +996,7 @@
#elseif ($cjtype == "double")
return new Double(get${cfc}());
#elseif ($cjtype == "boolean")
- return new Boolean(get${cfc}());
+ return Boolean.valueOf(get${cfc}());
#elseif ($cjtype == "short")
return new Short(get${cfc}());
#elseif ($cjtype == "byte")
No revision
No revision
1.2.2.4 +7 -7 db-torque/src/generator/src/java/org/apache/torque/engine/database/model/TypeMap.java
Index: TypeMap.java
===================================================================
RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/TypeMap.java,v
retrieving revision 1.2.2.3
retrieving revision 1.2.2.4
diff -u -r1.2.2.3 -r1.2.2.4
--- TypeMap.java 23 Aug 2004 11:49:04 -0000 1.2.2.3
+++ TypeMap.java 26 Aug 2004 05:16:03 -0000 1.2.2.4
@@ -98,13 +98,13 @@
CHAR, VARCHAR, LONGVARCHAR, CLOB, DATE, TIME, TIMESTAMP, BOOLEANCHAR
};
- public static final String CHAR_OBJECT_TYPE = "new String()";
- public static final String VARCHAR_OBJECT_TYPE = "new String()";
- public static final String LONGVARCHAR_OBJECT_TYPE = "new String()";
- public static final String CLOB_OBJECT_TYPE = "new String()";
+ public static final String CHAR_OBJECT_TYPE = "\"\"";
+ public static final String VARCHAR_OBJECT_TYPE = "\"\"";
+ public static final String LONGVARCHAR_OBJECT_TYPE = "\"\"";
+ public static final String CLOB_OBJECT_TYPE = "\"\"";
public static final String NUMERIC_OBJECT_TYPE = "new BigDecimal(0)";
public static final String DECIMAL_OBJECT_TYPE = "new BigDecimal(0)";
- public static final String BIT_OBJECT_TYPE = "new Boolean(true)";
+ public static final String BIT_OBJECT_TYPE = "Boolean.TRUE";
public static final String TINYINT_OBJECT_TYPE = "new Byte((byte)0)";
public static final String SMALLINT_OBJECT_TYPE = "new Short((short)0)";
public static final String INTEGER_OBJECT_TYPE = "new Integer(0)";
@@ -119,7 +119,7 @@
public static final String DATE_OBJECT_TYPE = "new Date()";
public static final String TIME_OBJECT_TYPE = "new Date()";
public static final String TIMESTAMP_OBJECT_TYPE = "new Date()";
- public static final String BOOLEANCHAR_OBJECT_TYPE = "new String()";
+ public static final String BOOLEANCHAR_OBJECT_TYPE = "\"\"";
public static final String BOOLEANINT_OBJECT_TYPE = "new Integer(0)";
public static final String CHAR_NATIVE_TYPE = "String";
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org