db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1329656 [3/4] - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/criteria/ torque-runtime/src/main/java/org/apache/torque/map/ torque-runtime/src/main/java/org/apache/torque/sql/ torque-runtime/src/main/java/org/...
Date Tue, 24 Apr 2012 11:52:51 GMT
Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/LikeBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/LikeBuilder.java?rev=1329656&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/LikeBuilder.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/LikeBuilder.java Tue Apr 24 11:52:50 2012
@@ -0,0 +1,224 @@
+package org.apache.torque.sql.whereclausebuilder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.TorqueException;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.criteria.SqlEnum;
+import org.apache.torque.sql.PreparedStatementPart;
+import org.apache.torque.sql.WhereClauseExpression;
+
+/**
+ * Builds a PreparedStatementPart from a WhereClauseExpression containing
+ * a Like operator.
+ *
+ * @version $Id: $
+ */
+public class LikeBuilder extends AbstractWhereClausePsPartBuilder
+{
+    /** The backslash character*/
+    private static final char BACKSLASH = '\\';
+
+    /**
+     * Builds the PS part for a WhereClauseExpression with a LIKE operator.
+     * Multicharacter wildcards % and * may be used
+     * as well as single character wildcards, _ and ?.  These
+     * characters can be escaped with \.
+     *
+     * e.g. criteria = "fre%" -> columnName LIKE 'fre%'
+     *                        -> UPPER(columnName) LIKE UPPER('fre%')
+     *      criteria = "50\%" -> columnName = '50%'
+     *
+     * @param whereClausePart the part of the where clause to build.
+     *        Can be modified in this method.
+     * @param ignoreCase If true and columns represent Strings, the appropriate
+     *        function defined for the database will be used to ignore
+     *        differences in case.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return the rendered SQL for the WhereClauseExpression
+     */
+    public PreparedStatementPart buildPs(
+                WhereClauseExpression whereClausePart,
+                boolean ignoreCase,
+                DB db)
+            throws TorqueException
+    {
+        if (!(whereClausePart.getRValue() instanceof String))
+        {
+            throw new TorqueException(
+                "rValue must be a String for the operator "
+                    + whereClausePart.getOperator());
+        }
+        String value = (String) whereClausePart.getRValue();
+        // If selection criteria contains wildcards use LIKE otherwise
+        // use = (equals).  Wildcards can be escaped by prepending
+        // them with \ (backslash). However, if we switch from
+        // like to equals, we need to remove the escape characters.
+        // from the wildcards.
+        // So we need two passes: The first replaces * and ? by % and _,
+        // and checks whether we switch to equals,
+        // the second removes escapes if we have switched to equals.
+        int position = 0;
+        StringBuffer sb = new StringBuffer();
+        boolean replaceWithEquals = true;
+        while (position < value.length())
+        {
+            char checkWildcard = value.charAt(position);
+
+            switch (checkWildcard)
+            {
+            case BACKSLASH:
+                if (position + 1 >= value.length())
+                {
+                    // ignore backslashes at end
+                    break;
+                }
+                position++;
+                char escapedChar = value.charAt(position);
+                if (escapedChar != '*' && escapedChar != '?')
+                {
+                    sb.append(checkWildcard);
+                }
+                // code below copies escaped character into sb
+                checkWildcard = escapedChar;
+                break;
+            case '%':
+            case '_':
+                replaceWithEquals = false;
+                break;
+            case '*':
+                replaceWithEquals = false;
+                checkWildcard = '%';
+                break;
+            case '?':
+                replaceWithEquals = false;
+                checkWildcard = '_';
+                break;
+            default:
+                break;
+            }
+
+            sb.append(checkWildcard);
+            position++;
+        }
+        value = sb.toString();
+
+        PreparedStatementPart result;
+        if (ignoreCase)
+        {
+            if (db.useIlike() && !replaceWithEquals)
+            {
+                if (SqlEnum.LIKE.equals(whereClausePart.getOperator()))
+                {
+                    whereClausePart.setOperator(SqlEnum.ILIKE);
+                }
+                else if (SqlEnum.NOT_LIKE.equals(whereClausePart.getOperator()))
+                {
+                    whereClausePart.setOperator(SqlEnum.NOT_ILIKE);
+                }
+                result = objectOrColumnPsPartBuilder.buildPs(
+                        whereClausePart.getLValue(), false, db);
+            }
+            else
+            {
+                // no native case insensitive like is offered by the DB,
+                // or the LIKE was replaced with equals.
+                // need to ignore case manually.
+                result = objectOrColumnPsPartBuilder.buildPs(
+                        whereClausePart.getLValue(), true, db);
+            }
+        }
+        else
+        {
+            result = objectOrColumnPsPartBuilder.buildPs(
+                    whereClausePart.getLValue(), ignoreCase, db);
+        }
+
+        if (replaceWithEquals)
+        {
+            if (whereClausePart.getOperator().equals(SqlEnum.NOT_LIKE)
+                    || whereClausePart.getOperator().equals(SqlEnum.NOT_ILIKE))
+            {
+                result.getSql().append(SqlEnum.NOT_EQUAL);
+            }
+            else
+            {
+                result.getSql().append(SqlEnum.EQUAL);
+            }
+
+            // remove escape backslashes from String
+            position = 0;
+            sb = new StringBuffer();
+            while (position < value.length())
+            {
+                char checkWildcard = value.charAt(position);
+
+                if (checkWildcard == BACKSLASH
+                        && position + 1 < value.length())
+                {
+                    position++;
+                    // code below copies escaped character into sb
+                    checkWildcard = value.charAt(position);
+                }
+                sb.append(checkWildcard);
+                position++;
+            }
+            value = sb.toString();
+        }
+        else
+        {
+            result.getSql().append(whereClausePart.getOperator());
+        }
+
+        String rValueSql = "?";
+        // handle ignoreCase if necessary
+        if (ignoreCase && (!(db.useIlike()) || replaceWithEquals))
+        {
+            rValueSql = db.ignoreCase(rValueSql);
+        }
+        // handle escape clause if necessary
+        if (!replaceWithEquals && db.useEscapeClauseForLike())
+        {
+            rValueSql = rValueSql + SqlEnum.ESCAPE + "'\\'";
+        }
+
+        result.getPreparedStatementReplacements().add(value);
+        result.getSql().append(rValueSql);
+        return result;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isApplicable(
+            WhereClauseExpression whereClauseExpression,
+            DB db)
+    {
+        if (whereClauseExpression.getOperator().equals(SqlEnum.LIKE)
+            || whereClauseExpression.getOperator().equals(SqlEnum.NOT_LIKE)
+            || whereClauseExpression.getOperator().equals(SqlEnum.ILIKE)
+            || whereClauseExpression.getOperator().equals(SqlEnum.NOT_ILIKE))
+        {
+            return true;
+        }
+        return false;
+    }
+}

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java?rev=1329656&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/NullValueBuilder.java Tue Apr 24 11:52:50 2012
@@ -0,0 +1,119 @@
+package org.apache.torque.sql.whereclausebuilder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.TorqueException;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.criteria.SqlEnum;
+import org.apache.torque.sql.PreparedStatementPart;
+import org.apache.torque.sql.WhereClauseExpression;
+
+/**
+ * Builds a PreparedStatementPart from a WhereClauseExpression which
+ * rhs is null and which has one of the comparison opertator =, <>, or !=,
+ * or which operator is SqlEnum.ISNULL or SqlEnum.ISNOTNULL
+
+ *
+ * @version $Id: $
+ */
+public class NullValueBuilder extends AbstractWhereClausePsPartBuilder
+{
+    /**
+     * Builds a PreparedStatementPart from a WhereClauseExpression which
+     * rhs is null and which has one of the comparison opertator =, <>, or !=.
+     *
+     * @param whereClausePart the part of the where clause to build.
+     *        Can be modified in this method.
+     * @param ignoreCase If true and columns represent Strings, the appropriate
+     *        function defined for the database will be used to ignore
+     *        differences in case.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return the rendered SQL for the WhereClauseExpression
+     */
+    public PreparedStatementPart buildPs(
+                WhereClauseExpression whereClausePart,
+                boolean ignoreCase,
+                DB db)
+            throws TorqueException
+    {
+        PreparedStatementPart result;
+        if (whereClausePart.getOperator().equals(SqlEnum.ISNULL)
+            || whereClausePart.getOperator().equals(SqlEnum.ISNOTNULL))
+        {
+            result = objectOrColumnPsPartBuilder.buildPs(
+                    whereClausePart.getLValue(), ignoreCase, db);
+            result.getSql().append(whereClausePart.getOperator());
+            return result;
+        }
+
+        // now we know from isApplicable() that rValue is null
+        if (whereClausePart.getOperator().equals(SqlEnum.EQUAL))
+        {
+            result = objectOrColumnPsPartBuilder.buildPs(
+                    whereClausePart.getLValue(), ignoreCase, db);
+            result.getSql().append(SqlEnum.ISNULL);
+            return result;
+        }
+        if (whereClausePart.getOperator().equals(SqlEnum.NOT_EQUAL)
+            || whereClausePart.getOperator().equals(
+                    SqlEnum.ALT_NOT_EQUAL))
+        {
+            result = objectOrColumnPsPartBuilder.buildPs(
+                    whereClausePart.getLValue(), ignoreCase, db);
+            result.getSql().append(SqlEnum.ISNOTNULL);
+            return result;
+        }
+        throw new IllegalStateException("unknown operator "
+                + whereClausePart.getOperator());
+    }
+
+    /**
+     * Returns whether this WhereClausePsPartBuilder is applicable for
+     * a given WhereClauseExpression.
+     *
+     * @param whereClauseExpression the WhereClauseExpression in question.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return true if applicable, false otherwise.
+     */
+    public boolean isApplicable(
+            WhereClauseExpression whereClauseExpression,
+            DB db)
+    {
+        if (whereClauseExpression.getOperator().equals(SqlEnum.ISNULL)
+            || whereClauseExpression.getOperator().equals(SqlEnum.ISNOTNULL))
+        {
+            return true;
+        }
+        if (whereClauseExpression.getRValue() != null)
+        {
+            return false;
+        }
+        if (whereClauseExpression.getOperator().equals(SqlEnum.EQUAL)
+            || whereClauseExpression.getOperator().equals(SqlEnum.NOT_EQUAL)
+            || whereClauseExpression.getOperator().equals(
+                        SqlEnum.ALT_NOT_EQUAL))
+        {
+            return true;
+        }
+        return false;
+    }
+}

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/StandardBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/StandardBuilder.java?rev=1329656&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/StandardBuilder.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/StandardBuilder.java Tue Apr 24 11:52:50 2012
@@ -0,0 +1,77 @@
+package org.apache.torque.sql.whereclausebuilder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.TorqueException;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.sql.PreparedStatementPart;
+import org.apache.torque.sql.WhereClauseExpression;
+
+/**
+ * Builds a PreparedStatementPart from a WhereClauseExpression which
+ * RHS and LHS is a simple value.
+ *
+ * @version $Id: $
+ */
+public class StandardBuilder extends AbstractWhereClausePsPartBuilder
+{
+    /**
+     * Builds a PreparedStatementPart from a WhereClauseExpression which
+     * RHS and LHS is a simple value.
+     *
+     * @param whereClausePart the part of the where clause to build.
+     *        Can be modified in this method.
+     * @param ignoreCase If true and columns represent Strings, the appropriate
+     *        function defined for the database will be used to ignore
+     *        differences in case.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return the rendered SQL for the WhereClauseExpression
+     */
+    public PreparedStatementPart buildPs(
+                WhereClauseExpression whereClausePart,
+                boolean ignoreCase,
+                DB db)
+            throws TorqueException
+    {
+        PreparedStatementPart result = objectOrColumnPsPartBuilder.buildPs(
+                whereClausePart.getLValue(), ignoreCase, db);
+        result.getSql().append(whereClausePart.getOperator());
+        result.append(objectOrColumnPsPartBuilder.buildPs(
+                whereClausePart.getRValue(), ignoreCase, db));
+        return result;
+    }
+
+    /**
+     * Returns whether this WhereClausePsPartBuilder is applicable for
+     * a given WhereClauseExpression.
+     *
+     * @param whereClauseExpression the WhereClauseExpression in question.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return true if applicable, false otherwise.
+     */
+    public boolean isApplicable(
+            WhereClauseExpression whereClauseExpression,
+            DB db)
+    {
+        return true;
+    }
+}

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/VerbatimSqlConditionBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/VerbatimSqlConditionBuilder.java?rev=1329656&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/VerbatimSqlConditionBuilder.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/VerbatimSqlConditionBuilder.java Tue Apr 24 11:52:50 2012
@@ -0,0 +1,85 @@
+package org.apache.torque.sql.whereclausebuilder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Arrays;
+
+import org.apache.torque.TorqueException;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.sql.PreparedStatementPart;
+import org.apache.torque.sql.WhereClauseExpression;
+
+/**
+ * Builds a PreparedStatementPart from a WhereClauseExpression containing
+ * a verbatim SQL condition.
+ *
+ * @version $Id: $
+ */
+public class VerbatimSqlConditionBuilder implements WhereClausePsPartBuilder
+{
+    /**
+     * Builds the PS part for a WhereClauseExpression with a verbatim
+     * SQL condition.
+     *
+     * @param whereClausePart the part of the where clause to build.
+     *        Can be modified in this method.
+     * @param ignoreCase is ignored here.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return the rendered SQL for the WhereClauseExpression
+     */
+    public PreparedStatementPart buildPs(
+                WhereClauseExpression whereClausePart,
+                boolean ignoreCase,
+                DB db)
+            throws TorqueException
+    {
+        PreparedStatementPart result = new PreparedStatementPart();
+        result.getSql().append(whereClausePart.getSql());
+        Object[] replacements
+                = whereClausePart.getPreparedStatementReplacements();
+        if (replacements != null)
+        {
+            result.getPreparedStatementReplacements().addAll(
+                    Arrays.asList(replacements));
+        }
+        return result;
+    }
+
+    /**
+     * Returns whether this WhereClausePsPartBuilder is applicable for
+     * a given WhereClauseExpression.
+     *
+     * @param whereClauseExpression the WhereClauseExpression in question.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return true if applicable, false otherwise.
+     */
+    public boolean isApplicable(
+            WhereClauseExpression whereClauseExpression,
+            DB db)
+    {
+        if (whereClauseExpression.isVerbatimSqlCondition())
+        {
+            return true;
+        }
+        return false;
+    }
+}

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/WhereClausePsPartBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/WhereClausePsPartBuilder.java?rev=1329656&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/WhereClausePsPartBuilder.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/WhereClausePsPartBuilder.java Tue Apr 24 11:52:50 2012
@@ -0,0 +1,64 @@
+package org.apache.torque.sql.whereclausebuilder;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.torque.TorqueException;
+import org.apache.torque.adapter.DB;
+import org.apache.torque.sql.PreparedStatementPart;
+import org.apache.torque.sql.WhereClauseExpression;
+
+/**
+ * Builds a PreparedStatementPart from a WhereClauseExpression.
+ *
+ * @version $Id: $
+ */
+public interface WhereClausePsPartBuilder
+{
+    /**
+     * Builds a PreparedStatementPart from a WhereClauseExpression.
+     *
+     * @param whereClausePart the part of the where clause to build.
+     *        Can be modified in this method.
+     * @param ignoreCase If true and columns represent Strings, the appropriate
+     *        function defined for the database will be used to ignore
+     *        differences in case.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return the PreparedStatementPart for the WhereClauseExpression.
+     *
+     * @throws TorqueException when rendering fails.
+     */
+    PreparedStatementPart buildPs(
+            WhereClauseExpression whereClauseExpression,
+            boolean ignoreCase,
+            DB db)
+        throws TorqueException;
+
+    /**
+     * Returns whether this WhereClausePsPartBuilder is applicable for
+     * a given WhereClauseExpression.
+     *
+     * @param whereClauseExpression the WhereClauseExpression in question.
+     * @param db The database for which the SQL should be created, not null.
+     *
+     * @return true if applicable, false otherwise.
+     */
+    boolean isApplicable(WhereClauseExpression whereClauseExpression, DB db);
+}

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/package.html?rev=1329656&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/package.html (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/whereclausebuilder/package.html Tue Apr 24 11:52:50 2012
@@ -0,0 +1,26 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<html>
+  <head>
+  </head>
+  <body>
+    This package contains classes which can build
+    PreparedStatementParts from a WhereClauseExpression.
+  </body>
+</html>

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java?rev=1329656&r1=1329655&r2=1329656&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java Tue Apr 24 11:52:50 2012
@@ -41,6 +41,7 @@ import org.apache.torque.Torque;
 import org.apache.torque.TorqueException;
 import org.apache.torque.adapter.DB;
 import org.apache.torque.adapter.IDMethod;
+import org.apache.torque.criteria.FromElement;
 import org.apache.torque.map.ColumnMap;
 import org.apache.torque.map.DatabaseMap;
 import org.apache.torque.map.MapHelper;
@@ -316,7 +317,7 @@ public class BasePeerImpl implements Ser
             throw new TorqueException("No conditions found in Criteria");
         }
         TableMap tableMap = MapHelper.getTableMap(
-                criterion.getColumn(), criteria, null);
+                criterion.getLValue(), criteria, null);
         if (tableMap == null)
         {
             throw new TorqueException("Unqualified column name in criteria"
@@ -450,7 +451,7 @@ public class BasePeerImpl implements Ser
         }
 
         boolean ownTableAdded = false;
-        for (Query.FromElement fromElement : query.getFromClause())
+        for (FromElement fromElement : query.getFromClause())
         {
             // Table names are case insensitive in known databases
             // so use case-insensitive compare
@@ -463,7 +464,7 @@ public class BasePeerImpl implements Ser
         if (!ownTableAdded)
         {
             query.getFromClause().add(
-                    new Query.FromElement(fullTableName, null, null));
+                    new FromElement(fullTableName, null, null));
         }
         String sql = query.toString();
 
@@ -546,7 +547,7 @@ public class BasePeerImpl implements Ser
                     criteria.getDbName());
         }
         boolean ownTableAdded = false;
