db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1224848 [2/4] - in /db/torque/torque4/trunk/torque-runtime/src: main/java/org/apache/torque/criteria/ main/java/org/apache/torque/map/ main/java/org/apache/torque/sql/ main/java/org/apache/torque/util/ test/java/org/apache/torque/criteria/...
Date Tue, 27 Dec 2011 01:17:12 GMT
Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java?rev=1224848&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java Tue Dec 27 01:17:11 2011
@@ -0,0 +1,172 @@
+package org.apache.torque.criteria;
+
+/*
+ * 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.List;
+import java.util.Map;
+
+import org.apache.torque.Column;
+import org.apache.torque.sql.OrderBy;
+import org.apache.torque.util.UniqueColumnList;
+import org.apache.torque.util.UniqueList;
+
+/**
+ *
+ * Interface for both the old org.apache.torque.util and the new
+ * org.apache.torque.criteria Criteria class.
+ *
+ * @version $Id: $
+ *
+ * @deprecated This interface will only exist temporarily and will be removed
+ * as soon as the class org.apache.torque.util.Criteria is removed.
+ */
+public interface CriteriaInterface
+{
+    /**
+     * Get the column aliases.
+     *
+     * @return A Map which map the column alias names
+     * to the alias clauses.
+     */
+    Map<String, Column> getAsColumns();
+
+    /**
+     * Get the table aliases.
+     *
+     * @return A Map which maps the table alias names to the actual table names.
+     */
+    Map<String, String> getAliases();
+
+    /**
+     * Allows one to specify an alias for a table that can
+     * be used in various parts of the SQL.
+     *
+     * @param alias a <code>String</code> value
+     * @param table a <code>String</code> value
+     */
+    void addAlias(String alias, String table);
+
+    /**
+     * Returns the table name associated with an alias.
+     *
+     * @param alias a <code>String</code> value
+     * @return a <code>String</code> value
+     */
+    String getTableForAlias(String alias);
+
+    /**
+     * Will force the sql represented by this criteria to be executed within
+     * a transaction.  This is here primarily to support the oid type in
+     * postgresql.  Though it can be used to require any single sql statement
+     * to use a transaction.
+     */
+    void setUseTransaction(boolean v);
+
+    /**
+     * Get the Database(Map) name.
+     *
+     * @return A String with the Database(Map) name.  By default, this
+     * is PoolBrokerService.DEFAULT.
+     */
+    String getDbName();
+
+    /**
+     * Set the DatabaseMap name.  If <code>null</code> is supplied, uses value
+     * provided by <code>Torque.getDefaultDB()</code>.
+     *
+     * @param dbName A String with the Database(Map) name.
+     */
+    void setDbName(String dbName);
+
+    /**
+     * get the List of Joins.  This method is meant to
+     * be called by BasePeer.
+     * @return a List which contains objects of type Join.
+     *         If the criteria does not contains any joins, the list is empty
+     */
+    List<Join> getJoins();
+
+    /**
+     * Adds &quot;ALL &quot; to the SQL statement.
+     */
+    void setAll();
+
+    /**
+     * Adds &quot;DISTINCT &quot; to the SQL statement.
+     */
+    void setDistinct();
+
+    /**
+     * Returns whether case should be ignored in where clauses and order by
+     * whenever String columns are encountered.
+     *
+     * @return True if case is ignored.
+     */
+    boolean isIgnoreCase();
+
+    /**
+     * Is single record?
+     *
+     * @return True if a single record is being returned.
+     */
+    boolean isSingleRecord();
+
+    /**
+     * Get limit.
+     *
+     * @return An int with the value for limit.
+     */
+    int getLimit();
+
+    /**
+     * Get offset.
+     *
+     * @return An int with the value for offset.
+     */
+    int getOffset();
+
+    /**
+     * Get select columns.
+     *
+     * @return An List with the names of the select columns.
+     */
+    UniqueColumnList getSelectColumns();
+
+    /**
+     * Get select modifiers.
+     *
+     * @return An UniqueList with the select modifiers.
+     */
+    UniqueList<String> getSelectModifiers();
+
+    /**
+     * Get order by columns.
+     *
+     * @return An UniqueList with the name of the order columns, not null.
+     */
+    UniqueList<OrderBy> getOrderByColumns();
+
+    /**
+     * Get group by columns.
+     *
+     * @return An UniqueList with the name of the groupBy clause, not null.
+     */
+    UniqueColumnList getGroupByColumns();
+}

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java?rev=1224848&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java Tue Dec 27 01:17:11 2011
@@ -0,0 +1,441 @@
+package org.apache.torque.criteria;
+
+/*
+ * 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.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.torque.Column;
+import org.apache.torque.ColumnImpl;
+
+/**
+ * Describes one or more where clause parts in the Criteria.
+ * Either the parts list is not null and represe<6nts this criterion
+ * or the column, value, comparison and ignoreStringCase columns
+ * are not null and represent this criterion.
+ */
+public class Criterion implements Serializable
+{
+    /** Serial version. */
+    private static final long serialVersionUID = 7157097965404611710L;
+
+    /** Constant for the operator " AND ". */
+    public static final String AND = " AND ";
+
+    /** Constant for thze operator " OR ". */
+    public static final String OR = " OR ";
+
+    /** Value of the CO. */
+    private Object value;
+
+    /** Comparison value. */
+    private SqlEnum comparison;
+
+    /** Column. */
+    private Column column;
+
+    /** flag to ignore case in comparision */
+    private boolean ignoreCase = false;
+
+    /**
+     * The criterion objects which form a composite criterion.
+     * Either this list is not null and represents this criterion
+     * or the column, value, comparison and ignoreStringCase columns
+     * are not null and represent this criterion.
+     */
+    private List<Criterion> parts;
+
+    /**
+     * The operator (AND, OR...) how the composite criterions
+     * are connected.
+     */
+    private String conjunction;
+
+
+    /**
+     * Create a new instance.
+     *
+     * @param column the column description, not null.
+     * @param val An Object with the value for the Criteria, may be null.
+     * @param comp A String with the comparison value, not null.
+     *
+     * @throws NullPointerException if column is null.
+     */
+    public Criterion(Column column, Object val, SqlEnum comp)
+    {
+        this.value = val;
+        setComparison(comp);
+        setColumn(column);
+    }
+
+    /**
+     * Create a new instance.
+     *
+     * @param column the name of the column description, not null.
+     * @param val An Object with the value for the Criteria, may be null.
+     * @param comp A String with the comparison value, not null.
+     *
+     * @throws NullPointerException if column is null.
+     */
+    public Criterion(String column, Object val, SqlEnum comp)
+    {
+        this.value = val;
+        setComparison(comp);
+        setColumn(new ColumnImpl(column));
+    }
+
+    /**
+     * Create a new instance, using equals as comparison.
+     *
+     * @param tableColumn the column description.
+     * @param val An Object with the value for the Criteria.
+     */
+    public Criterion(Column column, Object val)
+    {
+        this(column, val, Criteria.EQUAL);
+    }
+
+    /**
+     * Create a new instance.
+     *
+     * @param column the name of the column description, not null.
+     * @param val An Object with the value for the Criteria, may be null.
+     * @param comp A String with the comparison value, not null.
+     *
+     * @throws NullPointerException if column is null.
+     */
+    public Criterion(String column, Object val)
+    {
+        this(new ColumnImpl(column), val, Criteria.EQUAL);
+    }
+
+    /**
+     * Creates a shallow copy of the given Criterion.
+     *
+     * @param toCopy the Criterion to copy from, not null.
+     */
+    public Criterion(Criterion toCopy)
+    {
+        this.column = toCopy.column;
+        this.comparison = toCopy.comparison;
+        this.value = toCopy.value;
+        this.ignoreCase = toCopy.ignoreCase;
+        this.parts = toCopy.parts;
+        this.conjunction = toCopy.conjunction;
+    }
+
+    /**
+     * Sets the column.
+     *
+     * @param column the column, not null.
+     *
+     * @throws NullPointerException if column is null.
+     */
+    private void setColumn(Column column)
+    {
+        if (column == null)
+        {
+            throw new NullPointerException("column must not be null");
+        }
+        this.column = column;
+    }
+
+    /**
+     * Get the column.
+     *
+     * @return the column.
+     */
+    public Column getColumn()
+    {
+        return this.column;
+    }
+
+    /**
+     * Sets the comparison.
+     *
+     * @param comparison the comparison, not null.
+     *
+     * @throws NullPointerException if comparison is null.
+     */
+    private void setComparison(SqlEnum comparison)
+    {
+        if (comparison == null)
+        {
+            throw new NullPointerException("comparison must not be null");
+        }
+        this.comparison = comparison;
+    }
+
+    /**
+     * Get the comparison.
+     *
+     * @return A String with the comparison.
+     */
+    public SqlEnum getComparison()
+    {
+        return this.comparison;
+    }
+
+    /**
+     * Get the value.
+     *
+     * @return An Object with the value.
+     */
+    public Object getValue()
+    {
+        return this.value;
+    }
+
+    /**
+     * Set the value of the criterion.
+     *
+     * @param value the new value.
+     */
+    public void setValue(Object value)
+    {
+        this.value = value;
+    }
+
+    /**
+     * Sets ignore case.
+     *
+     * @param b True if case should be ignored.
+     * @return A modified Criteria object.
+     */
+    public Criterion setIgnoreCase(boolean b)
+    {
+        ignoreCase = b;
+        return this;
+    }
+
+    /**
+     * Is ignore case on or off?
+     *
+     * @return True if case is ignored.
+     */
+    public boolean isIgnoreCase()
+    {
+        return ignoreCase;
+    }
+
+    /**
+     * Returns the parts of which this criterion consists.
+     *
+     * @return an unmodifiable list of the clauses,
+     *         or null if this criterion is not a composite criterion.
+     */
+    public List<Criterion> getParts()
+    {
+        if (parts == null)
+        {
+            return null;
+        }
+        return Collections.unmodifiableList(parts);
+    }
+
+    /**
+     * Returns the conjunction for the parts of this criterion
+     *
+     * @return the conjunction, or null if this criterion is not a
+     *         composite criterion.
+     */
+    public String getConjunction()
+    {
+        return conjunction;
+    }
+
+    /**
+     * Returns whether this criterion is a composite criterion.
+     *
+     * @return true if this criterion is a composite criterion,
+     *         false if it represents a single condition.
+     */
+    public boolean isComposite()
+    {
+        return parts != null;
+    }
+
+    /**
+     * Replaces this criterion's condition with
+     * (this criterion's condition AND criterion).
+     *
+     * @param criterion the criterion to and with this criterion,
+     *        not null.
+     */
+    public Criterion and(Criterion criterion)
+    {
+        addCompositeCriterion(criterion, AND);
+        return this;
+    }
+
+    /**
+     * Replaces this criterion's condition with
+     * (this criterion's condition OR criterion).
+     *
+     * @param criterion the criterion to and with this criterion,
+     *        not null.
+     */
+    public Criterion or(Criterion criterion)
+    {
+        addCompositeCriterion(criterion, OR);
+        return this;
+    }
+
+    /**
+     * Add a composite criterion to this criterion.
+     *
+     * @param criterion the criterion to add, not null.
+     * @param conjunction the conjunction by which to add the criterion,
+     *        not null.
+     *
+     * @throws NullPointerException if criterion is null.
+     */
+    private void addCompositeCriterion(
+            Criterion criterion,
+            String conjunction)
+    {
+        if (criterion == null)
+        {
+            throw new NullPointerException("criterion must not be null");
+        }
+        if (isComposite() && this.conjunction.equals(conjunction))
+        {
+            parts.add(criterion);
+        }
+        else
+        {
+            Criterion copy = new Criterion(this);
+            parts = new ArrayList<Criterion>();
+            parts.add(copy);
+            parts.add(criterion);
+            this.conjunction = conjunction;
+            this.column = null;
+            this.comparison = null;
+            this.value = null;
+            this.ignoreCase = false;
+        }
+    }
+
+    /**
+     * Appends a debug String representation of the Criterion
+     * onto the String builder.
+     */
+    public void appendTo(StringBuilder sb)
+    {
+        if (isComposite())
+        {
+            boolean first = true;
+            for (Criterion part : parts)
+            {
+                if (!first)
+                {
+                    if (part.isComposite())
+                    {
+                        sb.append('(');
+                    }
+                    sb.append(conjunction);
+                    if (part.isComposite())
+                    {
+                        sb.append(')');
+                    }
+                }
+                sb.append(part);
+                first = false;
+            }
+        }
+        else
+        {
+            if (Criteria.CUSTOM == comparison)
+            {
+                if (value != null && !"".equals(value))
+                {
+                    sb.append((String) value);
+                }
+            }
+            else
+            {
+                String field = column.getSqlExpression();
+                sb.append(field).append(comparison).append(value);
+            }
+        }
+    }
+
+    /**
+     * Build a string representation of the Criterion for debug purposes.
+     *
+     * @return A String with the representation of the Criterion.
+     */
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        appendTo(builder);
+        return builder.toString();
+    }
+
+    /**
+     * This method checks another Criteria.Criterion to see if they contain
+     * the same attributes.
+     */
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if ((obj == null) || !(obj instanceof Criterion))
+        {
+            return false;
+        }
+        if (obj.getClass() != this.getClass())
+        {
+            return false;
+        }
+
+        Criterion criterion = (Criterion) obj;
+        EqualsBuilder equalsBuilder = new EqualsBuilder();
+        equalsBuilder.append(criterion.column, this.column);
+        equalsBuilder.append(criterion.comparison, this.comparison);
+        equalsBuilder.append(criterion.value, this.value);
+        equalsBuilder.append(criterion.ignoreCase, this.ignoreCase);
+        equalsBuilder.append(criterion.parts, this.parts);
+        equalsBuilder.append(criterion.conjunction, this.conjunction);
+        return equalsBuilder.isEquals();
+    }
+
+    /**
+     * Returns a hash code value for the object.
+     */
+    public int hashCode()
+    {
+        HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
+        hashCodeBuilder.append(this.column);
+        hashCodeBuilder.append(this.comparison);
+        hashCodeBuilder.append(this.value);
+        hashCodeBuilder.append(this.ignoreCase);
+        hashCodeBuilder.append(this.parts);
+        hashCodeBuilder.append(this.conjunction);
+        return hashCodeBuilder.toHashCode();
+    }
+}
+

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Join.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Join.java?rev=1224848&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Join.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Join.java Tue Dec 27 01:17:11 2011
@@ -0,0 +1,165 @@
+package org.apache.torque.criteria;
+
+/*
+ * 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.io.Serializable;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.torque.Column;
+
+/**
+ * Data object to describe a join between two tables, for example
+ * <pre>
+ * table_a LEFT JOIN table_b ON table_a.id = table_b.a_id
+ * </pre>
+ * The class is immutable. Because the class is also used by
+ * {@link org.apache.torque.util.BasePeer}, it is visible from the package.
+ */
+public class Join implements Serializable
+{
+    /** Version id for serializing. */
+    private static final long serialVersionUID = 1L;
+
+    /** the left column of the join condition, not null. */
+    private Column leftColumn = null;
+
+    /** the right column of the join condition, not null. */
+    private Column rightColumn = null;
+
+    /** the type of the join (LEFT JOIN, ...), or null. */
+    private SqlEnum joinType = null;
+
+    /**
+     * Constructor
+     * @param leftColumn the left column of the join condition;
+     *        might contain an alias name, not null.
+     * @param rightColumn the right column of the join condition
+     *        might contain an alias name, not null.
+     * @param joinType the type of the join. Valid join types are
+     *        null (adding the join condition to the where clause),
+     *        SqlEnum.LEFT_JOIN, SqlEnum.RIGHT_JOIN, and SqlEnum.INNER_JOIN
+     */
+    public Join(
+            final Column leftColumn,
+            final Column rightColumn,
+            final SqlEnum joinType)
+    {
+        if (leftColumn == null)
+        {
+            throw new NullPointerException("leftColumn is null");
+        }
+        if (rightColumn == null)
+        {
+            throw new NullPointerException("rightColumn is null");
+        }
+        this.leftColumn = leftColumn;
+        this.rightColumn = rightColumn;
+        this.joinType = joinType;
+    }
+
+    /**
+     * @return the type of the join, i.e. SqlEnum.LEFT_JOIN, ...,
+     *         or null for adding the join condition to the where Clause
+     */
+    public final SqlEnum getJoinType()
+    {
+        return joinType;
+    }
+
+    /**
+     * @return the left column of the join condition
+     */
+    public final Column getLeftColumn()
+    {
+        return leftColumn;
+    }
+
+    /**
+     * @return the right column of the join condition
+     */
+    public final Column getRightColumn()
+    {
+        return rightColumn;
+    }
+
+    /**
+     * returns a String representation of the class,
+     * mainly for debuggung purposes.
+     *
+     * @return a String representation of the class
+     */
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer();
+        if (joinType != null)
+        {
+            result.append(joinType)
+                    .append(" : ");
+        }
+        result.append(leftColumn.getSqlExpression())
+                .append("=")
+                .append(rightColumn.getSqlExpression())
+                .append(" (ignoreCase not considered)");
+
+        return result.toString();
+    }
+
+    /**
+     * This method checks another Criteria.Join to see if they contain the
+     * same attributes.
+     */
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+
+        if ((obj == null) || !(obj instanceof Join))
+        {
+            return false;
+        }
+
+        Join join = (Join) obj;
+        return new EqualsBuilder().append(
+                leftColumn.getSqlExpression(),
+                join.leftColumn.getSqlExpression())
+            .append(
+                rightColumn.getSqlExpression(),
+                join.rightColumn.getSqlExpression())
+            .append(joinType, join.getJoinType())
+            .isEquals();
+    }
+
+    /**
+     * Returns the hash code value for this Join.
+     *
+     * @return a hash code value for this object.
+     */
+    public int hashCode()
+    {
+        return new HashCodeBuilder().append(leftColumn.getSqlExpression())
+            .append(rightColumn.getSqlExpression())
+            .append(joinType)
+            .toHashCode();
+    }
+
+}

