You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jo...@apache.org on 2001/09/19 01:32:07 UTC

cvs commit: jakarta-turbine-torque/src/templates/om Peer.vm

jon         01/09/18 16:32:07

  Modified:    src/templates/om Peer.vm
  Log:
  get rid of a bunch of duplicated code
  
  cleaned up some comments
  
  wrapped some lines
  
  Revision  Changes    Path
  1.3       +58 -201   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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Peer.vm	2001/08/29 05:48:42	1.2
  +++ Peer.vm	2001/09/18 23:32:07	1.3
  @@ -142,7 +142,10 @@
       public static final Class CLASS_$child.Key.toUpperCase() = 
           init${child.Key.toUpperCase()}Class();
   
  -    /** Initialization method for static CLASS_$child.Key.toUpperCase() attribute */
  +    /**
  +     * Initialization method for static 
  +     * CLASS_$child.Key.toUpperCase() attribute
  +     */
       private static Class init${child.Key.toUpperCase()}Class()
       {
           Class c = null;
  @@ -163,51 +166,13 @@
       #end
   #end
   
  -    /** Method to do inserts */
  +    /** 
  +     * Method to do inserts 
  +     */
       public static ObjectKey doInsert( Criteria criteria ) throws Exception
       {
  -    #if ($table.Database.Name != "default")
  -        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
  -    #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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, 1);
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, 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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, "Y");
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, "N");
  -                }
  -            }                     
  -         }
  -         #end
  -     #end
  -        return BasePeer.doInsert( criteria );
  +        return $basePrefix${table.JavaName}Peer
  +            .doInsert( criteria, (DBConnection) null );
       }
   
       /** 
  @@ -259,7 +224,14 @@
            }
            #end
        #end
  -        return BasePeer.doInsert( criteria, dbCon );
  +        if ( dbCon == null )
  +        {
  +            return BasePeer.doInsert( criteria );
  +        }
  +        else
  +        {
  +            return BasePeer.doInsert( criteria, dbCon );
  +        }
       }
   
       /** Add all the columns needed to create a new object */
  @@ -349,64 +321,10 @@
       public static Vector doSelectVillageRecords( Criteria criteria ) 
           throws Exception
       {
  -    #if ($database == "postgresql" && $table.requiresTransactionInPostgres())
  -         // stuff for postgresql problem.....
  -         criteria.setBlobFlag();
  -    #end 
  - 
  -    #if ($table.Database.Name != "default")
  -        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
  -    #end
  -        if (criteria.getSelectColumns().size() == 0)
  -        {
  -            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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, 1);
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, 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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, "Y");
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, "N");
  -                }
  -            }                     
  -         }
  -         #end
  -     #end
  -
  -        // BasePeer returns a Vector of Value (Village) arrays.  The array
  -        // order follows the order columns were placed in the Select clause.
  -        return BasePeer.doSelect(criteria);
  +        return $basePrefix${table.JavaName}Peer
  +            .doSelectVillageRecords(criteria, (DBConnection) null);
       }
   
  -
       /** 
        * Grabs the raw Village records to be formed into objects.
        * This method should be used for transactions 
  @@ -466,7 +384,14 @@
   
           // BasePeer returns a Vector of Value (Village) arrays.  The array
           // order follows the order columns were placed in the Select clause.
  -        return BasePeer.doSelect(criteria, dbCon);
  +        if ( dbCon == null)
  +        {
  +            return BasePeer.doSelect(criteria);
  +        }
  +        else
  +        {
  +            return BasePeer.doSelect(criteria, dbCon);
  +        }
       }
   
       /** 
  @@ -562,53 +487,8 @@
        */
       public static void doUpdate(Criteria criteria) throws Exception
       {
  -    #if ($table.Database.Name != "default")
  -        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
  -    #end
  -        Criteria selectCriteria = new
  -            Criteria(mapBuilder.getDatabaseMap().getName(), 2);
  -     #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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, 1);
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, 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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, "Y");
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, "N");
  -                }
  -            }                     
  -        }
  -         #end
  -         #if($col.isPrimaryKey())
  -         selectCriteria.put( $cup, criteria.remove($cup) );
  -         #end
  -     #end
  -         BasePeer.doUpdate( selectCriteria, criteria );
  +         $basePrefix${table.JavaName}Peer
  +            .doUpdate( criteria, (DBConnection) null );
       }
   
       /** 
  @@ -666,8 +546,16 @@
            selectCriteria.put( $cup, criteria.remove($cup) );
            #end
        #end
  -         BasePeer.doUpdate( selectCriteria, criteria, dbCon );
  -     }
  +
  +        if ( dbCon == null )
  +        {
  +            BasePeer.doUpdate( selectCriteria, criteria );
  +        }
  +        else
  +        {
  +            BasePeer.doUpdate( selectCriteria, criteria, dbCon );
  +        }
  +    }
   
       /** 
        * Method to do deletes.
  @@ -676,48 +564,8 @@
        */
        public static void doDelete(Criteria criteria) throws Exception
        {
  -    #if ($table.Database.Name != "default")
  -        criteria.setDbName(mapBuilder.getDatabaseMap().getName());
  -    #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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, 1);
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, 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 )
  -            {
  -                if ( ((Boolean)possibleBoolean).booleanValue() )
  -                {
  -                    criteria.add($cup, "Y");
  -                }
  -                else
  -                {   
  -                    criteria.add($cup, "N");
  -                }
  -            }                     
  -         }
  -         #end
  -     #end
  -         BasePeer.doDelete ( criteria );
  +         $basePrefix${table.JavaName}Peer
  +            .doDelete ( criteria, (DBConnection) null );
        }
   
       /** 
  @@ -727,7 +575,8 @@
        *
        * @param Criteria object containing data that is used DELETE from database.
        */
  -     public static void doDelete(Criteria criteria, DBConnection dbCon) throws Exception
  +     public static void doDelete(Criteria criteria, DBConnection dbCon) 
  +        throws Exception
        {
       #if ($table.Database.Name != "default")
           criteria.setDbName(mapBuilder.getDatabaseMap().getName());
  @@ -770,7 +619,15 @@
            }
            #end
        #end
  -         BasePeer.doDelete ( criteria, dbCon );
  +
  +        if ( dbCon == null )
  +        {
  +            BasePeer.doDelete ( criteria );
  +        }
  +        else
  +        {
  +            BasePeer.doDelete ( criteria, dbCon );
  +        }
        }
   
       /** Method to do selects */
  @@ -813,7 +670,8 @@
        *
        * @param obj the data object to insert into the database.
        */
  -    public static void doInsert( $table.JavaName obj, DBConnection dbCon) throws Exception
  +    public static void doInsert( $table.JavaName obj, DBConnection dbCon)
  +        throws Exception
       {
           #if ($table.IdMethod.equals("none"))
           doInsert(buildCriteria(obj), dbCon);
  @@ -830,7 +688,8 @@
        *
        * @param obj the data object to update in the database.
        */
  -    public static void doUpdate($table.JavaName obj, DBConnection dbCon) throws Exception
  +    public static void doUpdate($table.JavaName obj, DBConnection dbCon)
  +        throws Exception
       {
           doUpdate(buildCriteria(obj), dbCon);
       }
  @@ -841,7 +700,8 @@
        *
        * @param obj the data object to delete in the database.
        */
  -    public static void doDelete($table.JavaName obj, DBConnection dbCon) throws Exception
  +    public static void doDelete($table.JavaName obj, DBConnection dbCon)
  +        throws Exception
       {
           doDelete(buildCriteria(obj), dbCon);
       }
  @@ -1081,8 +941,6 @@
        #end
   
   
  -
  -
        #foreach ($col in $table.Columns)
            #set ( $cup=$col.Name.toUpperCase() )
            #if($col.isBooleanInt())
  @@ -1203,7 +1061,6 @@
           #set ( $collThisTable=$strings.concat([$className,"sRelatedBy",$relatedByCol]) )
           #set ( $collThisTableMs=$strings.concat([$className,"RelatedBy",$relatedByCol]) )
        #end
  -
   
   
      /**
  
  
  

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