-        for (Query.FromElement fromElement : query.getFromClause())
+        for (FromElement fromElement : query.getFromClause())
         {
             // Table names are case insensitive in known databases
             // so use case-insensitive compare
@@ -559,7 +560,7 @@ public class BasePeerImpl implements Ser
         if (!ownTableAdded)
         {
             query.getFromClause().add(
-                    new Query.FromElement(fullTableName, null, null));
+                    new FromElement(fullTableName, null, null));
         }
         String sql = query.toString();
 
@@ -1160,7 +1161,7 @@ public class BasePeerImpl implements Ser
                     defaultTableMap.getName(),
                     criteria.getDbName());
             query.getFromClause().add(
-                    new Query.FromElement(tableName, null, null));
+                    new FromElement(tableName, null, null));
         }
 
         PreparedStatement statement = null;
@@ -1312,7 +1313,7 @@ public class BasePeerImpl implements Ser
                     defaultTableMap.getName(),
                     criteria.getDbName());
             query.getFromClause().add(
-                    new Query.FromElement(tableName, null, null));
+                    new FromElement(tableName, null, null));
         }
 
         PreparedStatement statement = null;
@@ -1655,7 +1656,7 @@ public class BasePeerImpl implements Ser
                 updateValues.getTable().getName(),
                 criteria.getDbName());
         query.getFromClause().add(
-                new Query.FromElement(fullTableName, null, null));
+                new FromElement(fullTableName, null, null));
 
         List<JdbcTypedValue> replacementObjects
                 = new ArrayList<JdbcTypedValue>();