Copied: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/SqlEnum.java (from r1206840, 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/criteria/SqlEnum.java?p2=db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/SqlEnum.java&p1=db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SqlEnum.java&r1=1206840&r2=1224848&rev=1224848&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/criteria/SqlEnum.java Tue Dec 27 01:17:11 2011
@@ -1,4 +1,4 @@
-package org.apache.torque.util;
+package org.apache.torque.criteria;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/package.html
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/package.html?rev=1224848&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/package.html (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/package.html Tue Dec 27 01:17:11 2011
@@ -0,0 +1,25 @@
+<!--
+ 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 Torque's Criteria classes.
+  </body>
+</html>

Added: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/MapHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/MapHelper.java?rev=1224848&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/MapHelper.java (added)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/MapHelper.java Tue Dec 27 01:17:11 2011
@@ -0,0 +1,85 @@
+package org.apache.torque.map;
+
+/*
+ * 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.Map;
+
+import org.apache.torque.Column;
+import org.apache.torque.Torque;
+import org.apache.torque.criteria.CriteriaInterface;
+
+/**
+ * Utility methods for Database, Table and Column Maps.
+ *
+ * @version $Id: $
+ */
+@SuppressWarnings("deprecation")
+public final class MapHelper
+{
+    /** Private constructor. */
+    private MapHelper()
+    {
+    }
+
+    /**
+     * Returns the table map for a table name.
+     *
+     * @param column the column to get the table map for.
+     * @param criteria A criteria containing the database name and perhaps
+     *        aliases for the table name, not null.
+     * @param defaultTableMap a default table map which is used if the table
+     *        name cannot be resolved, may be null.
+     * @return the table map, or null if the table name cannot be resolved.
+     */
+    public static TableMap getTableMap(
+            Column column,
+            CriteriaInterface criteria,
+            TableMap defaultTableMap)
+    {
+        TableMap result = null;
+        String tableName = column.getTableName();
+        if (tableName != null)
+        {
+            String databaseName = criteria.getDbName();
+            DatabaseMap databaseMap = Torque.getDatabaseMap(databaseName);
+            if (databaseMap != null)
+            {
+                result = databaseMap.getTable(tableName);
+            }
+            if (result != null)
+            {
+                return result;
+            }
+            // try aliases
+            Map<String, String> aliases = criteria.getAliases();
+            if (aliases.get(tableName) != null)
+            {
+                tableName = aliases.get(tableName);
+                result = databaseMap.getTable(tableName);
+            }
+        }
+        if (result == null)
+        {
+            result = defaultTableMap;
+        }
+        return result;
+    }
+
+}

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java?rev=1224848&r1=1224847&r2=1224848&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/JoinBuilder.java Tue Dec 27 01:17:11 2011
@@ -24,8 +24,9 @@ import java.util.List;
 import org.apache.torque.Column;
 import org.apache.torque.Database;
 import org.apache.torque.TorqueException;
-import org.apache.torque.util.Criteria;
-import org.apache.torque.util.SqlEnum;
+import org.apache.torque.criteria.CriteriaInterface;
+import org.apache.torque.criteria.Join;
+import org.apache.torque.criteria.SqlEnum;
 import org.apache.torque.util.UniqueList;
 
 /**
@@ -35,6 +36,7 @@ import org.apache.torque.util.UniqueList
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
  * @version $Id$
  */
+@SuppressWarnings("deprecation")
 public final class JoinBuilder
 {
     /**
@@ -57,11 +59,11 @@ public final class JoinBuilder
      */
     public static void processJoins(
             final Database database,
-            final Criteria criteria,
+            final CriteriaInterface criteria,
             final Query query)
             throws TorqueException
     {
-        List<Criteria.Join> criteriaJoins = criteria.getJoins();
+        List<Join> criteriaJoins = criteria.getJoins();
 
         if (criteriaJoins.isEmpty())
         {
@@ -73,7 +75,7 @@ public final class JoinBuilder
 
         for (int i = 0; i < criteriaJoins.size(); i++)
         {
-            Criteria.Join join = criteriaJoins.get(i);
+            Join join = criteriaJoins.get(i);
             Column leftColumn = join.getLeftColumn();
             Column rightColumn = join.getRightColumn();
 

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/OrderBy.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/OrderBy.java?rev=1224848&r1=1224847&r2=1224848&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/OrderBy.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/OrderBy.java Tue Dec 27 01:17:11 2011
@@ -24,7 +24,7 @@ import java.io.Serializable;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.torque.Column;
-import org.apache.torque.util.SqlEnum;
+import org.apache.torque.criteria.SqlEnum;
 
 /**
  * An order by clause.

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java?rev=1224848&r1=1224847&r2=1224848&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/sql/Query.java Tue Dec 27 01:17:11 2011
@@ -27,7 +27,7 @@ import org.apache.commons.lang.StringUti
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.torque.TorqueException;
-import org.apache.torque.util.SqlEnum;
+import org.apache.torque.criteria.SqlEnum;
 import org.apache.torque.util.UniqueList;
 
 /**

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=1224848&r1=1224847&r2=1224848&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 Tue Dec 27 01:17:11 2011
@@ -32,13 +32,15 @@ import org.apache.torque.Database;
 import org.apache.torque.Torque;
 import org.apache.torque.TorqueException;
 import org.apache.torque.adapter.DB;
+import org.apache.torque.criteria.Criteria;
+import org.apache.torque.criteria.CriteriaInterface;
+import org.apache.torque.criteria.Criterion;
+import org.apache.torque.criteria.SqlEnum;
 import org.apache.torque.map.ColumnMap;
 import org.apache.torque.map.DatabaseMap;
+import org.apache.torque.map.MapHelper;
 import org.apache.torque.map.TableMap;
 import org.apache.torque.om.ObjectKey;
-import org.apache.torque.util.Criteria;
-import org.apache.torque.util.Criteria.Criterion;
-import org.apache.torque.util.SqlEnum;
 import org.apache.torque.util.UniqueColumnList;
 import org.apache.torque.util.UniqueList;
 
@@ -51,6 +53,7 @@ import org.apache.torque.util.UniqueList
  * @author <a href="mailto:fischer@seitenbau.de">Thomas Fischer</a>
  * @version $Id$
  */
+@SuppressWarnings("deprecation")
 public final class SqlBuilder
 {
     /** Logging */
@@ -81,8 +84,10 @@ public final class SqlBuilder
      * @return the corresponding query to the criteria.
      *
      * @exception TorqueException if an error occurs
+     * @deprecated please use org.apache.torque.criteria.Criteria
+     *             instead of org.apache.torque.util.Criteria.
      */
-    public static Query buildQuery(final Criteria crit)
+    public static Query buildQuery(final org.apache.torque.util.Criteria crit)
             throws TorqueException
     {
         Query sqlStatement = new Query();
@@ -104,6 +109,36 @@ public final class SqlBuilder
         return sqlStatement;
     }
 
+    /**
+     * Builds a Query from a criteria.
+     *
+     * @param crit the criteria to build the query from, not null.
+     *
+     * @return the corresponding query to the criteria.
+     *
+     * @exception TorqueException if an error occurs
+     */
+    public static Query buildQuery(final Criteria crit)
+            throws TorqueException
+    {
+        Query sqlStatement = new Query();
+
+        final String dbName = crit.getDbName();
+        final DB db = Torque.getDB(dbName);
+        final Database database = Torque.getDatabase(dbName);
+
+        JoinBuilder.processJoins(database, crit, sqlStatement);
+        processModifiers(crit, sqlStatement);
+        processSelectColumns(crit, sqlStatement, database);
+        processAsColumns(crit, sqlStatement, database);
+        processCriterions(db, database, crit, sqlStatement);
+        processGroupBy(crit, database, sqlStatement);
+        processHaving(crit, sqlStatement);
+        processOrderBy(db, database, crit, sqlStatement);
+        processLimits(crit, sqlStatement);
+
+        return sqlStatement;
+    }
 
     /**
      * Adds the select columns from the criteria to the query.
@@ -115,7 +150,7 @@ public final class SqlBuilder
      * @throws TorqueException if the select columns can not be processed.
      */
     private static void processSelectColumns(
-                final Criteria criteria,
+                final CriteriaInterface criteria,
                 final Query query,
                 final Database database)
             throws TorqueException
@@ -154,7 +189,7 @@ public final class SqlBuilder
      * @throws TorqueException if the as columns can not be processed.
      */
     private static void processAsColumns(
-                final Criteria criteria,
+                final CriteriaInterface criteria,
                 final Query query,
                 final Database database)
             throws TorqueException
@@ -186,7 +221,7 @@ public final class SqlBuilder
      *        not null.
      */
     private static void processModifiers(
-            final Criteria criteria,
+            final CriteriaInterface criteria,
             final Query query)
     {
         UniqueList<String> selectModifiers = query.getSelectModifiers();
@@ -214,9 +249,130 @@ public final class SqlBuilder
             final Query query)
         throws TorqueException
     {
+        if (criteria.getTopLevelCriterion() == null)
+        {
+            return;
+        }
+        StringBuilder where = new StringBuilder();
+        appendCriterion(
+                criteria.getTopLevelCriterion(),
+                criteria,
+                db,
+                where,
+                database,
+                query);
+        query.getWhereClause().add(where.toString());
+    }
+
+    private static void appendCriterion(
+                Criterion criterion,
+                Criteria criteria,
+                DB db,
+                StringBuilder where,
+                Database database,
+                Query query)
+            throws TorqueException
+    {
+        if (criterion.isComposite())
+        {
+            where.append('(');
+            boolean firstPart = true;
+            for (Criterion part : criterion.getParts())
+            {
+                if (!firstPart)
+                {
+                    where.append(criterion.getConjunction());
+                }
+                appendCriterion(
+                        part,
+                        criteria,
+                        db,
+                        where,
+                        database,
+                        query);
+                firstPart = false;
+            }
+            where.append(')');
+            return;
+        }
+        Column column = criterion.getColumn();
+
+        // add the table to the from clause, if it is not already
+        // contained there
+        // it is important that this piece of code is executed AFTER
+        // the joins are processed
+        addTableToFromClause(
+            column,
+            database,
+            criteria,
+            query);
+
+        boolean ignoreCase
+                = criteria.isIgnoreCase() || criterion.isIgnoreCase();
+        {
+            Column databaseColumn = resolveAliasAndAsColumnAndSchema(
+                    column,
+                    criteria,
+                    database);
+            ColumnMap columnMap = null;
+            {
+                DatabaseMap databaseMap = database.getDatabaseMap();
+                TableMap tableMap = databaseMap.getTable(
+                        databaseColumn.getTableName());
+                if (tableMap != null)
+                {
+                    columnMap = tableMap.getColumn(
+                            databaseColumn.getColumnName());
+                }
+            }
+            if (columnMap != null)
+            {
+                // do not use ignoreCase on columns
+                // which do not contain String values
+                ignoreCase = ignoreCase
+                    && columnMap.getType() instanceof String;
+            }
+        }
+
+        String columnName = criterion.getColumn().getSqlExpression();
+        WhereClauseExpression whereClausePartInput
+                = new WhereClauseExpression(
+                        columnName,
+                        criterion.getComparison(),
+                        criterion.getValue());
+        PreparedStatementPart whereClausePartOutput
+            = buildPs(
+                whereClausePartInput,
+                ignoreCase,
+                db);
+        where.append(whereClausePartOutput.getSql());
+        query.getPreparedStatementReplacements().addAll(
+                whereClausePartOutput.getPreparedStatementReplacements());
+    }
+
+    /**
+     * Adds the Criterions from the criteria to the query.
+     *
+     * @param db the database for which the query should be created.
+     * @param database the database in which the query should run.
+     * @param criteria the criteria from which the Criterion-objects are taken
+     * @param query the query to which the Criterion-objects should be added.
+     *
+     * @throws TorqueException if the Criterion-objects can not be processed
+     * @deprecated please use org.apache.torque.criteria.Criteria
+     *             instead of org.apache.torque.util.Criteria.
+     */
+    private static void processCriterions(
+            final DB db,
+            final Database database,
+            final org.apache.torque.util.Criteria criteria,
+            final Query query)
+        throws TorqueException
+    {
         UniqueList<String> whereClause = query.getWhereClause();
 
-        for (Criteria.Criterion criterion : criteria.values())
+        for (org.apache.torque.util.Criteria.Criterion criterion
+                : criteria.values())
         {
             StringBuilder sb = new StringBuilder();
             appendCriterionToPs(
@@ -230,9 +386,13 @@ public final class SqlBuilder
         }
     }
 
+    /**
+     * @deprecated please use org.apache.torque.criteria.Criteria
+     *             instead of org.apache.torque.util.Criteria.
+     */
     private static void appendCriterionToPs(
-                Criterion criterion,
-                Criteria criteria,
+                org.apache.torque.util.Criteria.Criterion criterion,
+                org.apache.torque.util.Criteria criteria,
                 StringBuilder sb,
                 DB db,
                 Database database,
@@ -300,7 +460,8 @@ public final class SqlBuilder
         for (int i = 0; i < criterion.getClauses().size(); i++)
         {
             sb.append(criterion.getConjunctions().get(i));
-            Criterion clause = criterion.getClauses().get(i);
+            org.apache.torque.util.Criteria.Criterion clause
+                = criterion.getClauses().get(i);
             appendCriterionToPs(
                     clause,
                     criteria,
@@ -311,7 +472,6 @@ public final class SqlBuilder
             sb.append(')');
         }
     }
-
     /**
      * adds the OrderBy-Columns from the criteria to the query
      * @param criteria the criteria from which the OrderBy-Columns are taken
@@ -321,7 +481,7 @@ public final class SqlBuilder
     private static void processOrderBy(
             final DB db,
             final Database database,
-            final Criteria crit,
+            final CriteriaInterface crit,
             final Query query)
             throws TorqueException
     {
@@ -335,8 +495,7 @@ public final class SqlBuilder
         for (OrderBy orderBy : orderByList)
         {
             Column column = orderBy.getColumn();
-            TableMap tableMap = database.getDatabaseMap().getTable(
-                    column.getTableName());
+            TableMap tableMap = MapHelper.getTableMap(column, crit, null);
             ColumnMap columnMap = null;
             if (tableMap != null)
             {
@@ -391,7 +550,7 @@ public final class SqlBuilder
      * @throws TorqueException if the GroupBy-Columns can not be processed
      */
     private static void processGroupBy(
-            final Criteria criteria,
+            final CriteriaInterface criteria,
             final Database database,
             final Query query)
             throws TorqueException
@@ -427,7 +586,25 @@ public final class SqlBuilder
             final Query query)
             throws TorqueException
     {
-        Criteria.Criterion having = crit.getHaving();
+        Criterion having = crit.getHaving();
+        if (having != null)
+        {
+            query.setHaving(having.toString());
+        }
+    }
+
+    /**
+     * adds the Having-Columns from the criteria to the query
+     * @param criteria the criteria from which the Having-Columns are taken
+     * @param query the query to which the Having-Columns should be added
+     * @throws TorqueException if the Having-Columns can not be processed
+     */
+    private static void processHaving(
+            final org.apache.torque.util.Criteria crit,
+            final Query query)
+            throws TorqueException
+    {
+        org.apache.torque.util.Criteria.Criterion having = crit.getHaving();
         if (having != null)
         {
             query.setHaving(having.toString());
@@ -435,14 +612,14 @@ public final class SqlBuilder
     }
 
     /**
-     * adds a Limit clause to the query if supported by the database
+     * Adds a Limit clause to the query if supported by the database
      * @param criteria the criteria from which the Limit and Offset values
      *        are taken
      * @param query the query to which the Limit clause should be added
      * @throws TorqueException if the Database adapter cannot be obtained
      */
     private static void processLimits(
-            final Criteria crit,
+            final CriteriaInterface crit,
             final Query query)
             throws TorqueException
     {
@@ -472,7 +649,7 @@ public final class SqlBuilder
     static String getTableNameForFromClause(
             final Column column,
             final Database database,
-            final Criteria criteria)
+            final CriteriaInterface criteria)
             throws TorqueException
     {
         Column resolvedColumn
@@ -554,7 +731,7 @@ public final class SqlBuilder
      */
     static Column resolveAliasAndAsColumnAndSchema(
             final Column columnToResolve,
-            final Criteria criteria,
+            final CriteriaInterface criteria,
             Database database)
             throws TorqueException
     {
@@ -652,7 +829,7 @@ public final class SqlBuilder
     static String addTableToFromClause(
                 final Column column,
                 final Database database,
-                final Criteria criteria,
+                final CriteriaInterface criteria,
                 Query query)
             throws TorqueException
     {
@@ -769,6 +946,19 @@ public final class SqlBuilder
                     .append("(").append(subquery.toString()).append(")");
                 return result;
         }
+        if (whereClausePart.getRValue()
+                instanceof org.apache.torque.util.Criteria)
+        {
+            Query subquery = SqlBuilder.buildQuery(
+                    (org.apache.torque.util.Criteria)
+                        whereClausePart.getRValue());
+            result.getPreparedStatementReplacements().addAll(
+                    subquery.getPreparedStatementReplacements());
+            result.getSql().append(whereClausePart.getLValue())
+                    .append(whereClausePart.getOperator())
+                    .append("(").append(subquery.toString()).append(")");
+                return result;
+        }
 
         // handle LIKE and similar
         if (whereClausePart.getOperator().equals(Criteria.LIKE)

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=1224848&r1=1224847&r2=1224848&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 Tue Dec 27 01:17:11 2011
@@ -20,7 +20,7 @@ package org.apache.torque.sql;
  */
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.torque.util.SqlEnum;
+import org.apache.torque.criteria.SqlEnum;
 
 /**
  * The raw values for a part of the where clause of a SQL statement,

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java?rev=1224848&r1=1224847&r2=1224848&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java Tue Dec 27 01:17:11 2011
@@ -293,20 +293,6 @@ public abstract class BasePeer
     }
 
     /**
-     * Method to create an SQL query for display only based on values in a
-     * Criteria.
-     *
-     * @param criteria A Criteria.
-     * @return the SQL query for display
-     * @exception TorqueException Trouble creating the query string.
-     */
-    static String createQueryDisplayString(Criteria criteria)
-        throws TorqueException
-    {
-        return getBasePeerImpl().createQueryDisplayString(criteria);
-    }
-
-    /**
      * Selects rows from a database an maps them to objects.
      *
      * @param criteria A Criteria specifying the records to select, not null.

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=1224848&r1=1224847&r2=1224848&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 Dec 27 01:17:11 2011
@@ -43,6 +43,7 @@ import org.apache.torque.adapter.DB;
 import org.apache.torque.adapter.IDMethod;
 import org.apache.torque.map.ColumnMap;
 import org.apache.torque.map.DatabaseMap;
+import org.apache.torque.map.MapHelper;
 import org.apache.torque.map.TableMap;
 import org.apache.torque.oid.IdGenerator;
 import org.apache.torque.om.NumberKey;
@@ -666,21 +667,6 @@ public class BasePeerImpl implements Ser
     }
 
     /**
-     * Method to create an SQL query for display only based on values in a
-     * Criteria.
-     *
-     * @param criteria A Criteria.
-     * @return the SQL query for display
-     * @exception TorqueException Trouble creating the query string.
-     */
-   String createQueryDisplayString(Criteria criteria)
-        throws TorqueException
-    {
-        Query query = SqlBuilder.buildQuery(criteria);
-        return query.getDisplayString();
-    }
-
-    /**
      * Selects rows from a database an maps them to objects.
      *
      * @param criteria A Criteria specifying the records to select, not null.
@@ -1669,39 +1655,15 @@ public class BasePeerImpl implements Ser
                 TableMap defaultTableMap)
             throws TorqueException
     {
-        String tableName = criterion.getColumn().getTableName();
-        TableMap tableMap = null;
-        if (tableName != null)
-        {
-            String databaseName = criteria.getDbName();
-            if (databaseName == null)
-            {
-                databaseName = Torque.getDefaultDB();
-            }
-            DatabaseMap databaseMap = Torque.getDatabaseMap(databaseName);
-            if (databaseMap != null)
-            {
-                tableMap = databaseMap.getTable(tableName);
-            }
-            if (tableMap == null)
-            {
-                // try aliases
-                Map<String, String> aliases = criteria.getAliases();
-                if (aliases.get(tableName) != null)
-                {
-                    tableName = aliases.get(tableName);
-                    tableMap = databaseMap.getTable(tableName);
-                }
-            }
-        }
-        if (tableMap == null)
-        {
-            tableMap = defaultTableMap;
-        }
+        Column column = criterion.getColumn();
+        TableMap tableMap = MapHelper.getTableMap(
+                column,
+                criteria,
+                defaultTableMap);
         // if no description of table available, do not modify anything
         if (tableMap != null)
         {
-            String columnName = criterion.getColumn().getColumnName();
+            String columnName = column.getColumnName();
             ColumnMap columnMap = tableMap.getColumn(columnName);
             if (columnMap != null)
             {
@@ -1718,7 +1680,6 @@ public class BasePeerImpl implements Ser
                  }
             }
         }
-
         for (Criteria.Criterion attachedCriterion : criterion.getClauses())
         {
             correctBooleans(criteria, attachedCriterion, defaultTableMap);
@@ -1726,6 +1687,79 @@ public class BasePeerImpl implements Ser
     }
 
     /**
+     * Checks all columns in the criteria to see whether
+     * booleanchar and booleanint columns are queried with a boolean.
+     * If yes, the query values are mapped onto values the database
+     * does understand, i.e. 0 and 1 for booleanints and N and Y for
+     * booleanchar columns.
+     *
+     * @param criteria The criteria to be checked for booleanint and booleanchar
+     *        columns.
+     * @param defaultTableMap the table map to be used if the table name is
+     *        not given in a column.
+     * @throws TorqueException if the database map for the criteria cannot be
+     *         retrieved.
+     */
+    public void correctBooleans(
+                org.apache.torque.criteria.Criteria criteria,
+                TableMap defaultTableMap)
+            throws TorqueException
+    {
+       correctBooleans(
+               criteria,
+               criteria.getTopLevelCriterion(),
+               defaultTableMap);
+    }
+
+    private void correctBooleans(
+                org.apache.torque.criteria.Criteria criteria,
+                org.apache.torque.criteria.Criterion criterion,
+                TableMap defaultTableMap)
+            throws TorqueException
+    {
+        if (criterion == null)
+        {
+            return;
+        }
+        if (criterion.isComposite())
+        {
+            for (org.apache.torque.criteria.Criterion part
+                    : criterion.getParts())
+            {
+                correctBooleans(criteria, part, defaultTableMap);
+            }
+            return;
+        }
+
+        Column column = criterion.getColumn();
+        TableMap tableMap = MapHelper.getTableMap(
+                column,
+                criteria,
+                defaultTableMap);
+        // if no description of table available, do not modify anything
+        if (tableMap == null)
+        {
+            return;
+        }
+        String columnName = column.getColumnName();
+        ColumnMap columnMap = tableMap.getColumn(columnName);
+        if (columnMap != null)
+        {
+            if ("BOOLEANINT".equals(columnMap.getTorqueType()))
+            {
+                replaceBooleanValues(
+                        criterion,
+                        new Integer(1),
+                        new Integer(0));
+            }
+            else if ("BOOLEANCHAR".equals(columnMap.getTorqueType()))
+            {
+                replaceBooleanValues(criterion, "Y", "N");
+             }
+        }
+    }
+
+    /**
      * Replaces any Boolean value in the criterion and its attached Criterions
      * by trueValue if the Boolean equals <code>Boolean.TRUE</code>
      * and falseValue if the Boolean equals <code>Boolean.FALSE</code>.
@@ -1757,7 +1791,32 @@ public class BasePeerImpl implements Ser
             }
 
         }
+    }
 
+    /**
+     * Replaces any Boolean value in the criterion and its attached Criterions
+     * by trueValue if the Boolean equals <code>Boolean.TRUE</code>
+     * and falseValue if the Boolean equals <code>Boolean.FALSE</code>.
+     *
+     * @param criterion the criterion to replace Boolean values in.
+     *        May not be a composite criterion.
+     * @param trueValue the value by which Boolean.TRUE should be replaced.
+     * @param falseValue the value by which Boolean.FALSE should be replaced.
+     */
+    private void replaceBooleanValues(
+            org.apache.torque.criteria.Criterion criterion,
+            Object trueValue,
+            Object falseValue)
+    {
+        Object criterionValue = criterion.getValue();
+        if (criterionValue instanceof Boolean)
+        {
+            Boolean booleanValue = (Boolean) criterionValue;
+            criterion.setValue(
+                    Boolean.TRUE.equals(booleanValue)
+                            ? trueValue
+                            : falseValue);
+        }
     }
 
     /**

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java?rev=1224848&r1=1224847&r2=1224848&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/CountHelper.java Tue Dec 27 01:17:11 2011
@@ -34,6 +34,7 @@ import java.util.List;
 import org.apache.torque.Column;
 import org.apache.torque.ColumnImpl;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.SqlEnum;
 import org.apache.torque.om.mapper.IntegerMapper;
 
 /**

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=1224848&r1=1224847&r2=1224848&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 Tue Dec 27 01:17:11 2011
@@ -33,15 +33,19 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.torque.Column;
 import org.apache.torque.ColumnImpl;
 import org.apache.torque.Torque;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.CriteriaInterface;
+import org.apache.torque.criteria.Join;
+import org.apache.torque.criteria.SqlEnum;
 import org.apache.torque.om.ObjectKey;
 import org.apache.torque.sql.OrderBy;
+import org.apache.torque.sql.Query;
+import org.apache.torque.sql.SqlBuilder;
 
 /**
  * Encapsulates conditions to access rows in database tables.
@@ -57,8 +61,12 @@ import org.apache.torque.sql.OrderBy;
  * @author <a href="mailto:seade@backstagetech.com.au">Scott Eade</a>
  * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
  * @version $Id$
+ *
+ * @deprecated This class will be removed in a future version of Torque.
+ *             Use org.apache.torque.criteria.Criteria instead; note that
+ *             that class has another semantics of the add.. and or.. methods.
  */
-public class Criteria implements Serializable
+public class Criteria implements Serializable, CriteriaInterface
 {
     /** Serial version. */
     private static final long serialVersionUID = -9001666575933085601L;
@@ -1886,8 +1894,9 @@ public class Criteria implements Seriali
 
         try
         {
+            Query query = SqlBuilder.buildQuery(this);
             sb.append("\nCurrent Query SQL (may not be complete or applicable): ")
-                    .append(BasePeer.createQueryDisplayString(this));
+                    .append(query.getDisplayString());
         }
         catch (Exception exc)
         {
@@ -3469,146 +3478,4 @@ public class Criteria implements Seriali
             }
         }
     } // end of inner class Criterion
-
-    /**
-     * Data object to describe a join between two tables, for example
-     * <pre>
-     * table_a LEFT JOIN table_b ON table_a.id = table_b.a_id
-     * </pre>
-     * The class is immutable. Because the class is also used by
-     * {@link org.apache.torque.util.BasePeer}, it is visible from the package.
-     */
-    public static class Join implements Serializable
-    {
-        /** Version id for serializing. */
-        private static final long serialVersionUID = 1L;
-
-        /** the left column of the join condition, not null. */
-        private Column leftColumn = null;
-
-        /** the right column of the join condition, not null. */
-        private Column rightColumn = null;
-
-        /** the type of the join (LEFT JOIN, ...), or null. */
-        private SqlEnum joinType = null;
-
-        /**
-         * Constructor
-         * @param leftColumn the left column of the join condition;
-         *        might contain an alias name, not null.
-         * @param rightColumn the right column of the join condition
-         *        might contain an alias name, not null.
-         * @param joinType the type of the join. Valid join types are
-         *        null (adding the join condition to the where clause),
-         *        SqlEnum.LEFT_JOIN, SqlEnum.RIGHT_JOIN, and SqlEnum.INNER_JOIN
-         */
-        public Join(
-                final Column leftColumn,
-                final Column rightColumn,
-                final SqlEnum joinType)
-        {
-            if (leftColumn == null)
-            {
-                throw new NullPointerException("leftColumn is null");
-            }
-            if (rightColumn == null)
-            {
-                throw new NullPointerException("rightColumn is null");
-            }
-            this.leftColumn = leftColumn;
-            this.rightColumn = rightColumn;
-            this.joinType = joinType;
-        }
-
-        /**
-         * @return the type of the join, i.e. SqlEnum.LEFT_JOIN, ...,
-         *         or null for adding the join condition to the where Clause
-         */
-        public final SqlEnum getJoinType()
-        {
-            return joinType;
-        }
-
-        /**
-         * @return the left column of the join condition
-         */
-        public final Column getLeftColumn()
-        {
-            return leftColumn;
-        }
-
-        /**
-         * @return the right column of the join condition
-         */
-        public final Column getRightColumn()
-        {
-            return rightColumn;
-        }
-
-        /**
-         * returns a String representation of the class,
-         * mainly for debuggung purposes.
-         *
-         * @return a String representation of the class
-         */
-        public String toString()
-        {
-            StringBuffer result = new StringBuffer();
-            if (joinType != null)
-            {
-                result.append(joinType)
-                        .append(" : ");
-            }
-            result.append(leftColumn.getSqlExpression())
-                    .append("=")
-                    .append(rightColumn.getSqlExpression())
-                    .append(" (ignoreCase not considered)");
-
-            return result.toString();
-        }
-
-        /**
-         * This method checks another Criteria.Join to see if they contain the
-         * same attributes.
-         */
-        public boolean equals(Object obj)
-        {
-            if (this == obj)
-            {
-                return true;
-            }
-
-            if ((obj == null) || !(obj instanceof Join))
-            {
-                return false;
-            }
-
-            Join join = (Join) obj;
-
-            return ObjectUtils.equals(
-                        leftColumn.getSqlExpression(),
-                        join.getLeftColumn().getSqlExpression())
-                    && ObjectUtils.equals(
-                        rightColumn.getSqlExpression(),
-                        join.getRightColumn().getSqlExpression())
-                    && ObjectUtils.equals(joinType, join.getJoinType());
-        }
-
-        /**
-         * Returns the hash code value for this Join.
-         *
-         * @return a hash code value for this object.
-         */
-        public int hashCode()
-        {
-            int result = 13;
-            result = 37 * result
-                    + leftColumn.getSqlExpression().hashCode();
-            result = 37 * result
-                    + rightColumn.getSqlExpression().hashCode();
-            result = 37 * result + (null == joinType ? 0 : joinType.hashCode());
-            return result;
-        }
-
-    } // end of inner class Join
 }

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java?rev=1224848&r1=1224847&r2=1224848&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/SummaryHelper.java Tue Dec 27 01:17:11 2011
@@ -36,6 +36,7 @@ import org.apache.commons.logging.LogFac
 import org.apache.torque.Column;
 import org.apache.torque.ColumnImpl;
 import org.apache.torque.TorqueException;
+import org.apache.torque.criteria.SqlEnum;
 import org.apache.torque.om.mapper.ObjectListMapper;
 import org.apache.torque.om.mapper.RecordMapper;
 import org.apache.torque.sql.SqlBuilder;



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