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 Wed, 29 Dec 2004 20:45:01 GMT
tfischer    2004/12/29 12:45:01

  Modified:    src/java/org/apache/torque/util Tag: TORQUE_3_1_BRANCH
                        SQLBuilder.java
               src/rttest/org/apache/torque Tag: TORQUE_3_1_BRANCH
                        DataTest.java
  Log:
  This change removes qualifiers from table names. An example would be the columnanme "DISTINCT
x.y". These columnnames appear if one wants to count datasets.
  e.g. wanted SQL:  select count(distinct x.y) from x
  
  java:
  Criteria criteria = new criteria;
  criteria.addSelectColumn("count(distinct x.y)");
  BasePeer.doSelect(criteria);
  
  produced until now:
  select count(distinct x.y) from distinct x
  
  This change basically restores former behavour, see BasePeer 1.76.2.5, line 2153 and following.
  Also added a test case which tests the correct behaviour
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.7   +34 -2     db-torque/src/java/org/apache/torque/util/Attic/SQLBuilder.java
  
  Index: SQLBuilder.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/java/org/apache/torque/util/Attic/SQLBuilder.java,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- SQLBuilder.java	13 Dec 2004 17:08:28 -0000	1.1.2.6
  +++ SQLBuilder.java	29 Dec 2004 20:45:01 -0000	1.1.2.7
  @@ -158,6 +158,38 @@
   
           return null; // Ugh
       }
  +    
  +    /**
  +     * Removes possible qualifiers (like DISTINCT) from a column name
  +     *
  +     * @param name The column name, possibly containing qualifiers
  +     *
  +     * @return The column name
  +     *
  +     * @throws TorqueException If the column name was malformed
  +     */
  +    private static String removeQualifiers(final String name)
  +            throws TorqueException
  +    {
  +        // Empty name => return it
  +        if (StringUtils.isEmpty(name))
  +        {
  +            return name;
  +        }
  +
  +        final int spacePos = name.trim().lastIndexOf(' ');
  +
  +        // Do we have spaces, indicating that qualifiers are used ?
  +        if (spacePos > 0)
  +        {
  +            // Qualifiers are first, tablename is piece after last space
  +            return name.trim().substring(spacePos + 1);
  +        }
  +        
  +        // no spaces, nothing changed
  +        return name;
  +    }
  +    
   
       /**
        * Returns a table name from an identifier. Each identifier is to be qualified 
  @@ -172,7 +204,7 @@
       public static String getTableName(final String name, final String dbName)
               throws TorqueException
       {
  -        final String testName = removeSQLFunction(name);
  +        final String testName = removeQualifiers(removeSQLFunction(name));
   
           if (StringUtils.isEmpty(testName))
           {
  
  
  
  No                   revision
  No                   revision
  1.8.2.7   +19 -2     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.6
  retrieving revision 1.8.2.7
  diff -u -r1.8.2.6 -r1.8.2.7
  --- DataTest.java	27 Dec 2004 19:52:47 -0000	1.8.2.6
  +++ DataTest.java	29 Dec 2004 20:45:01 -0000	1.8.2.7
  @@ -358,7 +358,24 @@
           {
               result = BookPeer.doSelectVillageRecords(criteria);
           }
  -        catch(Exception e) {
  +        catch(Exception e) 
  +        {
  +            e.printStackTrace();
  +            fail("count(distinct(...)) : Exception caught : " 
  +                     + e.getClass().getName() 
  +                     + " : " + e.getMessage());
  +        }
  +        
  +        // test qualifiers in function in select columns
  +        criteria = new Criteria();
  +        criteria.addSelectColumn("count(distinct " + BookPeer.BOOK_ID + ")");
  +        
  +        try 
  +        {
  +            result = BookPeer.doSelectVillageRecords(criteria);
  +        }
  +        catch(Exception e) 
  +        {
               e.printStackTrace();
               fail("count(distinct(...)) : Exception caught : " 
                        + e.getClass().getName() 
  
  
  

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