@@ -1753,7 +1754,7 @@ public class BasePeerImpl implements Ser
                 updateValues.getTable().getName(),
                 criteria.getDbName());
         query.getFromClause().add(
-                new Query.FromElement(fullTableName, null, null));
+                new FromElement(fullTableName, null, null));
 
         List<JdbcTypedValue> replacementObjects
                 = new ArrayList<JdbcTypedValue>();
@@ -2114,9 +2115,9 @@ public class BasePeerImpl implements Ser
             return;
         }
 
-        Column column = criterion.getColumn();
+        Object possibleColumn = criterion.getLValue();
         TableMap tableMap = MapHelper.getTableMap(
-                column,
+                possibleColumn,
                 criteria,
                 defaultTableMap);
         // if no description of table available, do not modify anything
@@ -2124,7 +2125,7 @@ public class BasePeerImpl implements Ser
         {
             return;
         }
-        String columnName = column.getColumnName();
+        String columnName = ((Column) possibleColumn).getColumnName();
         ColumnMap columnMap = tableMap.getColumn(columnName);
         if (columnMap != null)
         {
@@ -2193,11 +2194,20 @@ public class BasePeerImpl implements Ser
             Object trueValue,
             Object falseValue)
     {
-        Object criterionValue = criterion.getValue();
-        if (criterionValue instanceof Boolean)
+        Object rValue = criterion.getRValue();
+        if (rValue instanceof Boolean)
+        {
+            Boolean booleanValue = (Boolean) rValue;
+            criterion.setRValue(
+                    Boolean.TRUE.equals(booleanValue)
+                            ? trueValue
+                            : falseValue);
+        }
+        Object lValue = criterion.getLValue();
+        if (lValue instanceof Boolean)
         {
-            Boolean booleanValue = (Boolean) criterionValue;
-            criterion.setValue(
+            Boolean booleanValue = (Boolean) lValue;
+            criterion.setLValue(
                     Boolean.TRUE.equals(booleanValue)
                             ? trueValue
                             : falseValue);

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java?rev=1329656&r1=1329655&r2=1329656&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/criteria/CriteriaTest.java Tue Apr 24 11:52:50 2012
@@ -105,8 +105,8 @@ public class CriteriaTest extends BaseTe
         assertFalse(c.getTopLevelCriterion().isComposite());
 
         // Verify that what we get out is what we put in
-        assertEquals(column, c.getTopLevelCriterion().getColumn());
-        assertEquals(value, c.getTopLevelCriterion().getValue());
+        assertEquals(column, c.getTopLevelCriterion().getLValue());
+        assertEquals(value, c.getTopLevelCriterion().getRValue());
         assertEquals(Criteria.EQUAL, c.getTopLevelCriterion().getComparison());
     }
 
@@ -134,37 +134,37 @@ public class CriteriaTest extends BaseTe
         // Verify that what we get out is what we put in
         assertEquals(
                 column1,
-                c.getTopLevelCriterion().getParts().get(0).getColumn());
+                c.getTopLevelCriterion().getParts().get(0).getLValue());
         assertEquals(
                 value1a,
-                c.getTopLevelCriterion().getParts().get(0).getValue());
+                c.getTopLevelCriterion().getParts().get(0).getRValue());
         assertEquals(
                 Criteria.EQUAL,
                 c.getTopLevelCriterion().getParts().get(0).getComparison());
         assertEquals(
                 column1,
-                c.getTopLevelCriterion().getParts().get(1).getColumn());
+                c.getTopLevelCriterion().getParts().get(1).getLValue());
         assertEquals(
                 value1b,
-                c.getTopLevelCriterion().getParts().get(1).getValue());
+                c.getTopLevelCriterion().getParts().get(1).getRValue());
         assertEquals(
                 Criteria.EQUAL,
                 c.getTopLevelCriterion().getParts().get(1).getComparison());
         assertEquals(
                 column2,
-                c.getTopLevelCriterion().getParts().get(2).getColumn());
+                c.getTopLevelCriterion().getParts().get(2).getLValue());
         assertEquals(
                 value2a,
-                c.getTopLevelCriterion().getParts().get(2).getValue());
+                c.getTopLevelCriterion().getParts().get(2).getRValue());
         assertEquals(
                 Criteria.EQUAL,
                 c.getTopLevelCriterion().getParts().get(2).getComparison());
         assertEquals(
                 column2,
-                c.getTopLevelCriterion().getParts().get(3).getColumn());
+                c.getTopLevelCriterion().getParts().get(3).getLValue());
         assertEquals(
                 value2b,
-                c.getTopLevelCriterion().getParts().get(3).getValue());
+                c.getTopLevelCriterion().getParts().get(3).getRValue());
         assertEquals(
                 Criteria.EQUAL,
                 c.getTopLevelCriterion().getParts().get(3).getComparison());
