db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1206840 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/sql/ torque-runtime/src/main/java/org/apache/torque/util/ torque-runtime/src/test/java/org/apache/torque/ torque-runtime/src/test/java/org/apache/torque/...
Date Sun, 27 Nov 2011 20:38:55 GMT
Author: tfischer
Date: Sun Nov 27 20:38:52 2011
New Revision: 1206840

URL: http://svn.apache.org/viewvc?rev=1206840&view=rev
Log:
Added runtime tests for SqlBuilder
Fixed an escaping bug in like (remove backslashes before * and ?)

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/WhereClauseExpression.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SqlEnum.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/BaseTestCase.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/TorqueInstanceTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java
    db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/SqlBuilder.java Sun Nov 27 20:38:52 2011
@@ -96,7 +96,7 @@ public final class SqlBuilder
         processSelectColumns(crit, sqlStatement, database);
         processAsColumns(crit, sqlStatement, database);
         processCriterions(db, database, crit, sqlStatement);
-        processGroupBy(crit, sqlStatement);
+        processGroupBy(crit, database, sqlStatement);
         processHaving(crit, sqlStatement);
         processOrderBy(db, database, crit, sqlStatement);
         processLimits(crit, sqlStatement);
@@ -382,22 +382,27 @@ public final class SqlBuilder
     }
 
     /**
-     * adds the GroupBy-Columns from the criteria to the query
-     * @param criteria the criteria from which the GroupBy-Columns are taken
-     * @param query the query to which the GroupBy-Columns should be added
+     * Adds the GroupBy-Columns from the criteria to the query.
+     *
+     * @param criteria the criteria from which the GroupBy-Columns are taken.
+     * @param database the database.
+     * @param query the query to which the GroupBy-Columns should be added.
+     *
      * @throws TorqueException if the GroupBy-Columns can not be processed
      */
     private static void processGroupBy(
-            final Criteria crit,
+            final Criteria criteria,
+            final Database database,
             final Query query)
             throws TorqueException
     {
         UniqueList<String> groupByClause = query.getGroupByClause();
-        UniqueColumnList groupBy = crit.getGroupByColumns();
+        UniqueList<String> selectClause = query.getSelectClause();
+        UniqueColumnList groupBy = criteria.getGroupByColumns();
 
         for (Column groupByColumn : groupBy)
         {
-            Column column = crit.getAsColumns().get(
+            Column column = criteria.getAsColumns().get(
                     groupByColumn.getSqlExpression());
 
             if (column == null)
@@ -405,7 +410,9 @@ public final class SqlBuilder
                 column = groupByColumn;
             }
 
-            groupByClause.add(column.getColumnName());
+            groupByClause.add(column.getSqlExpression());
+            selectClause.add(column.getSqlExpression());
+            addTableToFromClause(column, database, criteria, query);
         }
     }
 
@@ -423,7 +430,6 @@ public final class SqlBuilder
         Criteria.Criterion having = crit.getHaving();
         if (having != null)
         {
-            //String groupByString = null;
             query.setHaving(having.toString());
         }
     }
@@ -857,10 +863,14 @@ public final class SqlBuilder
                     // ignore backslashes at end
                     break;
                 }
-                sb.append(checkWildcard);
                 position++;
+                char escapedChar = value.charAt(position);
+                if (escapedChar != '*' && escapedChar != '?')
+                {
+                    sb.append(checkWildcard);
+                }
                 // code below copies escaped character into sb
-                checkWildcard = value.charAt(position);
+                checkWildcard = escapedChar;
                 break;
             case '%':
             case '_':

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/WhereClauseExpression.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/WhereClauseExpression.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/WhereClauseExpression.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/WhereClauseExpression.java Sun Nov 27 20:38:52 2011
@@ -19,6 +19,7 @@ package org.apache.torque.sql;
  * under the License.
  */
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.torque.util.SqlEnum;
 
 /**
@@ -32,10 +33,9 @@ import org.apache.torque.util.SqlEnum;
 public class WhereClauseExpression
 {
     /**
-     * The value on the left hand side of the operator,
-     * representing the name of a column, not null.
+     * The value on the left hand side of the operator, not null or empty.
      */
-    private String lValue = "";
+    private String lValue;
 
     /**
      * The operator.
@@ -45,7 +45,7 @@ public class WhereClauseExpression
     /**
      * The value on the right hand side of the operator.
      */
