Return-Path: Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: (qmail 23911 invoked from network); 5 May 2005 10:45:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 5 May 2005 10:45:30 -0000 Received: (qmail 10245 invoked by uid 500); 5 May 2005 10:47:12 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 10127 invoked by uid 500); 5 May 2005 10:47:09 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 9985 invoked by uid 500); 5 May 2005 10:47:07 -0000 Received: (qmail 9904 invoked by uid 99); 5 May 2005 10:47:06 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 05 May 2005 03:47:04 -0700 Received: (qmail 23714 invoked by uid 1977); 5 May 2005 10:44:42 -0000 Date: 5 May 2005 10:44:42 -0000 Message-ID: <20050505104442.23713.qmail@minotaur.apache.org> From: tfischer@apache.org To: db-torque-cvs@apache.org Subject: cvs commit: db-torque/src/generator/src/templates/om Peer.vm X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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