@@ -619,7 +619,7 @@ public class CriteriaTest extends BaseTe
         // Some direct Criterion checks
         Criterion cn = c.getTopLevelCriterion();
         cn.setIgnoreCase(true);
-        assertEquals("author%", cn.getValue());
+        assertEquals("author%", cn.getRValue());
         assertEquals(Criteria.LIKE, cn.getComparison());
         Criterion cnDirectClone = (Criterion) SerializationUtils.clone(cn);
         assertEquals(cn, cnDirectClone);
@@ -683,7 +683,7 @@ public class CriteriaTest extends BaseTe
 
         // Some Criterion checks
         Criterion cnClone = cClone.getTopLevelCriterion();
-        assertEquals("author%", cnClone.getValue());
+        assertEquals("author%", cnClone.getRValue());
         assertEquals(Criteria.LIKE, cnClone.getComparison());
         assertEquals(cn.isIgnoreCase(), cnClone.isIgnoreCase());
 
@@ -776,7 +776,7 @@ public class CriteriaTest extends BaseTe
 
         // Some Criterion checks
         Criterion cnClone = cClone.getTopLevelCriterion();
-        assertEquals("author%", cnClone.getValue());
+        assertEquals("author%", cnClone.getRValue());
         assertEquals(Criteria.LIKE, cnClone.getComparison());
         assertEquals(c.getTopLevelCriterion().isIgnoreCase(), cnClone.isIgnoreCase());
 

Modified: db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/QueryTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/QueryTest.java?rev=1329656&r1=1329655&r2=1329656&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/QueryTest.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/test/java/org/apache/torque/sql/QueryTest.java Tue Apr 24 11:52:50 2012
@@ -20,6 +20,7 @@ package org.apache.torque.sql;
  */
 
 import org.apache.torque.BaseTestCase;