-    private Object rValue = "";
+    private Object rValue;
 
     /**
      * Constructor.
@@ -80,13 +80,16 @@ public class WhereClauseExpression
      * Sets the value on the left hand side of the operator of the
      * expression. The value represents the name of a database column.
      *
-     * @param lValue the value to set, or null for the empty String.
+     * @param lValue the value to set, not null or empty.
+     *
+     * @throws IllegalArgumentException if lValue is null or empty.
      */
     public void setLValue(String lValue)
     {
-        if (lValue == null)
+        if (StringUtils.isEmpty(lValue))
         {
-            this.lValue = "";
+            throw new IllegalArgumentException(
+                    "lValue must not be null or empty");
         }
         else
         {

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/Criteria.java Sun Nov 27 20:38:52 2011
@@ -465,6 +465,9 @@ public class Criteria implements Seriali
      * Criterions to form a more complex where clause.
      *
      * @param column String full name of column (for example TABLE.COLUMN).
+     * @param value The value to compare to.
+     * @param comparison the comparison to use.
+     *
      * @return A Criterion.
      */
     public Criterion getNewCriterion(Column column, Object value,
@@ -478,6 +481,23 @@ public class Criteria implements Seriali
      * to this Criteria.  This can be used to chain the
      * Criterions to form a more complex where clause.
      *
+     * @param column String full name of column (for example TABLE.COLUMN).
+     * @param value The value to compare to.
+     * @param comparison the comparison to use.
+     *
+     * @return A Criterion.
+     */
+    public Criterion getNewCriterion(String column, Object value,
+            SqlEnum comparison)
+    {
+        return new Criterion(new ColumnImpl(column), value, comparison);
+    }
+
+    /**
+     * Method to return criterion that is not added automatically
+     * to this Criteria.  This can be used to chain the
+     * Criterions to form a more complex where clause.
+     *
      * @param table String name of table.
      * @param column String name of column.
      * @return A Criterion.
@@ -1972,6 +1992,20 @@ public class Criteria implements Seriali
         return this;
     }
 
+
+    /**
+     * Add order by column name, explicitly specifying ascending.
+     *
+     * @param column The column to order by.
+     * @param ignoreCase whether to ignore case on String columns.
+     *
+     * @return A modified Criteria object.
+     */
+    public Criteria addAscendingOrderByColumn(Column column, boolean ignoreCase)
+    {
+        orderByColumns.add(new OrderBy(column, SqlEnum.ASC, ignoreCase));
+        return this;
+    }
     /**
      * Add order by column name, explicitly specifying ascending.
      *
@@ -2001,6 +2035,22 @@ public class Criteria implements Seriali
      * Add order by column name, explicitly specifying descending.
      *
      * @param column The column to order by.
+     * @param ignoreCase whether to ignore case on String columns.
+     *
+     * @return A modified Criteria object.
+     */
+    public Criteria addDescendingOrderByColumn(
+            Column column,
+            boolean ignoreCase)
+    {
+        orderByColumns.add(new OrderBy(column, SqlEnum.DESC, ignoreCase));
+        return this;
+    }
+
+    /**
+     * Add order by column name, explicitly specifying descending.
+     *
+     * @param column The column to order by.
      * @return A modified Criteria object.
      */
     public Criteria addDescendingOrderByColumn(String column)

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SqlEnum.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SqlEnum.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SqlEnum.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SqlEnum.java Sun Nov 27 20:38:52 2011
@@ -108,10 +108,10 @@ public final class SqlEnum implements ja
         new SqlEnum("DESC");
     /** SQL Expression " IS NULL ". */
     public static final SqlEnum ISNULL =
-        new SqlEnum(" IS NULL ");
+        new SqlEnum(" IS NULL");
     /** SQL Expression " IS NOT NULL ". */
     public static final SqlEnum ISNOTNULL =
-        new SqlEnum(" IS NOT NULL ");
+        new SqlEnum(" IS NOT NULL");
     /** SQL Expression "CURRENT_DATE". */
     public static final SqlEnum CURRENT_DATE =
         new SqlEnum("CURRENT_DATE");

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/BaseTestCase.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/BaseTestCase.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/BaseTestCase.java Sun Nov 27 20:38:52 2011
@@ -45,8 +45,14 @@ public abstract class BaseTestCase exten
     /** A pre-filled database map. */
     protected DatabaseMap databaseMap;
 
-    /** A pre-filled database. */
-    protected Database database;
+    /** A Reference to the postgresql (default) database. */
+    protected Database databasePostgresql;
+
+    /** A Reference to the mysql database. */
+    protected Database databaseMysql;
+
+    /** A Reference to the oracle database. */
+    protected Database databaseOracle;
 
     /** A pre-filled String column map. */
     protected ColumnMap stringColumnMap;
@@ -66,7 +72,9 @@ public abstract class BaseTestCase exten
         Torque.init(CONFIG_FILE);
 
         databaseMap = Torque.getDatabaseMap("postgresql");
-        database = databaseMap.getDatabase();
+        databasePostgresql = databaseMap.getDatabase();
+        databaseMysql = Torque.getDatabaseMap("mysql").getDatabase();
+        databaseOracle = Torque.getDatabaseMap("oracle").getDatabase();
         tableMap = databaseMap.addTable("TABLE");
         {
             stringColumnMap = new ColumnMap("COLUMN1", tableMap);

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/TorqueInstanceTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/TorqueInstanceTest.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/TorqueInstanceTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/TorqueInstanceTest.java Sun Nov 27 20:38:52 2011
@@ -21,12 +21,8 @@ package org.apache.torque;
 
 import java.util.Map;
 
-import junit.framework.TestCase;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.torque.adapter.DB;
+import org.apache.torque.adapter.DBPostgres;
 import org.apache.torque.dsfactory.DataSourceFactory;
 
 /**
@@ -35,38 +31,15 @@ import org.apache.torque.dsfactory.DataS
  * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
  * @version $Id$
  */
-public class TorqueInstanceTest extends TestCase
+public class TorqueInstanceTest extends BaseTestCase
 {
     /** The name of the "default" dataSourceFactory. */
     private static final String DEFAULT_NAME = "default";
 
     /**
-     * The name of the "mysql" dataSourceFactory
+     * The name of the "postgresql" dataSourceFactory
      */
-    private static final String MYSQL_NAME = "mysql";
-
-    /**
-     * Creates a new instance.
-     *
-     * @param name the name of the test case to run
-     */
-    public TorqueInstanceTest(String name)
-    {
-        super(name);
-    }
-
-    /**
-     * Performs initialisations before the test.
-     *
-     * @throws Exception if the initialisation fails.
-     */
-    protected void setUp() throws Exception
-    {
-        if (!Torque.isInit())
-        {
-            Torque.init(getConfiguration());
-        }
-    }
+    private static final String POSTGRESQL_NAME = "postgresql";
 
     /**
      * Tests whether an external adapter is loaded correctly.
@@ -74,8 +47,9 @@ public class TorqueInstanceTest extends 
      */
     public void testExternalAdapter() throws Exception
     {
-        DB adapter = Torque.getDatabase(MYSQL_NAME).getAdapter();
+        DB adapter = Torque.getDatabase(POSTGRESQL_NAME).getAdapter();
         assertNotNull(adapter);
+        assertTrue(adapter instanceof DBPostgres);
     }
 
     /**
@@ -92,13 +66,13 @@ public class TorqueInstanceTest extends 
                 + DEFAULT_NAME
                 + " should not be null",
                 defaultDataSourceFactory);
-        DataSourceFactory turbineDataSourceFactory
-                = Torque.getInstance().getDataSourceFactory(DEFAULT_NAME);
+        DataSourceFactory postgresqlDataSourceFactory
+                = Torque.getInstance().getDataSourceFactory(POSTGRESQL_NAME);
         assertSame("The default DataSourceFactory "
-                + "and the turbine DataSourceFactory "
+                + "and the postgresql DataSourceFactory "
                 + "are not the same object",
                 defaultDataSourceFactory,
-                turbineDataSourceFactory);
+                postgresqlDataSourceFactory);
     }
 
     /**
@@ -108,23 +82,23 @@ public class TorqueInstanceTest extends 
     public void testDatabases() throws Exception
     {
         //Torque.init(getConfiguration());
-        Map databases = Torque.getDatabases();
+        Map<String, Database> databases = Torque.getDatabases();
         // check whether all expected databases are contained in the Map
         assertEquals(
-                "Databases should contain 3 Databases, not "
+                "Databases should contain 4 Databases, not "
                     + databases.size(),
-                3,
+                4,
                 databases.size());
 
         // check that the default database and the turbine database
         // refer to the same object
         Database defaultDatabase = Torque.getDatabase(DEFAULT_NAME);
-        Database turbineDatabase = Torque.getDatabase(MYSQL_NAME);
+        Database postgresqlDatabase = Torque.getDatabase(POSTGRESQL_NAME);
 
         assertNotSame("The default database and the turbine database "
                         + "are the same object",
                     defaultDatabase,
-                    turbineDatabase);
+                    postgresqlDatabase);
     }
 
     public void testShutdown() throws Exception
@@ -132,7 +106,7 @@ public class TorqueInstanceTest extends 
         // because we have not properly initialized the DataSourceFactory,
         // closing the DatasourceFactory down would result in an error.
         // So we have to remove the reference to the DatasourceFactory.
-        Torque.getDatabase(MYSQL_NAME).setDataSourceFactory(null);
+        Torque.getDatabase(POSTGRESQL_NAME).setDataSourceFactory(null);
 
         Torque.shutdown();
         assertFalse("Torque.isInit() should return false after shutdown",
@@ -143,21 +117,9 @@ public class TorqueInstanceTest extends 
             fail("Torque.getDatabases() should throw an Exception "
                     + "after shutdown");
         }
-        catch (Exception e)
+        catch (TorqueException e)
         {
+            assertEquals("Torque is not initialized.", e.getMessage());
         }
     }
-
-    /**
-     * Reads and returns the configuration out of the configuration file.
-     * @return
-     * @throws ConfigurationException
-     */
-    private static Configuration getConfiguration() 
-            throws ConfigurationException
-    {
-        Configuration conf
-                = new PropertiesConfiguration(BaseTestCase.CONFIG_FILE);
-        return conf;
-    }
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/SqlBuilderTest.java Sun Nov 27 20:38:52 2011
@@ -20,15 +20,16 @@ package org.apache.torque.sql;
  */
 
 import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.torque.BaseTestCase;
+import org.apache.torque.Column;
 import org.apache.torque.Database;
 import org.apache.torque.TorqueException;
-import org.apache.torque.adapter.DB;
-import org.apache.torque.adapter.DBFactory;
+import org.apache.torque.om.NumberKey;
 import org.apache.torque.util.Criteria;
-import org.apache.torque.util.SqlEnum;
 
 /**
  * Tests for SqlExpression
@@ -39,123 +40,6 @@ import org.apache.torque.util.SqlEnum;
  */
 public class SqlBuilderTest extends BaseTestCase
 {
-    private DB db = null;
-
-    /**
-     * set up environment
-     */
-    public void setUp() throws Exception
-    {
-        super.setUp();
-        try
-        {
-            db = DBFactory.create("mysql");
-        }
-        catch (Exception ex)
-        {
-            ex.printStackTrace();
-        }
-    }
-
-    /**
-     * Test for buildPsIn.
-     */
-    public void testBuildPsIn()
-        {
-        WhereClauseExpression whereClauseExpression
-                = new WhereClauseExpression(
-                        "COL",
-                        SqlEnum.IN,
-                        new String[] {"42", "43", "44"});
-        PreparedStatementPart result
-            = SqlBuilder.buildPsIn(whereClauseExpression, false, db);
-        assertEquals("COL IN (?,?,?)", result.getSql().toString());
-        List<Object> replacements = result.getPreparedStatementReplacements();
-        assertEquals(3, replacements.size());
-        assertEquals("42", replacements.get(0));
-        assertEquals("43", replacements.get(1));
-        assertEquals("44", replacements.get(2));
-    }
-
-    /**
-     * Test for buildPsIn with ignore case
-     */
-    public void testBuildPsInIgnoreCase()
-        {
-        WhereClauseExpression whereClauseExpression
-            = new WhereClauseExpression(
-                    "COL",
-                    SqlEnum.IN,
-                    new String[] {"42", "43", "44"});
-        PreparedStatementPart result
-            = SqlBuilder.buildPsIn(whereClauseExpression, true, db);
-
-        assertEquals("COL IN (?,?,?)", result.getSql().toString());
-        List<Object> replacements = result.getPreparedStatementReplacements();
-        assertEquals(3, replacements.size());
-        assertEquals("42", replacements.get(0));
-        assertEquals("43", replacements.get(1));
-        assertEquals("44", replacements.get(2));
-    }
-
-    public void testLargeBuildInStringObjectSqlEnumbooleanDB()
-    {
-        int size = 10000;
-        String[] values = new String[size];
-        for (int i = 0; i < size; i++)
-        {
-            Array.set(values, i, String.valueOf(i));
-        }
-        WhereClauseExpression whereClauseExpression
-            = new WhereClauseExpression(
-                    "COL",
-                    SqlEnum.IN,
-                    values);
-        long start = System.currentTimeMillis();
-        PreparedStatementPart result
-                = SqlBuilder.buildPsIn(whereClauseExpression, true, db);
-        long end =  System.currentTimeMillis();
-        List<Object> replacements = result.getPreparedStatementReplacements();
-        assertEquals(size, replacements.size());
-        System.out.println("large buildIn took " + (end - start) + " milliseconds");
-    }
-
-    /**
-     * Test whether LIKE clauses without Escapes are built correctly.
-     */
-    public void testBuildPsLikeWithoutEscape() throws TorqueException
-    {
-        WhereClauseExpression whereClauseExpression
-            = new WhereClauseExpression(
-                    "COL",
-                    SqlEnum.LIKE,
-                    "fre%");
-        PreparedStatementPart result
-            = SqlBuilder.buildPsLike(whereClauseExpression, false, db);
-        assertEquals("COL LIKE ?", result.getSql().toString());
-        List<Object> replacements = result.getPreparedStatementReplacements();
-        assertEquals(1, replacements.size());
-        assertEquals("fre%", replacements.get(0));
-    }
-
-    /**
-     * Test whether LIKE clauses with Escapes are built correctly.
-     */
-    public void testBuildPsLikeWithEscape() throws TorqueException
-    {
-        WhereClauseExpression whereClauseExpression
-            = new WhereClauseExpression(
-                    "COL",
-                    SqlEnum.LIKE,
-                    "50\\%");
-        PreparedStatementPart result
-                = SqlBuilder.buildPsLike(whereClauseExpression, false, db);
-        assertEquals("COL=?", result.getSql().toString());
-        List<Object> replacements = result.getPreparedStatementReplacements();
-        assertEquals(1, replacements.size());
-        assertEquals("50%", replacements.get(0));
-    }
-
     /**
      * Test that unknown columns are treated case-insensitive if ignoreCase
      * is set.
@@ -219,7 +103,21 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
-    public void testMultipleOrderBy() throws Exception
+    public void testOrderByNullColumn() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        try
+        {
+            criteria.addAscendingOrderByColumn((Column) null);
+            fail("Exception expected");
+        }
+        catch (NullPointerException e)
+        {
+            assertEquals("column is null", e.getMessage());
+        }
+    }
+
+    public void testOrderByMultiple() throws Exception
     {
         Criteria criteria = new Criteria();
         criteria.addAscendingOrderByColumn("table.column1");
@@ -249,9 +147,52 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
-    public void testOrderByIgnoreCase()
+    public void testOrderByAscendingIgnoreCaseString() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addAscendingOrderByColumn(stringColumnMap, true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals(
+                "SELECT UPPER(TABLE.COLUMN1) FROM TABLE "
+                    + "ORDER BY UPPER(TABLE.COLUMN1) ASC",
+                query.toString());
+    }
+
+    public void testOrderByAscendingIgnoreCaseInteger() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addAscendingOrderByColumn(integerColumnMap, true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals(
+                "SELECT TABLE.COLUMN4 FROM TABLE "
+                    + "ORDER BY TABLE.COLUMN4 ASC",
+                query.toString());
+    }
+
+    public void testOrderByDescendingIgnoreCase() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addDescendingOrderByColumn(stringColumnMap, true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals(
+                "SELECT UPPER(TABLE.COLUMN1) FROM TABLE "
+                    + "ORDER BY UPPER(TABLE.COLUMN1) DESC",
+                query.toString());
+    }
+
+    public void testOrderByDescendingIgnoreCaseInteger() throws Exception
     {
-        // TODO implement
+        Criteria criteria = new Criteria();
+        criteria.addDescendingOrderByColumn(integerColumnMap, true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals(
+                "SELECT TABLE.COLUMN4 FROM TABLE "
+                    + "ORDER BY TABLE.COLUMN4 DESC",
+                query.toString());
     }
 
     public void testAlias() throws Exception
@@ -442,19 +383,77 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
-    public void testInnerJoin()
+    public void testInnerJoinImplicit()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table1.column");
+        criteria.addJoin("table1.column1", "table2.column2");
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals(
+                "SELECT table1.column FROM table1, table2"
+                    + " WHERE table1.column1=table2.column2",
+                query.toString());
+    }
+
+
+    public void testInnerJoinExplicit()
             throws Exception
     {
         Criteria criteria = new Criteria();
         criteria.addSelectColumn("table1.column1");
-        criteria.addJoin("table1.column", "table2.column");
+        criteria.addJoin(
+                "table1.column1",
+                "table2.column2",
+                Criteria.INNER_JOIN);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals(
-                "SELECT table1.column1 FROM table1, table2"
-                    + " WHERE table1.column=table2.column",
+                "SELECT table1.column1 FROM table1 INNER JOIN table2"
+                    + " ON table1.column1=table2.column2",
                 query.toString());
     }
 
+    public void testInnerJoinWithExcplicitExistingRightTable()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table1.column1");
+        criteria.addJoin("table2.column2", "table3.column3", Criteria.INNER_JOIN);
+        criteria.addJoin("table1.column1", "table2.column2", Criteria.INNER_JOIN);
+        Query query = SqlBuilder.buildQuery(criteria);
+        // second join condition must be changed in order to satisfy
+        // first join condition
+        assertEquals(
+                "SELECT table1.column1"
+                    + " FROM table2 INNER JOIN table3"
+                    + " ON table2.column2=table3.column3"
+                    + " INNER JOIN table1"
+                    + " ON table2.column2=table1.column1",
+                query.toString());
+    }
+
+    public void testInnerJoinExcplicitWithExistingRightAndLeftTable()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table1.column1");
+        criteria.addJoin("table2.column2", "table3.column3", Criteria.INNER_JOIN);
+        criteria.addJoin("table1.column1", "table4.column4", Criteria.INNER_JOIN);
+        criteria.addJoin("table1.column1", "table2.column2", Criteria.INNER_JOIN);
+        try
+        {
+            SqlBuilder.buildQuery(criteria);
+            fail("Exception expected");
+        }
+        catch (TorqueException e)
+        {
+            assertEquals("Unable to create a  INNER JOIN "
+                    + "because both table names table1 and table2 "
+                    + "are already in use. Try to create an(other) alias.",
+                e.getMessage());
+        }
+    }
+
     public void testLeftJoin()
             throws Exception
     {
@@ -469,6 +468,25 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
+    public void testLeftJoinWithExistingRightTable()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table1.column1");
+        criteria.addJoin("table2.column2", "table3.column3", Criteria.INNER_JOIN);
+        criteria.addJoin("table1.column1", "table2.column2", Criteria.LEFT_JOIN);
+        Query query = SqlBuilder.buildQuery(criteria);
+        // left join must be converted to right join to satisfy
+        // first join condition
+        assertEquals(
+                "SELECT table1.column1"
+                    + " FROM table2 INNER JOIN table3"
+                    + " ON table2.column2=table3.column3"
+                    + " RIGHT JOIN table1"
+                    + " ON table2.column2=table1.column1",
+                query.toString());
+    }
+
     public void testRightJoin()
             throws Exception
     {
@@ -483,7 +501,26 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
-    public void testInnerJoinWithAlias()
+    public void testRightJoinWithExistingRightTable()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table1.column1");
+        criteria.addJoin("table2.column2", "table3.column3", Criteria.INNER_JOIN);
+        criteria.addJoin("table1.column1", "table2.column2", Criteria.RIGHT_JOIN);
+        Query query = SqlBuilder.buildQuery(criteria);
+        // right join must be converted to left join to satisfy
+        // first join condition
+        assertEquals(
+                "SELECT table1.column1"
+                    + " FROM table2 INNER JOIN table3"
+                    + " ON table2.column2=table3.column3"
+                    + " LEFT JOIN table1"
+                    + " ON table2.column2=table1.column1",
+                query.toString());
+    }
+
+    public void testInnerJoinImplicitWithAlias()
             throws Exception
     {
         Criteria criteria = new Criteria();
@@ -497,7 +534,7 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
-    public void testInnerJoinWithAliasAndAsColumn()
+    public void testInnerJoinImplicitWithAliasAndAsColumn()
             throws Exception
     {
         Criteria criteria = new Criteria();
@@ -512,7 +549,7 @@ public class SqlBuilderTest extends Base
     }
 
 
-    public void testInnerJoinWithDefaultSchema()
+    public void testInnerJoinImplicitWithDefaultSchema()
             throws Exception
     {
         Criteria criteria = new Criteria();
@@ -529,7 +566,7 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
-    public void testInnerJoinWithAliasAndDefaultSchema()
+    public void testInnerJoinImplicitWithAliasAndDefaultSchema()
             throws Exception
     {
         Criteria criteria = new Criteria();
@@ -546,7 +583,7 @@ public class SqlBuilderTest extends Base
                 query.toString());
     }
 
-    public void testInnerJoinWithAliasAndSchema()
+    public void testInnerJoinImplicitWithAliasAndSchema()
             throws Exception
     {
         Criteria criteria = new Criteria();
@@ -559,4 +596,587 @@ public class SqlBuilderTest extends Base
                     + " WHERE alias.column=table2.column",
                 query.toString());
     }
+
+    public void testDistinct()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table1.column1");
+        criteria.setDistinct();
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals(
+                "SELECT DISTINCT table1.column1 FROM table1",
+                query.toString());
+    }
+
+    public void testGroupBy()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addGroupByColumn(stringColumnMap);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals(
+                "SELECT TABLE.COLUMN1 FROM TABLE GROUP BY TABLE.COLUMN1",
+                query.toString());
+    }
+
+    public void testLimitPostgresql() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(stringColumnMap);
+        criteria.setLimit(20);
+        criteria.setDbName(databasePostgresql.getName());
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT TABLE.COLUMN1 FROM TABLE "
+                + "LIMIT 20",
+            query.toString());
+    }
+
+    public void testOffsetPostgresql() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(stringColumnMap);
+        criteria.setOffset(10);
+        criteria.setDbName(databasePostgresql.getName());
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT TABLE.COLUMN1 FROM TABLE "
+                + "OFFSET 10",
+            query.toString());
+    }
+
+    public void testLimitOffsetPostgresql() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(stringColumnMap);
+        criteria.setLimit(20);
+        criteria.setOffset(10);
+        criteria.setDbName(databasePostgresql.getName());
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT TABLE.COLUMN1 FROM TABLE "
+                + "LIMIT 20 OFFSET 10",
+            query.toString());
+    }
+
+    public void testLimitMysql() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(stringColumnMap);
+        criteria.setLimit(20);
+        criteria.setDbName(databaseMysql.getName());
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT TABLE.COLUMN1 FROM TABLE "
+                + "LIMIT 20",
+            query.toString());
+    }
+
+    public void testOffsetMysql() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(stringColumnMap);
+        criteria.setOffset(10);
+        criteria.setDbName(databaseMysql.getName());
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT TABLE.COLUMN1 FROM TABLE "
+                + "LIMIT 18446744073709551615 OFFSET 10",
+            query.toString());
+    }
+
+    public void testLimitOffsetMysql() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(stringColumnMap);
+        criteria.setLimit(20);
+        criteria.setOffset(10);
+        criteria.setDbName(databaseMysql.getName());
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT TABLE.COLUMN1 FROM TABLE "
+                + "LIMIT 20 OFFSET 10",
+            query.toString());
+    }
+
+    public void testHaving() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addGroupByColumn(stringColumnMap);
+        criteria.addAsColumn("count", "count(*)");
+        criteria.addSelectColumn(stringColumnMap);
+        criteria.addHaving(
+                criteria.getNewCriterion("count", 10, Criteria.GREATER_EQUAL));
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT TABLE.COLUMN1, count(*) AS count FROM TABLE "
+                + "GROUP BY TABLE.COLUMN1 HAVING count>=10",
+            query.toString());
+    }
+
+    public void testSelectColumnWithoutTable()
+            throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("*");
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT * FROM ", query.toString());
+    }
+
+
+    public void testCriterionCustom() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("A", (Object) "A = functionOf(B)", Criteria.CUSTOM);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table WHERE A = functionOf(B)",
+                query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionCurrentDate() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", Criteria.CURRENT_DATE);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column=CURRENT_DATE",
+            query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionCurrentTime() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", Criteria.CURRENT_TIME);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column=CURRENT_TIME",
+            query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionObjectKey() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", new NumberKey(11));
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column=?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                new BigDecimal(11),
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionNullValue() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", null);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column IS NULL",
+            query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionNullValueNotEqual() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", (Object) null, Criteria.NOT_EQUAL);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column IS NOT NULL",
+            query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionNullValueAltNotEqual() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", (Object) null, Criteria.ALT_NOT_EQUAL);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column IS NOT NULL",
+            query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionIsNull() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", (Object) "value ignored", Criteria.ISNULL);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column IS NULL",
+            query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionIsNotNull() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column");
+        criteria.add("column", (Object) "value ignored", Criteria.ISNOTNULL);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table "
+                + "WHERE column IS NOT NULL",
+            query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionCriteria() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+
+        Criteria subquery = new Criteria();
+        subquery.add("table.column2", "value2");
+        subquery.addSelectColumn("table.column3");
+        criteria.add("table.column3", subquery);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column3=("
+                + "SELECT table.column3 FROM table "
+                + "WHERE table.column2=?)",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals("value2", query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionLike() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "*v%al_e2?", Criteria.LIKE);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 LIKE ?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "%v%al_e2_",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    /**
+     * Test whether LIKE clauses with Escapes are built correctly.
+     */
+    public void testCriterionLikeWithEscape() throws TorqueException
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add(
+                "table.column2",
+                (Object) "\\*v\\%al\\_e\\\\*2\\?\\",
+                Criteria.LIKE);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 LIKE ?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "*v\\%al\\_e\\\\%2?\\",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    /**
+     * Test whether LIKE clauses with Escapes are built correctly in Oracle.
+     * Oracle needs to have an ESCAPE clause
+     */
+    public void testCriterionLikeWithEscapeOracle() throws TorqueException
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add(
+                "table.column2",
+                (Object) "\\*v\\%al\\_e\\\\*2\\?\\",
+                Criteria.LIKE);
+        criteria.setDbName(databaseOracle.getName());
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 LIKE ? ESCAPE '\\'",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "*v\\%al\\_e\\\\%2?\\",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionLikeIgnoreCase() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "*v%al_e2?", Criteria.LIKE);
+        criteria.setIgnoreCase(true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 ILIKE ?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "%v%al_e2_",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionLikeIgnoreCaseNoWildcard() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "value\\\\2", Criteria.LIKE);
+        criteria.setIgnoreCase(true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE UPPER(table.column2)=UPPER(?)",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "value\\2",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionLikeInteger() throws TorqueException
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add(
+                "table.column2",
+                1,
+                Criteria.LIKE);
+
+        try
+        {
+            SqlBuilder.buildQuery(criteria);
+            fail("Exception expected");
+        }
+        catch (TorqueException e)
+        {
+            assertEquals("rValue must be a String for the operator  LIKE ",
+                    e.getMessage());
+        }
+    }
+
+    public void testCriterionNotLike() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "*val_e2?", Criteria.NOT_LIKE);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 NOT LIKE ?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "%val_e2_",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionNotLikeIgnoreCase() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "*v%al_e2?", Criteria.NOT_LIKE);
+        criteria.setIgnoreCase(true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 NOT ILIKE ?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "%v%al_e2_",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionNotLikeIgnoreCaseNoWildcard() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "value\\\\2", Criteria.NOT_LIKE);
+        criteria.setIgnoreCase(true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE UPPER(table.column2)<>UPPER(?)",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "value\\2",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionIlike() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "*val_e2?", Criteria.ILIKE);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 ILIKE ?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "%val_e2_",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionNotIlike() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add("table.column2", (Object) "*val_e2?", Criteria.NOT_ILIKE);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 NOT ILIKE ?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "%val_e2_",
+                query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testCriterionInArray() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add(
+                "table.column2",
+                new String[] {"a", "b", null},
+                Criteria.IN);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 IN (?,?,?)",
+            query.toString());
+        assertEquals(3, query.getPreparedStatementReplacements().size());
+        assertEquals("a", query.getPreparedStatementReplacements().get(0));
+        assertEquals("b", query.getPreparedStatementReplacements().get(1));
+        assertEquals(null, query.getPreparedStatementReplacements().get(2));
+    }
+
+    public void testCriterionInArrayIgnoreCase() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add(
+                "table.column2",
+                new String[] {"a", "b", null},
+                Criteria.IN);
+        criteria.setIgnoreCase(true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE UPPER(table.column2) IN (UPPER(?),UPPER(?),?)",
+            query.toString());
+        List<Object> replacements = query.getPreparedStatementReplacements();
+        assertEquals(3, replacements.size());
+        assertEquals("a", replacements.get(0));
+        assertEquals("b", replacements.get(1));
+        assertEquals(null, replacements.get(2));
+    }
+
+    public void testCriterionInList() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        List<Integer> inList = new ArrayList<Integer>();
+        inList.add(1);
+        inList.add(2);
+        inList.add(null);
+        criteria.add(
+                "table.column2",
+                inList,
+                Criteria.IN);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE table.column2 IN (?,?,?)",
+            query.toString());
+        assertEquals(3, query.getPreparedStatementReplacements().size());
+        assertEquals(1, query.getPreparedStatementReplacements().get(0));
+        assertEquals(2, query.getPreparedStatementReplacements().get(1));
+        assertEquals(null, query.getPreparedStatementReplacements().get(2));
+    }
+
+    public void testCriterionInListIgnoreCase() throws Exception
+        {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        List<String> inList = new ArrayList<String>();
+        inList.add("a");
+        inList.add("b");
+        inList.add(null);
+        criteria.add(
+                "table.column2",
+                inList,
+                Criteria.IN);
+        criteria.setIgnoreCase(true);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column1 FROM table "
+                + "WHERE UPPER(table.column2) IN (UPPER(?),UPPER(?),?)",
+            query.toString());
+        List<Object> replacements = query.getPreparedStatementReplacements();
+        assertEquals(3, replacements.size());
+        assertEquals("a", replacements.get(0));
+        assertEquals("b", replacements.get(1));
+        assertEquals(null, replacements.get(2));
+    }
+
+    public void testCriterionInLargeArray() throws TorqueException
+    {
+        int size = 10000;
+        String[] values = new String[size];
+        for (int i = 0; i < size; i++)
+        {
+            Array.set(values, i, String.valueOf(i));
+        }
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add(
+                "table.column2",
+                values,
+                Criteria.IN);
+        long start = System.currentTimeMillis();
+        Query query = SqlBuilder.buildQuery(criteria);
+        long end =  System.currentTimeMillis();
+        List<Object> replacements = query.getPreparedStatementReplacements();
+        assertEquals(size, replacements.size());
+        // time limit 50 ms
+        assertTrue(end - start < 50L);
+    }
+
+    public void testCriterionInString() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn("table.column1");
+        criteria.add(
+                "table.column2",
+                (Object) "illegal in value",
+                Criteria.IN);
+
+        try
+        {
+            SqlBuilder.buildQuery(criteria);
+            fail("Exception expected");
+        }
+        catch (IllegalArgumentException e)
+        {
+            assertEquals("Unknown rValue type java.lang.String. "
+                    + "rValue must be an instance of  Iterable or Array",
+            e.getMessage());
+        }
+    }
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/resources/Torque.properties Sun Nov 27 20:38:52 2011
@@ -17,10 +17,16 @@
 
 
 torque.database.default = postgresql
