db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject cvs commit: db-torque/src/generator/src/templates/om Peer.vm
Date Thu, 05 May 2005 10:44:42 GMT
tfischer    2005/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  Changes    Path
  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 -0000	1.13
  +++ Peer.vm	5 May 2005 10:44:42 -0000	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)
       #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 int
  -        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
  +
       #if($col.isPrimaryKey())
            selectCriteria.put($cup, criteria.remove($cup));
       #end
  @@ -689,41 +639,8 @@
        public static void doDelete(Criteria criteria, Connection con)
           throws TorqueException
        {
  -  #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);
   
           if (con == null)
  @@ -1263,42 +1180,8 @@
               ${joinClassName}Peer.$columnFk.Name.toUpperCase());
           #end
   
  -
  -        #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);
  +        
   		List rows;
   		if( conn == null )
   	        rows = BasePeer.doSelect(criteria);
  @@ -1445,40 +1328,8 @@
               #end
             #end
           #end
  -        #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);
   
           List rows; 
           if( conn == null )
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message