+import org.apache.torque.criteria.FromElement;
 import org.apache.torque.util.UniqueList;
 
 /**
@@ -38,7 +39,7 @@ public class QueryTest extends BaseTestC
     {
         Query query = new Query();
 
-        UniqueList columns = query.getSelectClause();
+        UniqueList<String> columns = query.getSelectClause();
         columns.add("tableA.column1");
         columns.add("tableA.column2");
         columns.add("tableB.column1");
@@ -58,15 +59,15 @@ public class QueryTest extends BaseTestC
                 + " AND tableA.B = 1234";
         Query query = new Query();
 
-        UniqueList columns = query.getSelectClause();
+        UniqueList<String> columns = query.getSelectClause();
         columns.add("tableA.column1");
         columns.add("tableA.column2");
         columns.add("tableB.column1");
 
-        UniqueList<Query.FromElement> tables = query.getFromClause();
+        UniqueList<FromElement> tables = query.getFromClause();
         tables.clear();
-        tables.add(new Query.FromElement("tableA", null, null));
-        tables.add(new Query.FromElement("tableB", null, null));
+        tables.add(new FromElement("tableA", null, null));
+        tables.add(new FromElement("tableB", null, null));
 
         UniqueList<String> where = query.getWhereClause();
         where.clear();

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=1329656&r1=1329655&r2=1329656&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 Tue Apr 24 11:52:50 2012
@@ -31,6 +31,7 @@ import org.apache.torque.Database;
 import org.apache.torque.TorqueException;
 import org.apache.torque.criteria.Criteria;
 import org.apache.torque.criteria.Criterion;
+import org.apache.torque.criteria.FromElement;
 import org.apache.torque.om.NumberKey;
 
 /**
@@ -78,6 +79,41 @@ public class SqlBuilderTest extends Base
     }
 
     /**
+     * Test where condition with several ORs compairing against Strings.
+     */
+    public void testOrString() throws Exception
+    {
+        final Column column1 = new ColumnImpl("myTable", "myColumn1");
+        final Column column2 = new ColumnImpl("myTable", "myColumn2");
+        final String value1a = "1a";
+        final String value1b = "1b";
+        final String value2a = "2a";
+        final String value2b = "2b";
+        Criteria c = new Criteria().where(column1, value1a)
+            .or(column1, value1b)
+            .or(column2, value2a)
+            .or(column2, value2b);
+
+        Query query = SqlBuilder.buildQuery(c);
+
+        assertEquals(
+                "SELECT  FROM myTable "
+                   + "WHERE (myTable.myColumn1=? "
+                   + "OR myTable.myColumn1=? "
+                   + "OR myTable.myColumn2=? "
+                   + "OR myTable.myColumn2=?)",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add(value1a);
+        expectedReplacements.add(value1b);
+        expectedReplacements.add(value2a);
+        expectedReplacements.add(value2b);
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
      * Test where condition with several ANDs compairing against Strings.
      */
     public void testAndCriterions() throws Exception
@@ -111,6 +147,265 @@ public class SqlBuilderTest extends Base
     }
 
     /**
+     * Test where condition with several ORs compairing against Strings.
+     */
+    public void testOrCriterions() throws Exception
+    {
+        final Column column1 = new ColumnImpl("myTable", "myColumn1");
+        final Column column2 = new ColumnImpl("myTable", "myColumn2");
+        final String value1a = "1a";
+        final String value1b = "1b";
+        final String value2a = "2a";
+        Criterion criterion1 = new Criterion(column1, value1a);
+        Criterion criterion2 = new Criterion(column1, value1b);
+        Criterion criterion3 = new Criterion(column2, value2a);
+        criterion1.or(criterion2).or(criterion3);
+        Criteria c = new Criteria().where(criterion1);
+
+        Query query = SqlBuilder.buildQuery(c);
+
+        assertEquals(
+                "SELECT  FROM myTable "
+                   + "WHERE (myTable.myColumn1=? "
+                   + "OR myTable.myColumn1=? "
+                   + "OR myTable.myColumn2=?)",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add(value1a);
+        expectedReplacements.add(value1b);
+        expectedReplacements.add(value2a);
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the andVerbatimSql method with null replacements.
+     */
+    public void testAndVerbatimSqlReplacementNull() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .where(new ColumnImpl("table1.a"), "a")
+            .andVerbatimSql(
+                "foo(table1.x) = bar(table2.y)",
+                null);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM table1 "
+                   + "WHERE (table1.a=? "
+                   + "AND foo(table1.x) = bar(table2.y))",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add("a");
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the andVerbatimSql method with replacements.
+     */
+    public void testAndVerbatimSqlWithReplacements() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .where(new ColumnImpl("table1.a"), "a")
+            .andVerbatimSql(
+                "foo(table1.x, ?) = bar(table2.y, ?)",
+                new Object[] {"y", "z"});
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM table1 "
+                   + "WHERE (table1.a=? "
+                   + "AND foo(table1.x, ?) = bar(table2.y, ?))",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add("a");
+        expectedReplacements.add("y");
+        expectedReplacements.add("z");
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the andVerbatimSql method with from Columns.
+     */
+    public void testAndVerbatimSqlWithFromColumns() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .where(new ColumnImpl("table1.a"), "a")
+            .andVerbatimSql(
+                "foo(table1.x) = bar(table2.y)",
+                new Object[] {},
+                new ColumnImpl("table1.x"),
+                new ColumnImpl("table2.y"));
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM table1, table2 "
+                   + "WHERE (table1.a=? "
+                   + "AND foo(table1.x) = bar(table2.y))",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add("a");
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the orVerbatimSql method with null replacements.
+     */
+    public void testOrVerbatimSqlReplacementNull() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .where(new ColumnImpl("table1.a"), "a")
+            .orVerbatimSql(
+                "foo(table1.x) = bar(table2.y)",
+                null);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM table1 "
+                   + "WHERE (table1.a=? "
+                   + "OR foo(table1.x) = bar(table2.y))",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add("a");
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the orVerbatimSql method with replacements.
+     */
+    public void testOrVerbatimSqlWithReplacements() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .where(new ColumnImpl("table1.a"), "a")
+            .orVerbatimSql(
+                "foo(table1.x, ?) = bar(table2.y, ?)",
+                new Object[] {"y", "z"});
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM table1 "
+                   + "WHERE (table1.a=? "
+                   + "OR foo(table1.x, ?) = bar(table2.y, ?))",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add("a");
+        expectedReplacements.add("y");
+        expectedReplacements.add("z");
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the orVerbatimSql method with from Columns.
+     */
+    public void testOrVerbatimSqlWithFromColumns() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .where(new ColumnImpl("table1.a"), "a")
+            .orVerbatimSql(
+                "foo(table1.x) = bar(table2.y)",
+                new Object[] {},
+                new ColumnImpl("table1.x"),
+                new ColumnImpl("table2.y"));
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM table1, table2 "
+                   + "WHERE (table1.a=? "
+                   + "OR foo(table1.x) = bar(table2.y))",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add("a");
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the whereVerbatimSql method with null replacements.
+     */
+    public void testWhereVerbatimSqlReplacementNull() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .whereVerbatimSql(
+                "foo(table1.x) = bar(table2.y)",
+                null);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM  "
+                   + "WHERE foo(table1.x) = bar(table2.y)",
+                query.toString());
+        assertEquals(
+                new ArrayList<String>(),
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the whereVerbatimSql method with replacements.
+     */
+    public void testWhereVerbatimSqlWithReplacements() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .whereVerbatimSql(
+                "foo(table1.x, ?) = bar(table2.y, ?)",
+                new Object[] {"y", "z"});
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM  "
+                   + "WHERE foo(table1.x, ?) = bar(table2.y, ?)",
+                query.toString());
+        List<String> expectedReplacements = new ArrayList<String>();
+        expectedReplacements.add("y");
+        expectedReplacements.add("z");
+        assertEquals(
+                expectedReplacements,
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Test the whereVerbatimSql method with from Columns.
+     */
+    public void testWhereVerbatimSqlWithFromColumns() throws Exception
+    {
+        Criteria criteria = new Criteria()
+            .whereVerbatimSql(
+                "foo(table1.x) = bar(table2.y)",
+                new Object[] {},
+                new ColumnImpl("table1.x"),
+                new ColumnImpl("table2.y"));
+
+        Query query = SqlBuilder.buildQuery(criteria);
+
+        assertEquals(
+                "SELECT  FROM table1, table2 "
+                   + "WHERE foo(table1.x) = bar(table2.y)",
+                query.toString());
+        assertEquals(
+                new ArrayList<String>(),
+                query.getPreparedStatementReplacements());
+    }
+
+    /**
      * Test that unknown columns are treated case-insensitive if ignoreCase
      * is set.
      */
@@ -233,7 +528,7 @@ public class SqlBuilderTest extends Base
     {
         Criteria criteria = new Criteria();
         criteria.addAsColumn("asColumn", stringColumnMap);
-        criteria.addAscendingOrderByColumn("asColumn");
+        criteria.addAscendingOrderByColumn(new ColumnImpl("asColumn"));
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals(
                 "SELECT TABLE.COLUMN1 AS asColumn "
@@ -246,7 +541,7 @@ public class SqlBuilderTest extends Base
     {
         Criteria criteria = new Criteria();
         criteria.addAsColumn("asColumn", stringColumnMap);
-        criteria.addAscendingOrderByColumn("asColumn", true);
+        criteria.addAscendingOrderByColumn(new ColumnImpl("asColumn"), true);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals(
                 "SELECT TABLE.COLUMN1 AS asColumn, UPPER(asColumn) "
@@ -262,7 +557,7 @@ public class SqlBuilderTest extends Base
         criteria.addAsColumn(
                 "asColumn",
                 new ColumnImpl("alias", stringColumnMap.getColumnName()));
-        criteria.addAscendingOrderByColumn("asColumn", true);
+        criteria.addAscendingOrderByColumn(new ColumnImpl("asColumn"), true);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals(
                 "SELECT alias.COLUMN1 AS asColumn, UPPER(asColumn) "
@@ -924,7 +1219,7 @@ public class SqlBuilderTest extends Base
     {
         Criteria criteria = new Criteria();
         criteria.addGroupByColumn(stringColumnMap);
-        criteria.addAsColumn("count", "count(*)");
+        criteria.addAsColumn("count", new ColumnImpl("count(*)"));
         criteria.addSelectColumn(stringColumnMap);
         criteria.addHaving(
                 new Criterion("count", 10, Criteria.GREATER_EQUAL));
@@ -938,16 +1233,16 @@ public class SqlBuilderTest extends Base
             throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("*");
+        criteria.addSelectColumn(new ColumnImpl("*"));
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT * FROM ", query.toString());
     }
 
 
-    public void testCriterionCustom() throws Exception
+    public void testCustom() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
         criteria.where("A", "A = functionOf(B)", Criteria.CUSTOM);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table WHERE A = functionOf(B)",
@@ -955,11 +1250,56 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionCurrentDate() throws Exception
+    public void testCriterionCustom() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        Criterion criterion
+                = new Criterion("A", "A = functionOf(B)", Criteria.CUSTOM);
+        criteria.where(criterion);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table WHERE A = functionOf(B)",
+                query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testCriterionCustomNoString() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        Criterion criterion
+                = new Criterion("A", 3, Criteria.CUSTOM);
+        criteria.where(criterion);
+        try
+        {
+            SqlBuilder.buildQuery(criteria);
+            fail("Exception expected");
+        }
+        catch (TorqueException e)
+        {
+            assertEquals(
+                    "rValue must be a String for the operator CUSTOM",
+                    e.getMessage());
+        }
+    }
+    public void testLvalueIsObject() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", Criteria.CURRENT_DATE);
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(1, 2);
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table WHERE ?=?",
+                query.toString());
+        assertEquals(2, query.getPreparedStatementReplacements().size());
+        assertEquals(1, query.getPreparedStatementReplacements().get(0));
+        assertEquals(2, query.getPreparedStatementReplacements().get(1));
+    }
+
+    public void testCurrentDate() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(new ColumnImpl("column"), Criteria.CURRENT_DATE);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column=CURRENT_DATE",
@@ -967,11 +1307,11 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionCurrentTime() throws Exception
+    public void testCurrentTime() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", Criteria.CURRENT_TIME);
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(new ColumnImpl("column"), Criteria.CURRENT_TIME);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column=CURRENT_TIME",
@@ -979,11 +1319,11 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionObjectKey() throws Exception
+    public void testObjectKey() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", new NumberKey(11));
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(new ColumnImpl("column"), new NumberKey(11));
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column=?",
@@ -994,11 +1334,11 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionNullValue() throws Exception
+    public void testNullValue() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", null);
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(new ColumnImpl("column"), null);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column IS NULL",
@@ -1006,11 +1346,14 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionNullValueNotEqual() throws Exception
+    public void testNullValueNotEqual() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", (Object) null, Criteria.NOT_EQUAL);
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(
+                new ColumnImpl("column"),
+                (Object) null,
+                Criteria.NOT_EQUAL);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column IS NOT NULL",
@@ -1018,11 +1361,14 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionNullValueAltNotEqual() throws Exception
+    public void testNullValueAltNotEqual() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", (Object) null, Criteria.ALT_NOT_EQUAL);
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(
+                new ColumnImpl("column"),
+                (Object) null,
+                Criteria.ALT_NOT_EQUAL);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column IS NOT NULL",
@@ -1030,11 +1376,14 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionIsNull() throws Exception
+    public void testIsNull() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", "value ignored", Criteria.ISNULL);
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(
+                new ColumnImpl("column"),
+                "value ignored",
+                Criteria.ISNULL);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column IS NULL",
@@ -1042,11 +1391,14 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionIsNotNull() throws Exception
+    public void testIsNotNull() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column");
-        criteria.where("column", "value ignored", Criteria.ISNOTNULL);
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where(
+                new ColumnImpl("column"),
+                "value ignored",
+                Criteria.ISNOTNULL);
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column FROM table "
                 + "WHERE column IS NOT NULL",
@@ -1054,15 +1406,15 @@ public class SqlBuilderTest extends Base
         assertEquals(0, query.getPreparedStatementReplacements().size());
     }
 
-    public void testCriterionCriteria() throws Exception
+    public void testSubselect() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
 
-        Criteria subquery = new Criteria();
-        subquery.where("table.column2", "value2");
-        subquery.addSelectColumn("table.column3");
-        criteria.where("table.column3", subquery);
+        Criteria subselect = new Criteria();
+        subselect.where(new ColumnImpl("table.column2"), "value2");
+        subselect.addSelectColumn(new ColumnImpl("table.column3"));
+        criteria.where(new ColumnImpl("table.column3"), subselect);
 
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column1 FROM table "
@@ -1074,11 +1426,14 @@ public class SqlBuilderTest extends Base
         assertEquals("value2", query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionLike() throws Exception
+    public void testLike() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "*v%al_e2?", Criteria.LIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "*v%al_e2?",
+                Criteria.LIKE);
 
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column1 FROM table "
@@ -1093,12 +1448,12 @@ public class SqlBuilderTest extends Base
     /**
      * Test whether LIKE clauses with Escapes are built correctly.
      */
-    public void testCriterionLikeWithEscape() throws TorqueException
+    public void testLikeWithEscape() throws TorqueException
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         criteria.where(
-                "table.column2",
+                new ColumnImpl("table.column2"),
                 "\\*v\\%al\\_e\\\\*2\\?\\",
                 Criteria.LIKE);
 
@@ -1116,12 +1471,12 @@ public class SqlBuilderTest extends Base
      * Test whether LIKE clauses with Escapes are built correctly in Oracle.
      * Oracle needs to have an ESCAPE clause
      */
-    public void testCriterionLikeWithEscapeOracle() throws TorqueException
+    public void testLikeWithEscapeOracle() throws TorqueException
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         criteria.where(
-                "table.column2",
+                new ColumnImpl("table.column2"),
                 "\\*v\\%al\\_e\\\\*2\\?\\",
                 Criteria.LIKE);
         criteria.setDbName(databaseOracle.getName());
@@ -1136,11 +1491,14 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionLikeIgnoreCase() throws Exception
+    public void testLikeIgnoreCase() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "*v%al_e2?", Criteria.LIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "*v%al_e2?",
+                Criteria.LIKE);
         criteria.setIgnoreCase(true);
 
         Query query = SqlBuilder.buildQuery(criteria);
@@ -1153,11 +1511,14 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionLikeIgnoreCaseNoWildcard() throws Exception
+    public void testLikeIgnoreCaseNoWildcard() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "value\\\\2", Criteria.LIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "value\\\\2",
+                Criteria.LIKE);
         criteria.setIgnoreCase(true);
 
         Query query = SqlBuilder.buildQuery(criteria);
@@ -1170,11 +1531,11 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionLikeInteger() throws TorqueException
+    public void testLikeInteger() throws TorqueException
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", 1, Criteria.LIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(new ColumnImpl("table.column2"), 1, Criteria.LIKE);
 
         try
         {
@@ -1188,11 +1549,14 @@ public class SqlBuilderTest extends Base
         }
     }
 
-    public void testCriterionNotLike() throws Exception
+    public void testNotLike() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "*val_e2?", Criteria.NOT_LIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "*val_e2?",
+                Criteria.NOT_LIKE);
 
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column1 FROM table "
@@ -1204,11 +1568,14 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionNotLikeIgnoreCase() throws Exception
+    public void testNotLikeIgnoreCase() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "*v%al_e2?", Criteria.NOT_LIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "*v%al_e2?",
+                Criteria.NOT_LIKE);
         criteria.setIgnoreCase(true);
 
         Query query = SqlBuilder.buildQuery(criteria);
