cvs commit: db-torque/src/rttest/org/apache/torque DataTest.java

2005-05-05 Thread tfischer
tfischer2005/05/05 01:17:11

  Modified:src/rttest/org/apache/torque DataTest.java
  Log:
  added a test case to test primary keys which are also foreign keys
  added a test to the orderByTest to check usage of sql functions in the order 
by clause
  
  Revision  ChangesPath
  1.16  +27 -1 db-torque/src/rttest/org/apache/torque/DataTest.java
  
  Index: DataTest.java
  ===
  RCS file: /home/cvs/db-torque/src/rttest/org/apache/torque/DataTest.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DataTest.java 23 Apr 2005 14:58:14 -  1.15
  +++ DataTest.java 5 May 2005 08:17:11 -   1.16
  @@ -34,9 +34,12 @@
   import org.apache.torque.test.BooleanCheckPeer;
   import org.apache.torque.test.DateTest;
   import org.apache.torque.test.DateTestPeer;
  +import org.apache.torque.test.IntegerPk;
  +import org.apache.torque.test.IntegerPkPeer;
   import org.apache.torque.test.LargePk;
   import org.apache.torque.test.LargePkPeer;
   import org.apache.torque.test.MultiPk;
  +import org.apache.torque.test.MultiPkForeignKey;
   import org.apache.torque.test.MultiPkPeer;
   import org.apache.torque.test.NullValueTable;
   import org.apache.torque.util.BasePeer;
  @@ -726,6 +729,12 @@
+ , should be \Book 2\);
   }
   
  +// test usage of Expressions in order by
  +criteria = new Criteria();
  +criteria.addAscendingOrderByColumn(UPPER( + BookPeer.TITLE + 
));
  +criteria.setIgnoreCase(true);
  +BookPeer.doSelect(criteria);
  +
   }
   catch( Exception e) 
   {
  @@ -1034,6 +1043,23 @@
+  :  + e.getMessage());
   }
   }
  +
  +
  +/**
  + * Tests whether we can handle multiple primary keys some of which are 
  + * also foreign keys
  + * @throws Exception if the testfails
  + */
  +public void testMultiplePrimaryForeignKey() throws Exception
  +{
  +IntegerPk integerPk = new IntegerPk();
  +integerPk.save();
  +MultiPkForeignKey multiPkForeignKey = new MultiPkForeignKey();
  +multiPkForeignKey.setId(10);
  +multiPkForeignKey.setIntegerPk(integerPk);
  +multiPkForeignKey.save();
  +integerPk.save();
  +}
   
   /**
* Tests inserting single quotes in Strings.
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: db-torque/src/generator/src/templates/om Peer.vm

2005-05-05 Thread tfischer
tfischer2005/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  ChangesPath
  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 -  1.13
  +++ Peer.vm   5 May 2005 10:44:42 -   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)