+
 torque.database.mysql.adapter=mysql
 torque.dsfactory.mysql.factory= org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+
 torque.database.postgresql.adapter=postgresql
 torque.dsfactory.postgresql.factory= org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+
+torque.database.oracle.adapter=oracle
+torque.dsfactory.oracle.factory= org.apache.torque.dsfactory.SharedPoolDataSourceFactory
+
 torque.idbroker.prefetch=false
 
 

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1206840&r1=1206839&r2=1206840&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Sun Nov 27 20:38:52 2011
@@ -2521,7 +2521,8 @@ public class DataTest extends BaseRuntim
     public void testLikeClauseEscaping() throws Exception
     {
         String[] authorNames
-                = {"abc", "bbc", "a_c", "a%c", "a\\c", "a\"c", "a'c"};
+                = {"abc", "bbc", "a_c", "a%c", "a\\c",
+                   "a\"c", "a'c", "a?c", "a*c" };
 
         Map<String, String> likeResults = new HashMap<String, String>();
 
@@ -2537,6 +2538,14 @@ public class DataTest extends BaseRuntim
         likeResults.put("a\\\\%", "a\\c");
         likeResults.put("%\\\\c", "a\\c");
 
+        likeResults.put("a\\*c", "a*c");
+        likeResults.put("a\\*%", "a*c");
+        likeResults.put("%\\*c", "a*c");
+
+        likeResults.put("a\\?c", "a?c");
+        likeResults.put("a\\?%", "a?c");
+        likeResults.put("%\\?c", "a?c");
+
         likeResults.put("a\"c", "a\"c");
         likeResults.put("a\"%", "a\"c");
         likeResults.put("%\"c", "a\"c");
@@ -2578,7 +2587,18 @@ public class DataTest extends BaseRuntim
                     AuthorPeer.NAME,
                     likeResult.getKey(),
                     Criteria.LIKE);
-            List<Author> authorList = AuthorPeer.doSelect(criteria);
+            List<Author> authorList;
+            try
+            {
+                authorList = AuthorPeer.doSelect(criteria);
+            }
+            catch (Exception e)
+            {
+                throw new Exception(
+                        "error rxecuting select using like content "
+                        + likeResult.getKey(),
+                    e);
+            }
             assertEquals(
                     "AuthorList should contain one author"
                         + " when querying for " + likeResult.getKey(),



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