@@ -1221,11 +1588,14 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionNotLikeIgnoreCaseNoWildcard() throws Exception
+    public void testNotLikeIgnoreCaseNoWildcard() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "value\\\\2", Criteria.NOT_LIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "value\\\\2",
+                Criteria.NOT_LIKE);
         criteria.setIgnoreCase(true);
 
         Query query = SqlBuilder.buildQuery(criteria);
@@ -1238,11 +1608,14 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionIlike() throws Exception
+    public void testIlike() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "*val_e2?", Criteria.ILIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "*val_e2?",
+                Criteria.ILIKE);
 
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column1 FROM table "
@@ -1254,11 +1627,14 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionNotIlike() throws Exception
+    public void testNotIlike() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.where("table.column2", "*val_e2?", Criteria.NOT_ILIKE);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.where(
+                new ColumnImpl("table.column2"),
+                "*val_e2?",
+                Criteria.NOT_ILIKE);
 
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column1 FROM table "
@@ -1270,12 +1646,60 @@ public class SqlBuilderTest extends Base
                 query.getPreparedStatementReplacements().get(0));
     }
 
-    public void testCriterionInArray() throws Exception
+    public void testLvalueString() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        criteria.where("X", "Y");
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table WHERE ?=?",
+                query.toString());
+        assertEquals(2, query.getPreparedStatementReplacements().size());
+        assertEquals(
+                "X",
+                query.getPreparedStatementReplacements().get(0));
+        assertEquals(
+                "Y",
+                query.getPreparedStatementReplacements().get(1));
+    }
+
+    public void testLvalueNull() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        try
+        {
+          criteria.where(null, new ColumnImpl("table.column"));
+          fail("Exception expected");
+        }
+        catch (IllegalArgumentException e)
+        {
+            assertEquals("Either the values(lValue, comparison) or "
+                    + "sql must be not null",
+                    e.getMessage());
+        }
+    }
+
+    public void testLvalueCriteria() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column"));
+        Criteria subselect = new Criteria();
+        subselect.addSelectColumn(new ColumnImpl("table2.column2"));
+        criteria.where(subselect, new ColumnImpl("table.column"));
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table.column FROM table WHERE "
+                + "(SELECT table2.column2 FROM table2)=table.column",
+                query.toString());
+        assertEquals(0, query.getPreparedStatementReplacements().size());
+    }
+
+    public void testInArray() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         String[] inValue = new String[] {"a", "b", null, null};
-        criteria.whereIn("table.column2", inValue.clone());
+        criteria.whereIn(new ColumnImpl("table.column2"), inValue.clone());
 
         Query query = SqlBuilder.buildQuery(criteria);
 
