seade       2004/08/25 22:18:39

  Modified:    src/generator/src/templates/om Object.vm Peer.vm
                        ObjectWithManager.vm
               src/generator/src/java/org/apache/torque/engine/database/model
                        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
  1.15      +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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Object.vm 14 Aug 2004 12:01:42 -0000      1.14
  +++ Object.vm 26 Aug 2004 05:18:38 -0000      1.15
  @@ -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")
  
  
  
  1.9       +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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Peer.vm   23 Aug 2004 11:49:47 -0000      1.8
  +++ Peer.vm   26 Aug 2004 05:18:38 -0000      1.9
  @@ -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.10      +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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ObjectWithManager.vm      22 Jan 2004 00:55:06 -0000      1.9
  +++ ObjectWithManager.vm      26 Aug 2004 05:18:38 -0000      1.10
  @@ -874,7 +874,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")
  @@ -914,7 +914,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")
  @@ -953,7 +953,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.10      +6 -6      
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- TypeMap.java      24 Aug 2004 01:14:22 -0000      1.9
  +++ TypeMap.java      26 Aug 2004 05:18:38 -0000      1.10
  @@ -85,10 +85,10 @@
           SchemaType.TIMESTAMP, SchemaType.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)";
  @@ -106,7 +106,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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to