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/rttest/org/apache/torque DataTest.java
Date Mon, 06 Dec 2004 19:53:54 GMT
tfischer    2004/12/06 11:53:54

  Modified:    src/rttest/org/apache/torque Tag: TORQUE_3_1_BRANCH
                        DataTest.java
  Log:
  removed compile errors
  added new method testAsColumn() which runs a simple test on Criteria.addAsColumn(...)
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.8.2.4   +52 -8     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.8.2.3
  retrieving revision 1.8.2.4
  diff -u -r1.8.2.3 -r1.8.2.4
  --- DataTest.java	1 Dec 2004 15:03:39 -0000	1.8.2.3
  +++ DataTest.java	6 Dec 2004 19:53:54 -0000	1.8.2.4
  @@ -31,6 +31,7 @@
   import org.apache.torque.test.MultiPk;
   import org.apache.torque.test.MultiPkPeer;
   import org.apache.torque.test.NullValueTable;
  +import org.apache.torque.util.BasePeer;
   import org.apache.torque.util.Criteria;
   
   /**
  @@ -447,7 +448,7 @@
                       Criteria.RIGHT_JOIN);
               criteria.addJoin(
                       AuthorPeer.AUTHOR_ID, 
  -                    "b." + BookPeer.getRawColumnName(BookPeer.AUTHOR_ID),
  +                    "b." + getRawColumnName(BookPeer.AUTHOR_ID),
                       Criteria.LEFT_JOIN);
               authorList = AuthorPeer.doSelect(criteria);
               // Here we get 11 authors:
  @@ -467,7 +468,7 @@
               criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID,
                       Criteria.RIGHT_JOIN);
               criteria.addJoin(
  -                    "b." + BookPeer.getRawColumnName(BookPeer.AUTHOR_ID),
  +                    "b." + getRawColumnName(BookPeer.AUTHOR_ID),
                       AuthorPeer.AUTHOR_ID,
                       Criteria.RIGHT_JOIN);
               authorList = AuthorPeer.doSelect(criteria);
  @@ -577,9 +578,9 @@
               criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
               criteria.addJoin(
                       AuthorPeer.AUTHOR_ID, 
  -                    "b." + BookPeer.getRawColumnName(BookPeer.AUTHOR_ID));
  +                    "b." + getRawColumnName(BookPeer.AUTHOR_ID));
               criteria.addAscendingOrderByColumn(
  -                    "b." + BookPeer.getRawColumnName(BookPeer.TITLE));
  +                    "b." + getRawColumnName(BookPeer.TITLE));
               criteria.addDescendingOrderByColumn(BookPeer.TITLE);
               // the retrieved columns are
               // author    book   b
  @@ -617,10 +618,10 @@
               criteria.addJoin(BookPeer.AUTHOR_ID, AuthorPeer.AUTHOR_ID);
               criteria.addJoin(
                       AuthorPeer.AUTHOR_ID, 
  -                    "b." + BookPeer.getRawColumnName(BookPeer.AUTHOR_ID));
  +                    "b." + getRawColumnName(BookPeer.AUTHOR_ID));
               criteria.addAscendingOrderByColumn(BookPeer.TITLE);
               criteria.addDescendingOrderByColumn(
  -                    "b." + BookPeer.getRawColumnName(BookPeer.TITLE));
  +                    "b." + getRawColumnName(BookPeer.TITLE));
               // the retrieved columns are
               // author    book   b
               // author1  book1   book1
  @@ -672,11 +673,11 @@
           {
               Author author = new Author();
               author.setName("AuTHor");
  -            criteria.setIgnoreCase(true);
               author.save();
               
               Criteria criteria = new Criteria();
               criteria.add(AuthorPeer.NAME, author.getName().toLowerCase());
  +            criteria.setIgnoreCase(true);
               List result = AuthorPeer.doSelect(criteria);
               if (result.size() != 1) 
               {
  @@ -692,6 +693,27 @@
           }
       }
       
  +    /**
  +     * tests AsColumns produce valid SQL code
  +     */
  +    public void testAsColumn() {
  +        try 
  +        {
  +            Criteria criteria = new Criteria();
  +            criteria.addAsColumn("ALIASNAME", AuthorPeer.NAME);
  +            // we need an additional column to select from,
  +            // to indicate the table we want use
  +            criteria.addSelectColumn(AuthorPeer.AUTHOR_ID);
  +            BasePeer.doSelect(criteria);
  +        }
  +        catch( Exception e) 
  +        {
  +            e.printStackTrace();
  +            fail("Exception caught : " 
  +                     + e.getClass().getName() 
  +                     + " : " + e.getMessage());
  +        }
  +    }
   
       /**
        * Deletes all authors and books in the bookstore tables
  @@ -726,4 +748,26 @@
                        + " : " + e.getMessage());
           }
       }
  +    
  +    
  +    /**
  +     * Strips the schema and table name from a fully qualified colum name
  +     * This is useful for creating Query with aliases, as the constants
  +     * for the colum names in the data objects are fully qualified.
  +     * @param fullyQualifiedColumnName the fully qualified column name, not null
  +     * @return the column name stripped from the table (and schema) prefixes
  +     */
  +    public static String getRawColumnName(String fullyQualifiedColumnName) 
  +    {
  +        int dotPosition = fullyQualifiedColumnName.lastIndexOf(".");
  +        if (dotPosition == -1) 
  +        {
  +            return fullyQualifiedColumnName;
  +        }
  +        String result = fullyQualifiedColumnName.substring(
  +                dotPosition + 1, 
  +                fullyQualifiedColumnName.length());
  +        return result;
  +    }
  +
   }
  
  
  

---------------------------------------------------------------------
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