@@ -1288,12 +1712,12 @@ public class SqlBuilderTest extends Base
         assertEquals(inValue[1], replacements.get(1));
     }
 
-    public void testCriterionInArrayIgnoreCase() throws Exception
+    public void testInArrayIgnoreCase() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         String[] inValue = new String[] {"a", "b", null, null};
-        criteria.whereIn("table.column2", inValue.clone());
+        criteria.whereIn(new ColumnImpl("table.column2"), inValue.clone());
         criteria.setIgnoreCase(true);
 
         Query query = SqlBuilder.buildQuery(criteria);
@@ -1308,16 +1732,16 @@ public class SqlBuilderTest extends Base
         assertEquals(inValue[1], replacements.get(1));
     }
 
-    public void testCriterionInList() throws Exception
+    public void testInList() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         List<Integer> inList = new ArrayList<Integer>();
         inList.add(1);
         inList.add(null);
         inList.add(2);
         inList.add(null);
-        criteria.whereIn("table.column2", inList);
+        criteria.whereIn(new ColumnImpl("table.column2"), inList);
 
         Query query = SqlBuilder.buildQuery(criteria);
         assertEquals("SELECT table.column1 FROM table "
@@ -1330,16 +1754,16 @@ public class SqlBuilderTest extends Base
         assertEquals(2, query.getPreparedStatementReplacements().get(1));
     }
 
-    public void testCriterionInListIgnoreCase() throws Exception
+    public void testInListIgnoreCase() throws Exception
         {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         List<String> inList = new ArrayList<String>();
         inList.add("a");
         inList.add("b");
         inList.add(null);
         inList.add(null);
-        criteria.whereIn("table.column2", inList);
+        criteria.whereIn(new ColumnImpl("table.column2"), inList);
         criteria.setIgnoreCase(true);
 
         Query query = SqlBuilder.buildQuery(criteria);
@@ -1353,17 +1777,17 @@ public class SqlBuilderTest extends Base
         assertEquals("b", replacements.get(1));
     }
 
-    public void testCriterionNotInList() throws Exception
+    public void testNotInList() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         List<Integer> inList = new ArrayList<Integer>();
         inList.add(1);
         inList.add(null);
         inList.add(2);
         inList.add(null);
         criteria.where(
-                "table.column2",
+                new ColumnImpl("table.column2"),
                 inList,
                 Criteria.NOT_IN);
 
@@ -1377,7 +1801,7 @@ public class SqlBuilderTest extends Base
         assertEquals(2, query.getPreparedStatementReplacements().get(1));
     }
 
-    public void testCriterionInLargeArray() throws TorqueException
+    public void testInLargeArray() throws TorqueException
     {
         int size = 10000;
         String[] values = new String[size];
@@ -1386,8 +1810,8 @@ public class SqlBuilderTest extends Base
             Array.set(values, i, String.valueOf(i));
         }
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
-        criteria.whereIn("table.column2", values);
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
+        criteria.whereIn(new ColumnImpl("table.column2"), values);
         long start = System.currentTimeMillis();
         Query query = SqlBuilder.buildQuery(criteria);
         long end =  System.currentTimeMillis();
@@ -1397,10 +1821,10 @@ public class SqlBuilderTest extends Base
         assertTrue(end - start < 50L);
     }
 
-    public void testCriterionInString() throws Exception
+    public void testInString() throws Exception
     {
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("table.column1");
+        criteria.addSelectColumn(new ColumnImpl("table.column1"));
         criteria.where(
                 "table.column2",
                 "illegal in value",
@@ -1418,4 +1842,34 @@ public class SqlBuilderTest extends Base
             e.getMessage());
         }
     }
+
+    public void testFromElementsSetExplicitly() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table1.column1"));
+        criteria.addFrom(new FromElement("table3"));
+        criteria.where(new ColumnImpl("table2.column2"), 1);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table1.column1 FROM table3 "
+                + "WHERE table2.column2=?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(1, query.getPreparedStatementReplacements().get(0));
+    }
+
+    public void testFromElementsSetExplicitlyAsString() throws Exception
+    {
+        Criteria criteria = new Criteria();
+        criteria.addSelectColumn(new ColumnImpl("table1.column1"));
+        criteria.addFrom("table3");
+        criteria.where(new ColumnImpl("table2.column2"), 1);
+
+        Query query = SqlBuilder.buildQuery(criteria);
+        assertEquals("SELECT table1.column1 FROM table3 "
+                + "WHERE table2.column2=?",
+            query.toString());
+        assertEquals(1, query.getPreparedStatementReplacements().size());
+        assertEquals(1, query.getPreparedStatementReplacements().get(0));
+    }
 }

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=1329656&r1=1329655&r2=1329656&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 Tue Apr 24 11:52:50 2012
@@ -21,7 +21,6 @@ package org.apache.torque;
 
 import java.sql.Connection;
 import java.sql.ResultSet;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -421,12 +420,14 @@ public class DataTest extends BaseDataba
     {
         // test double functions in select columns
         Criteria criteria = new Criteria();
-        criteria.addSelectColumn("count(distinct(" + BookPeer.BOOK_ID + "))");
+        criteria.addSelectColumn(
+                new ColumnImpl("count(distinct(" + BookPeer.BOOK_ID + "))"));
         BasePeer.doSelect(criteria, new IntegerMapper(), null);
 
         // test qualifiers in function in select columns
         criteria = new Criteria();
-        criteria.addSelectColumn("count(distinct " + BookPeer.BOOK_ID + ")");
+        criteria.addSelectColumn(
+                new ColumnImpl("count(distinct " + BookPeer.BOOK_ID + ")"));
         BasePeer.doSelect(criteria, new IntegerMapper(), null);
     }
 
@@ -862,7 +863,8 @@ public class DataTest extends BaseDataba
 
         // test usage of Expressions in order by
         criteria = new Criteria();
-        criteria.addAscendingOrderByColumn("UPPER(" + BookPeer.TITLE + ")");
+        criteria.addAscendingOrderByColumn(
+                new ColumnImpl("UPPER(" + BookPeer.TITLE + ")"));
         criteria.setIgnoreCase(true);
         BookPeer.doSelect(criteria);
     }
@@ -1422,139 +1424,6 @@ public class DataTest extends BaseDataba
     }
 
     /**
-     * Tests whether we can execute subqueries.
-     * @throws Exception if the test fails
-     */
-    public void testSubqueries() throws Exception
-    {
-        DB adapter = Torque.getDatabase(Torque.getDefaultDB()).getAdapter();
-        if (adapter instanceof DBMM)
-        {
-            int majorVersion = getMysqlMajorVersion();
-            int minorVersion = getMysqlMinorVersion();
-            if (majorVersion < 4 || (majorVersion == 4 && minorVersion == 0))
-            {
-                log.warn("testSubqueries(): "
-                        + "Subselects are not supported by Mysql < 4.1");
-                return;
-            }
-        }
-        cleanBookstore();
-        Author author1 = new Author();
-        author1.setName("author1");
-        author1.save();
-        Author author2 = new Author();
-        author2.setName("author2");
-        author2.save();
-        Author author2b = new Author();
-        author2b.setName("author2");
-        author2b.save();
-        Author author3 = new Author();
-        author3.setName("author3");
-        author3.save();
-
-        // subquery with "in" clause
-        {
-            Criteria subquery = new Criteria();
-            subquery.addSelectColumn(AuthorPeer.AUTHOR_ID);
-            List<String> authorIds = new ArrayList<String>();
-            authorIds.add(author1.getName());
-            authorIds.add(author2.getName());
-            subquery.add(AuthorPeer.NAME, authorIds, Criteria.IN);
-            Criteria criteria = new Criteria();
-            criteria.add(AuthorPeer.AUTHOR_ID, subquery, Criteria.IN);
-            criteria.addDescendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
-            List<?> result = AuthorPeer.doSelect(criteria);
-            assertEquals("Expected result of size 2 but got " + result.size(),
-                    result.size(),
-                    3);
-            Author author = (Author) result.get(0);
-            assertEquals("Expected author with Id "
-                    + author2b.getAuthorId()
-                    + " at first position but got "
-                    + author.getAuthorId(),
-                    author2b.getAuthorId(),
-                    author.getAuthorId());
-            author = (Author) result.get(1);
-            assertEquals("Expected author with Id "
-                    + author2.getAuthorId()
-                    + " at second position but got "
-                    + author.getAuthorId(),
-                    author2.getAuthorId(),
-                    author.getAuthorId());
-            author = (Author) result.get(2);
-            assertEquals("Expected author with Id "
-                    + author1.getAuthorId()
-                    + " at second position but got "
-                    + author.getAuthorId(),
-                    author1.getAuthorId(),
-                    author.getAuthorId());
-        }
-
-        // subquery with =
-        {
-            Criteria subquery = new Criteria();
-            subquery.addSelectColumn(AuthorPeer.AUTHOR_ID);
-            subquery.add(AuthorPeer.NAME, author1.getName());
-            Criteria criteria = new Criteria();
-            criteria.add(AuthorPeer.AUTHOR_ID, subquery);
-
-            List<Author> result = AuthorPeer.doSelect(criteria);
-            assertEquals("Expected result of size 1 but got " + result.size(),
-                    result.size(),
-                    1);
-            Author author = result.get(0);
-            assertEquals("Expected author with Id "
-                    + author1.getAuthorId()
-                    + " but got "
-                    + author.getAuthorId(),
-                    author1.getAuthorId(),
-                    author.getAuthorId());
-        }
-
-        // subquery containin an in()
-        {
-            Criteria subquery = new Criteria();
-            subquery.addSelectColumn(AuthorPeer.AUTHOR_ID);
-            List<String> nameList = new ArrayList<String>();
-            nameList.add(author1.getName());
-            nameList.add(author2.getName());
-            subquery.add(AuthorPeer.NAME, nameList, Criteria.IN);
-            Criteria criteria = new Criteria();
-            criteria.add(AuthorPeer.AUTHOR_ID, subquery, Criteria.IN);
-            criteria.addAscendingOrderByColumn(AuthorPeer.AUTHOR_ID);
-
-            List<Author> result = AuthorPeer.doSelect(criteria);
-            assertEquals("Expected result of size 2 but got " + result.size(),
-                    result.size(),
-                    3);
-            Author author = result.get(0);
-            assertEquals("Expected author with Id "
-                    + author1.getAuthorId()
-                    + " but got "
-                    + author.getAuthorId(),
-                    author1.getAuthorId(),
-                    author.getAuthorId());
-            author = result.get(1);
-            assertEquals("Expected author with Id "
-                    + author2.getAuthorId()
-                    + " but got "
-                    + author.getAuthorId(),
-                    author2.getAuthorId(),
-                    author.getAuthorId());
-            author = result.get(2);
-            assertEquals("Expected author with Id "
-                    + author2b.getAuthorId()
-                    + " but got "
-                    + author.getAuthorId(),
-                    author2b.getAuthorId(),
-                    author.getAuthorId());
-        }
-    }
-
-
-    /**
      * Tests whether a table implementing an interface actually
      * returns an instance of this interface
      * @throws Exception if the test fails
@@ -1729,7 +1598,7 @@ public class DataTest extends BaseDataba
 
         Criteria criteria = new Criteria();
         criteria.where(AuthorPeer.AUTHOR_ID, (Object) null, Criteria.NOT_EQUAL);
-        criteria.and("name", "Joshua Bloch", Criteria.EQUAL);
+        criteria.and(new ColumnImpl("name"), "Joshua Bloch", Criteria.EQUAL);
         List<Author> authors = AuthorPeer.doSelect(criteria);
         assertEquals(1, authors.size());
     }

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DocsTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DocsTest.java?rev=1329656&r1=1329655&r2=1329656&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DocsTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DocsTest.java Tue Apr 24 11:52:50 2012
@@ -69,7 +69,7 @@ public class DocsTest extends BaseDataba
 
         // clean the books database
         Criteria criteria = new Criteria();
-        criteria.add(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
+        criteria.where(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
         try
         {
             BookPeer.doDelete(criteria);
@@ -82,7 +82,7 @@ public class DocsTest extends BaseDataba
                      + " : " + e.getMessage());
         }
         criteria = new Criteria();
-        criteria.add(
+        criteria.where(
                 AuthorPeer.AUTHOR_ID,
                 (Long) null, Criteria.NOT_EQUAL);
         try
@@ -385,10 +385,11 @@ public class DocsTest extends BaseDataba
             }
         }
         Criteria subquery = new Criteria();
-        subquery.addSelectColumn("MAX(" + AuthorPeer.AUTHOR_ID + ")");
+        subquery.addSelectColumn(
+                new ColumnImpl("MAX(" + AuthorPeer.AUTHOR_ID + ")"));
 
         Criteria criteria = new Criteria();
-        criteria.add(AuthorPeer.AUTHOR_ID, subquery);
+        criteria.where(AuthorPeer.AUTHOR_ID, subquery);
 
         List<Author> authors = AuthorPeer.doSelect(criteria);
         assertEquals("Expected list of size 1 but got " + authors.size(),



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