You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2013/02/20 22:06:37 UTC
svn commit: r1448414 [3/14] - in
/db/torque/torque4/trunk/torque-runtime/src: main/java/org/apache/torque/
main/java/org/apache/torque/adapter/ main/java/org/apache/torque/criteria/
main/java/org/apache/torque/map/ main/java/org/apache/torque/oid/ main...
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criteria.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=1448414&r1=1448413&r2=1448414&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java Wed Feb 20 21:06:35 2013
@@ -1,184 +1,184 @@
-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.
- *
- * @param <T> the implementation 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.
- */
-@Deprecated
-public interface CriteriaInterface<T>
-{
- /**
- * 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, ? extends Object> 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);
-
- /**
- * Get the Database(Map) name.
- *
- * @return A String with the Database(Map) name. May be null.
- */
- 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 BasePeerImpl.
- * @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 "ALL " to the SQL statement.
- */
- void setAll();
-
- /**
- * Adds "DISTINCT " 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.
- */
- long 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();
-
- /**
- * Set a limit for the query
- *
- * @param limit The upper limit for the number of records returned
- * by a query.
- * @return A modified Criteria object.
- */
- T setLimit(int limit);
-
- /**
- * Set the offset.
- *
- * @param offset how many records should be skipped at the start of the
- * result.
- * @return A modified Criteria object.
- */
- T setOffset(long offset);
-}
+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.
+ *
+ * @param <T> the implementation 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.
+ */
+@Deprecated
+public interface CriteriaInterface<T>
+{
+ /**
+ * 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, ? extends Object> 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);
+
+ /**
+ * Get the Database(Map) name.
+ *
+ * @return A String with the Database(Map) name. May be null.
+ */
+ 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 BasePeerImpl.
+ * @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 "ALL " to the SQL statement.
+ */
+ void setAll();
+
+ /**
+ * Adds "DISTINCT " 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.
+ */
+ long 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();
+
+ /**
+ * Set a limit for the query
+ *
+ * @param limit The upper limit for the number of records returned
+ * by a query.
+ * @return A modified Criteria object.
+ */
+ T setLimit(int limit);
+
+ /**
+ * Set the offset.
+ *
+ * @param offset how many records should be skipped at the start of the
+ * result.
+ * @return A modified Criteria object.
+ */
+ T setOffset(long offset);
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/CriteriaInterface.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=1448414&r1=1448413&r2=1448414&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java Wed Feb 20 21:06:35 2013
@@ -1,568 +1,568 @@
-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.collections.ListUtils;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.torque.Column;
-
-/**
- * Describes one or more where clause parts in the Criteria.
- * Either the parts list is not null and represents 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 the operator " OR ". */
- public static final String OR = " OR ";
-
- /**
- * Left-hand-side value of the comparison, may be null.
- * If this object implements the Column interface, it is interpreted as
- * a value computed by the database, otherwise as verbatim value.
- */
- private Object lValue;
-
- /** Comparison operator. Can only be null if sql is not null. */
- private SqlEnum comparison;
-
- /**
- * Right-hand-side value of the comparison, may be null.
- * If this object implements the Column interface, it is interpreted as
- * a value computed by the database, otherwise as verbatim value.
- */
- private Object rValue;
-
- /** A verbatim SQL for this Criterion. */
- private String sql;
-
- /**
- * Replacements for the placeholders in the verbatim SQL.
- * Is only used if sql is not null.
- */
- private Object[] preparedStatementReplacements;
-
- /** Flag to ignore case in comparison */
- 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.
- * Either this Criterion represents a comparison without verbatim SQL;
- * in this case the parameters lValue and comparison must be not null,
- * rValue may be not null and sql and preparedStatementReplacements must
- * be null; or it represents a verbatim sql condition, in which case
- * the parameter comparison must be null and the sql must be not null
- * (preparedStatementReplacements may be set to contain sql placeholder
- * replacement values, and lValue and rValue can be set to add columns
- * to the automatically computed from clause of the query).
- *
- * @param lValue the left hand side value of the comparison.
- * If this value should be a value from the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- * @param rValue the right hand side value of the comparison.
- * If this value should be a value from the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- * @param comparison The comparison operator. Either this parameter or
- * sql must be not null.
- * @param sql a verbatim sql condition. Either this parameter or
- * comparison must be not null.
- * @param preparedStatementReplacements Values for the placeholders
- * in the verbatim sql condition.
- *
- * @throws NullPointerException if column is null.
- */
- public Criterion(
- Object lValue,
- Object rValue,
- SqlEnum comparison,
- String sql,
- Object[] preparedStatementReplacements)
- {
- if (comparison != null
- && (sql != null || preparedStatementReplacements != null))
- {
- throw new IllegalArgumentException("Either comparison or "
- + "some of (sql, preparedStatementReplacements) "
- + "can be not null, not both");
- }
- if ((lValue == null || comparison == null)
- && (sql == null))
- {
- throw new IllegalArgumentException("Either the values"
- + "(lValue, comparison) or "
- + "sql must be not null");
- }
- this.lValue = lValue;
- this.comparison = comparison;
- this.rValue = rValue;
- this.sql = sql;
- this.preparedStatementReplacements = preparedStatementReplacements;
- }
-
- /**
- * Create a new instance without verbatim sql, using equals as
- * comparison operator.
- *
- * @param lValue the left hand side value of the comparison, not null.
- * If this value should be a value from the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- * @param rValue the right hand side value of the comparison.
- * If this value should be a value from the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- */
- public Criterion(Object lValue, Object rValue)
- {
- this(lValue, rValue, Criteria.EQUAL, null, null);
- }
-
- /**
- * Create a new instance without verbatim sql.
- *
- * @param lValue the left hand side value of the comparison, not null.
- * If this value should be a value from the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- * @param rValue the right hand side value of the comparison.
- * If this value should be a value from the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- * @param comparison The comparison operator, not null.
- */
- public Criterion(Object lValue, Object rValue, SqlEnum comparison)
- {
- this(lValue, rValue, comparison, null, null);
- }
-
- /**
- * Creates a shallow copy of the given Criterion.
- *
- * @param toCopy the Criterion to copy from, not null.
- */
- public Criterion(Criterion toCopy)
- {
- this.lValue = toCopy.lValue;
- this.comparison = toCopy.comparison;
- this.rValue = toCopy.rValue;
- this.sql = toCopy.sql;
- this.preparedStatementReplacements
- = toCopy.preparedStatementReplacements;
- this.ignoreCase = toCopy.ignoreCase;
- if (toCopy.parts != null)
- {
- this.parts = new ArrayList<Criterion>(toCopy.parts.size());
- for (Criterion part : toCopy.parts)
- {
- this.parts.add(new Criterion(part));
- }
- }
- this.conjunction = toCopy.conjunction;
- }
-
- /**
- * Get the left hand side value of the comparison.
- *
- * @return the left hand side value of the comparison.
- * If this value is a value computed by the database,
- * the object implements the
- * <code>org.apache.torque.Column</code> interface.
- */
- public Object getLValue()
- {
- return this.lValue;
- }
-
- /**
- * Set the left hand side value of the comparison.
- *
- * @param lValue the left hand side value of the comparison.
- * If this value is a value computed by the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- */
- public void setLValue(Object lValue)
- {
- this.lValue = lValue;
- }
-
- /**
- * Get the comparison.
- *
- * @return A String with the comparison, or null if this
- * Criterion represents a verbatim sql condition.
- */
- public SqlEnum getComparison()
- {
- return this.comparison;
- }
-
- /**
- * Get the right hand side value of the comparison.
- *
- * @return the right hand side value of the comparison.
- * If this value is a value computed by the database,
- * the object implements the
- * <code>org.apache.torque.Column</code> interface.
- */
- public Object getRValue()
- {
- return this.rValue;
- }
-
- /**
- * Set the right hand side value of the comparison.
- *
- * @param rValue the right hand side value of the comparison.
- * If this value is a value computed by the database,
- * the object must implement the
- * <code>org.apache.torque.Column</code> interface.
- */
- public void setRValue(Object rValue)
- {
- this.rValue = rValue;
- }
-
- /**
- * Returns the verbatim sql for this condition.
- *
- * @return the verbatim sql for this condition, or null if this
- * Criterion does not represent a verbatim sql condition.
- */
- public String getSql()
- {
- return sql;
- }
-
- /**
- * Returns the prepared statement replacements for a verbatim sql condition.
- *
- * @return the replacement values, or null.
- */
- public Object[] getPreparedStatementReplacements()
- {
- return preparedStatementReplacements;
- }
-
- /**
- * Returns whether this Criterion represents a verbatim sql condition.
- *
- * @return true if this Criterion represents a verbatim sql condition,
- * false if the sql is computed from lValue, comparison and rValue.
- */
- public boolean isVerbatimSqlCondition()
- {
- return (sql != null);
- }
-
- /**
- * Sets ignore case. ignoreCase is ignored for a verbatim sql statement.
- *
- * @param b True if case should be ignored.
- * @return A modified Criterion 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(new Criterion(criterion));
- }
- else
- {
- Criterion copy = new Criterion(this);
- parts = new ArrayList<Criterion>();
- parts.add(copy);
- parts.add(new Criterion(criterion));
- this.conjunction = conjunction;
- this.rValue = null;
- this.comparison = null;
- this.lValue = null;
- this.sql = null;
- this.preparedStatementReplacements = null;
- this.ignoreCase = false;
- }
- }
-
- /**
- * Appends a debug String representation of the Criterion
- * onto the String builder.
- */
- @SuppressWarnings("deprecation")
- public void appendTo(StringBuilder sb)
- {
- if (isComposite())
- {
- boolean first = true;
- for (Criterion part : parts)
- {
- if (!first)
- {
- sb.append(conjunction);
- }
- if (part.isComposite())
- {
- sb.append('(');
- }
- part.appendTo(sb);
- if (part.isComposite())
- {
- sb.append(')');
- }
- first = false;
- }
- }
- else
- {
- if (SqlEnum.CUSTOM == comparison)
- {
- if (rValue != null && !"".equals(rValue))
- {
- sb.append((String) rValue);
- }
- }
- else if (isVerbatimSqlCondition())
- {
- sb.append(sql);
- }
- else
- {
- String lValueDisplay;
- if (lValue instanceof Column)
- {
- lValueDisplay = ((Column) lValue).getSqlExpression();
- }
- else if (lValue != null)
- {
- lValueDisplay = lValue.toString();
- }
- else
- {
- lValueDisplay = "";
- }
- String rValueDisplay;
- if (rValue instanceof Column)
- {
- rValueDisplay = ((Column) rValue).getSqlExpression();
- }
- else if (rValue != null)
- {
- rValueDisplay = rValue.toString();
- }
- else
- {
- rValueDisplay = "";
- }
- sb.append(lValueDisplay)
- .append(comparison)
- .append(rValueDisplay);
- }
- }
- }
-
- /**
- * Build a string representation of the Criterion for debug purposes.
- *
- * @return A String with the representation of the Criterion.
- */
- @Override
- 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.
- */
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (obj.getClass() != this.getClass())
- {
- return false;
- }
-
- Criterion criterion = (Criterion) obj;
- EqualsBuilder equalsBuilder = new EqualsBuilder();
- equalsBuilder.append(criterion.lValue, this.lValue)
- .append(criterion.comparison, this.comparison)
- .append(criterion.rValue, this.rValue)
- .append(criterion.sql, this.sql)
- .append(criterion.preparedStatementReplacements,
- this.preparedStatementReplacements)
- .append(criterion.ignoreCase, this.ignoreCase)
- .append(criterion.parts, this.parts)
- .append(criterion.conjunction, this.conjunction);
- return equalsBuilder.isEquals();
- }
-
- /**
- * Returns a hash code value for the object.
- */
- @Override
- public int hashCode()
- {
- HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
- hashCodeBuilder.append(this.lValue)
- .append(this.comparison)
- .append(this.rValue)
- .append(this.sql)
- .append(this.preparedStatementReplacements)
- .append(this.ignoreCase)
- .append(this.parts)
- .append(this.conjunction);
- return hashCodeBuilder.toHashCode();
- }
-}
-
+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.collections.ListUtils;
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.torque.Column;
+
+/**
+ * Describes one or more where clause parts in the Criteria.
+ * Either the parts list is not null and represents 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 the operator " OR ". */
+ public static final String OR = " OR ";
+
+ /**
+ * Left-hand-side value of the comparison, may be null.
+ * If this object implements the Column interface, it is interpreted as
+ * a value computed by the database, otherwise as verbatim value.
+ */
+ private Object lValue;
+
+ /** Comparison operator. Can only be null if sql is not null. */
+ private SqlEnum comparison;
+
+ /**
+ * Right-hand-side value of the comparison, may be null.
+ * If this object implements the Column interface, it is interpreted as
+ * a value computed by the database, otherwise as verbatim value.
+ */
+ private Object rValue;
+
+ /** A verbatim SQL for this Criterion. */
+ private String sql;
+
+ /**
+ * Replacements for the placeholders in the verbatim SQL.
+ * Is only used if sql is not null.
+ */
+ private Object[] preparedStatementReplacements;
+
+ /** Flag to ignore case in comparison */
+ 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.
+ * Either this Criterion represents a comparison without verbatim SQL;
+ * in this case the parameters lValue and comparison must be not null,
+ * rValue may be not null and sql and preparedStatementReplacements must
+ * be null; or it represents a verbatim sql condition, in which case
+ * the parameter comparison must be null and the sql must be not null
+ * (preparedStatementReplacements may be set to contain sql placeholder
+ * replacement values, and lValue and rValue can be set to add columns
+ * to the automatically computed from clause of the query).
+ *
+ * @param lValue the left hand side value of the comparison.
+ * If this value should be a value from the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ * @param rValue the right hand side value of the comparison.
+ * If this value should be a value from the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ * @param comparison The comparison operator. Either this parameter or
+ * sql must be not null.
+ * @param sql a verbatim sql condition. Either this parameter or
+ * comparison must be not null.
+ * @param preparedStatementReplacements Values for the placeholders
+ * in the verbatim sql condition.
+ *
+ * @throws NullPointerException if column is null.
+ */
+ public Criterion(
+ Object lValue,
+ Object rValue,
+ SqlEnum comparison,
+ String sql,
+ Object[] preparedStatementReplacements)
+ {
+ if (comparison != null
+ && (sql != null || preparedStatementReplacements != null))
+ {
+ throw new IllegalArgumentException("Either comparison or "
+ + "some of (sql, preparedStatementReplacements) "
+ + "can be not null, not both");
+ }
+ if ((lValue == null || comparison == null)
+ && (sql == null))
+ {
+ throw new IllegalArgumentException("Either the values"
+ + "(lValue, comparison) or "
+ + "sql must be not null");
+ }
+ this.lValue = lValue;
+ this.comparison = comparison;
+ this.rValue = rValue;
+ this.sql = sql;
+ this.preparedStatementReplacements = preparedStatementReplacements;
+ }
+
+ /**
+ * Create a new instance without verbatim sql, using equals as
+ * comparison operator.
+ *
+ * @param lValue the left hand side value of the comparison, not null.
+ * If this value should be a value from the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ * @param rValue the right hand side value of the comparison.
+ * If this value should be a value from the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ */
+ public Criterion(Object lValue, Object rValue)
+ {
+ this(lValue, rValue, Criteria.EQUAL, null, null);
+ }
+
+ /**
+ * Create a new instance without verbatim sql.
+ *
+ * @param lValue the left hand side value of the comparison, not null.
+ * If this value should be a value from the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ * @param rValue the right hand side value of the comparison.
+ * If this value should be a value from the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ * @param comparison The comparison operator, not null.
+ */
+ public Criterion(Object lValue, Object rValue, SqlEnum comparison)
+ {
+ this(lValue, rValue, comparison, null, null);
+ }
+
+ /**
+ * Creates a shallow copy of the given Criterion.
+ *
+ * @param toCopy the Criterion to copy from, not null.
+ */
+ public Criterion(Criterion toCopy)
+ {
+ this.lValue = toCopy.lValue;
+ this.comparison = toCopy.comparison;
+ this.rValue = toCopy.rValue;
+ this.sql = toCopy.sql;
+ this.preparedStatementReplacements
+ = toCopy.preparedStatementReplacements;
+ this.ignoreCase = toCopy.ignoreCase;
+ if (toCopy.parts != null)
+ {
+ this.parts = new ArrayList<Criterion>(toCopy.parts.size());
+ for (Criterion part : toCopy.parts)
+ {
+ this.parts.add(new Criterion(part));
+ }
+ }
+ this.conjunction = toCopy.conjunction;
+ }
+
+ /**
+ * Get the left hand side value of the comparison.
+ *
+ * @return the left hand side value of the comparison.
+ * If this value is a value computed by the database,
+ * the object implements the
+ * <code>org.apache.torque.Column</code> interface.
+ */
+ public Object getLValue()
+ {
+ return this.lValue;
+ }
+
+ /**
+ * Set the left hand side value of the comparison.
+ *
+ * @param lValue the left hand side value of the comparison.
+ * If this value is a value computed by the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ */
+ public void setLValue(Object lValue)
+ {
+ this.lValue = lValue;
+ }
+
+ /**
+ * Get the comparison.
+ *
+ * @return A String with the comparison, or null if this
+ * Criterion represents a verbatim sql condition.
+ */
+ public SqlEnum getComparison()
+ {
+ return this.comparison;
+ }
+
+ /**
+ * Get the right hand side value of the comparison.
+ *
+ * @return the right hand side value of the comparison.
+ * If this value is a value computed by the database,
+ * the object implements the
+ * <code>org.apache.torque.Column</code> interface.
+ */
+ public Object getRValue()
+ {
+ return this.rValue;
+ }
+
+ /**
+ * Set the right hand side value of the comparison.
+ *
+ * @param rValue the right hand side value of the comparison.
+ * If this value is a value computed by the database,
+ * the object must implement the
+ * <code>org.apache.torque.Column</code> interface.
+ */
+ public void setRValue(Object rValue)
+ {
+ this.rValue = rValue;
+ }
+
+ /**
+ * Returns the verbatim sql for this condition.
+ *
+ * @return the verbatim sql for this condition, or null if this
+ * Criterion does not represent a verbatim sql condition.
+ */
+ public String getSql()
+ {
+ return sql;
+ }
+
+ /**
+ * Returns the prepared statement replacements for a verbatim sql condition.
+ *
+ * @return the replacement values, or null.
+ */
+ public Object[] getPreparedStatementReplacements()
+ {
+ return preparedStatementReplacements;
+ }
+
+ /**
+ * Returns whether this Criterion represents a verbatim sql condition.
+ *
+ * @return true if this Criterion represents a verbatim sql condition,
+ * false if the sql is computed from lValue, comparison and rValue.
+ */
+ public boolean isVerbatimSqlCondition()
+ {
+ return (sql != null);
+ }
+
+ /**
+ * Sets ignore case. ignoreCase is ignored for a verbatim sql statement.
+ *
+ * @param b True if case should be ignored.
+ * @return A modified Criterion 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(new Criterion(criterion));
+ }
+ else
+ {
+ Criterion copy = new Criterion(this);
+ parts = new ArrayList<Criterion>();
+ parts.add(copy);
+ parts.add(new Criterion(criterion));
+ this.conjunction = conjunction;
+ this.rValue = null;
+ this.comparison = null;
+ this.lValue = null;
+ this.sql = null;
+ this.preparedStatementReplacements = null;
+ this.ignoreCase = false;
+ }
+ }
+
+ /**
+ * Appends a debug String representation of the Criterion
+ * onto the String builder.
+ */
+ @SuppressWarnings("deprecation")
+ public void appendTo(StringBuilder sb)
+ {
+ if (isComposite())
+ {
+ boolean first = true;
+ for (Criterion part : parts)
+ {
+ if (!first)
+ {
+ sb.append(conjunction);
+ }
+ if (part.isComposite())
+ {
+ sb.append('(');
+ }
+ part.appendTo(sb);
+ if (part.isComposite())
+ {
+ sb.append(')');
+ }
+ first = false;
+ }
+ }
+ else
+ {
+ if (SqlEnum.CUSTOM == comparison)
+ {
+ if (rValue != null && !"".equals(rValue))
+ {
+ sb.append((String) rValue);
+ }
+ }
+ else if (isVerbatimSqlCondition())
+ {
+ sb.append(sql);
+ }
+ else
+ {
+ String lValueDisplay;
+ if (lValue instanceof Column)
+ {
+ lValueDisplay = ((Column) lValue).getSqlExpression();
+ }
+ else if (lValue != null)
+ {
+ lValueDisplay = lValue.toString();
+ }
+ else
+ {
+ lValueDisplay = "";
+ }
+ String rValueDisplay;
+ if (rValue instanceof Column)
+ {
+ rValueDisplay = ((Column) rValue).getSqlExpression();
+ }
+ else if (rValue != null)
+ {
+ rValueDisplay = rValue.toString();
+ }
+ else
+ {
+ rValueDisplay = "";
+ }
+ sb.append(lValueDisplay)
+ .append(comparison)
+ .append(rValueDisplay);
+ }
+ }
+ }
+
+ /**
+ * Build a string representation of the Criterion for debug purposes.
+ *
+ * @return A String with the representation of the Criterion.
+ */
+ @Override
+ 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.
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (obj.getClass() != this.getClass())
+ {
+ return false;
+ }
+
+ Criterion criterion = (Criterion) obj;
+ EqualsBuilder equalsBuilder = new EqualsBuilder();
+ equalsBuilder.append(criterion.lValue, this.lValue)
+ .append(criterion.comparison, this.comparison)
+ .append(criterion.rValue, this.rValue)
+ .append(criterion.sql, this.sql)
+ .append(criterion.preparedStatementReplacements,
+ this.preparedStatementReplacements)
+ .append(criterion.ignoreCase, this.ignoreCase)
+ .append(criterion.parts, this.parts)
+ .append(criterion.conjunction, this.conjunction);
+ return equalsBuilder.isEquals();
+ }
+
+ /**
+ * Returns a hash code value for the object.
+ */
+ @Override
+ public int hashCode()
+ {
+ HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
+ hashCodeBuilder.append(this.lValue)
+ .append(this.comparison)
+ .append(this.rValue)
+ .append(this.sql)
+ .append(this.preparedStatementReplacements)
+ .append(this.ignoreCase)
+ .append(this.parts)
+ .append(this.conjunction);
+ return hashCodeBuilder.toHashCode();
+ }
+}
+
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Criterion.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java?rev=1448414&r1=1448413&r2=1448414&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java Wed Feb 20 21:06:35 2013
@@ -1,261 +1,261 @@
-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.List;
-
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-
-/**
- * This class describes an Element in the From-part of a SQL clause.
- * It must contain the name of the database table.
- * It might contain an alias for the table name, a join type
- * a join condition and prepared statement replacements.
- * The class is immutable.
- */
-public class FromElement implements Serializable
-{
- /** serial Version UID. */
- private static final long serialVersionUID = 1L;
-
- /**
- * The fromExpression, e.g. a simple table name or a table name
- * or a subquery with an appended alias name.
- */
- private String fromExpression = null;
-
- /** The type of the join, e.g. JoinType.LEFT_JOIN */
- private JoinType joinType = null;
-
- /** The join condition, e.g. table_a.id = table_b.a_id */
- private String joinCondition = null;
-
- /** The replacements which might occur in the fromExpression. */
- private final List<Object> preparedStatementReplacements
- = new ArrayList<Object>();
-
- /**
- * Constructor with join type null and joinCondition null.
- *
- * @param tableName the table name, might contain an appended alias name
- * e.g. <br />
- * table_1<br />
- * table_1 alias_for_table_1
- */
- public FromElement(String tableName)
- {
- this(tableName, null, null, null);
- }
-
- /**
- * Constructor.
- *
- * @param fromExpression the expression to add to the from clause,
- * e.g. a simple table name or a table name with an alias,
- * e.g. <br />
- * table_1<br />
- * table_1 alias_for_table_1
- * @param joinType the type of the join, e.g. JoinType.LEFT_JOIN,
- * or null if no excplicit join is wanted
- * @param joinCondition the join condition,
- * e.g. table_a.id = table_b.a_id,
- * or null if no explicit join is wanted
- * (In this case, the join condition is appended to the
- * whereClause instead)
- */
- public FromElement(
- String fromExpression,
- JoinType joinType,
- String joinCondition)
- {
- this(fromExpression, joinType, joinCondition, null);
- }
-
- /**
- * Constructor.
- *
- * @param fromExpression the expression to add to the from clause,
- * e.g. a simple table name or a table name with an alias,
- * e.g. <br />
- * table_1<br />
- * table_1 alias_for_table_1
- * @param joinType the type of the join, e.g. JoinType.LEFT_JOIN,
- * or null if no explicit join is wanted
- * @param joinCondition the join condition,
- * e.g. table_a.id = table_b.a_id,
- * or null if no explicit join is wanted
- * (In this case, the join condition is appended to the
- * whereClause instead)
- * @param preparedStatementReplacements the replacements for placeholders
- * which might occur in the fromExpression, may be null.
- */
- public FromElement(
- String fromExpression,
- JoinType joinType,
- String joinCondition,
- List<Object> preparedStatementReplacements)
- {
- this.fromExpression = fromExpression;
- this.joinType = joinType;
- this.joinCondition = joinCondition;
- if (preparedStatementReplacements != null)
- {
- this.preparedStatementReplacements.addAll(
- preparedStatementReplacements);
- }
- }
-
- /**
- * Constructor.
- *
- * @param fromExpression the expression to add to the from clause,
- * e.g. a simple table name or a table name with an alias,
- * e.g. <br />
- * table_1<br />
- * table_1 alias_for_table_1
- * @param joinType the type of the join, e.g. JoinType.LEFT_JOIN,
- * or null if no explicit join is wanted
- * @param joinCondition the join condition,
- * e.g. table_a.id = table_b.a_id, not null.
- */
- public FromElement(
- String fromExpression,
- JoinType joinType,
- PreparedStatementPart joinCondition)
- {
- this(fromExpression,
- joinType,
- joinCondition.getSql().toString(),
- joinCondition.getPreparedStatementReplacements());
- }
-
-
- /**
- * Returns the join condition.
- *
- * @return the join condition, e.g. table_a.id = table_b.a_id,
- * or null if the join is not an explicit join
- */
- public String getJoinCondition()
- {
- return joinCondition;
- }
-
- /**
- * Returns the join type.
- *
- * @return the type of the join, e.g. JoinType.LEFT_JOIN,
- * or null if the join is not an explicit join
- */
- public JoinType getJoinType()
- {
- return joinType;
- }
-
- /**
- * Returns the fromExpression, which might e.g. be a simple table name or
- * a table name or a subquery with an alias appended.
- *
- * @return the tablename, might contain an appended alias name,
- * e.g. <br />
- * table_1<br />
- * table_1 alias_for_table_1
- *
- */
- public String getFromExpression()
- {
- return fromExpression;
- }
-
- /**
- * Returns the replacements for prepared statement placeholders in the
- * fromExpression.
- *
- * @return the replacements, not null.
-
- */
- public List<Object> getPreparedStatementReplacements()
- {
- return preparedStatementReplacements;
- }
-
- /**
- * Returns a SQL representation of the element.
- *
- * @return a SQL representation of the element
- */
- @Override
- public String toString()
- {
- StringBuffer result = new StringBuffer();
- if (joinType != null)
- {
- result.append(joinType);
- }
- result.append(fromExpression);
- if (joinCondition != null)
- {
- result.append(SqlEnum.ON);
- result.append(joinCondition);
- }
- return result.toString();
- }
-
-
- @Override
- public int hashCode()
- {
- return new HashCodeBuilder()
- .append(joinCondition)
- .append(joinType)
- .append(fromExpression)
- .append(preparedStatementReplacements)
- .toHashCode();
- }
-
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null)
- {
- return false;
- }
- if (getClass() != obj.getClass())
- {
- return false;
- }
- FromElement other = (FromElement) obj;
- return new EqualsBuilder()
- .append(joinCondition, other.joinCondition)
- .append(joinType, other.joinType)
- .append(fromExpression, other.fromExpression)
- .append(preparedStatementReplacements,
- other.preparedStatementReplacements)
- .isEquals();
- }
-}
+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.List;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
+/**
+ * This class describes an Element in the From-part of a SQL clause.
+ * It must contain the name of the database table.
+ * It might contain an alias for the table name, a join type
+ * a join condition and prepared statement replacements.
+ * The class is immutable.
+ */
+public class FromElement implements Serializable
+{
+ /** serial Version UID. */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The fromExpression, e.g. a simple table name or a table name
+ * or a subquery with an appended alias name.
+ */
+ private String fromExpression = null;
+
+ /** The type of the join, e.g. JoinType.LEFT_JOIN */
+ private JoinType joinType = null;
+
+ /** The join condition, e.g. table_a.id = table_b.a_id */
+ private String joinCondition = null;
+
+ /** The replacements which might occur in the fromExpression. */
+ private final List<Object> preparedStatementReplacements
+ = new ArrayList<Object>();
+
+ /**
+ * Constructor with join type null and joinCondition null.
+ *
+ * @param tableName the table name, might contain an appended alias name
+ * e.g. <br />
+ * table_1<br />
+ * table_1 alias_for_table_1
+ */
+ public FromElement(String tableName)
+ {
+ this(tableName, null, null, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param fromExpression the expression to add to the from clause,
+ * e.g. a simple table name or a table name with an alias,
+ * e.g. <br />
+ * table_1<br />
+ * table_1 alias_for_table_1
+ * @param joinType the type of the join, e.g. JoinType.LEFT_JOIN,
+ * or null if no excplicit join is wanted
+ * @param joinCondition the join condition,
+ * e.g. table_a.id = table_b.a_id,
+ * or null if no explicit join is wanted
+ * (In this case, the join condition is appended to the
+ * whereClause instead)
+ */
+ public FromElement(
+ String fromExpression,
+ JoinType joinType,
+ String joinCondition)
+ {
+ this(fromExpression, joinType, joinCondition, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param fromExpression the expression to add to the from clause,
+ * e.g. a simple table name or a table name with an alias,
+ * e.g. <br />
+ * table_1<br />
+ * table_1 alias_for_table_1
+ * @param joinType the type of the join, e.g. JoinType.LEFT_JOIN,
+ * or null if no explicit join is wanted
+ * @param joinCondition the join condition,
+ * e.g. table_a.id = table_b.a_id,
+ * or null if no explicit join is wanted
+ * (In this case, the join condition is appended to the
+ * whereClause instead)
+ * @param preparedStatementReplacements the replacements for placeholders
+ * which might occur in the fromExpression, may be null.
+ */
+ public FromElement(
+ String fromExpression,
+ JoinType joinType,
+ String joinCondition,
+ List<Object> preparedStatementReplacements)
+ {
+ this.fromExpression = fromExpression;
+ this.joinType = joinType;
+ this.joinCondition = joinCondition;
+ if (preparedStatementReplacements != null)
+ {
+ this.preparedStatementReplacements.addAll(
+ preparedStatementReplacements);
+ }
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param fromExpression the expression to add to the from clause,
+ * e.g. a simple table name or a table name with an alias,
+ * e.g. <br />
+ * table_1<br />
+ * table_1 alias_for_table_1
+ * @param joinType the type of the join, e.g. JoinType.LEFT_JOIN,
+ * or null if no explicit join is wanted
+ * @param joinCondition the join condition,
+ * e.g. table_a.id = table_b.a_id, not null.
+ */
+ public FromElement(
+ String fromExpression,
+ JoinType joinType,
+ PreparedStatementPart joinCondition)
+ {
+ this(fromExpression,
+ joinType,
+ joinCondition.getSql().toString(),
+ joinCondition.getPreparedStatementReplacements());
+ }
+
+
+ /**
+ * Returns the join condition.
+ *
+ * @return the join condition, e.g. table_a.id = table_b.a_id,
+ * or null if the join is not an explicit join
+ */
+ public String getJoinCondition()
+ {
+ return joinCondition;
+ }
+
+ /**
+ * Returns the join type.
+ *
+ * @return the type of the join, e.g. JoinType.LEFT_JOIN,
+ * or null if the join is not an explicit join
+ */
+ public JoinType getJoinType()
+ {
+ return joinType;
+ }
+
+ /**
+ * Returns the fromExpression, which might e.g. be a simple table name or
+ * a table name or a subquery with an alias appended.
+ *
+ * @return the tablename, might contain an appended alias name,
+ * e.g. <br />
+ * table_1<br />
+ * table_1 alias_for_table_1
+ *
+ */
+ public String getFromExpression()
+ {
+ return fromExpression;
+ }
+
+ /**
+ * Returns the replacements for prepared statement placeholders in the
+ * fromExpression.
+ *
+ * @return the replacements, not null.
+
+ */
+ public List<Object> getPreparedStatementReplacements()
+ {
+ return preparedStatementReplacements;
+ }
+
+ /**
+ * Returns a SQL representation of the element.
+ *
+ * @return a SQL representation of the element
+ */
+ @Override
+ public String toString()
+ {
+ StringBuffer result = new StringBuffer();
+ if (joinType != null)
+ {
+ result.append(joinType);
+ }
+ result.append(fromExpression);
+ if (joinCondition != null)
+ {
+ result.append(SqlEnum.ON);
+ result.append(joinCondition);
+ }
+ return result.toString();
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder()
+ .append(joinCondition)
+ .append(joinType)
+ .append(fromExpression)
+ .append(preparedStatementReplacements)
+ .toHashCode();
+ }
+
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ FromElement other = (FromElement) obj;
+ return new EqualsBuilder()
+ .append(joinCondition, other.joinCondition)
+ .append(joinType, other.joinType)
+ .append(fromExpression, other.fromExpression)
+ .append(preparedStatementReplacements,
+ other.preparedStatementReplacements)
+ .isEquals();
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/FromElement.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: 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=1448414&r1=1448413&r2=1448414&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Join.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Join.java Wed Feb 20 21:06:35 2013
@@ -1,219 +1,219 @@
-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>
- */
-public class Join implements Serializable
-{
- /** Version id for serializing. */
- private static final long serialVersionUID = 1L;
-
- /** The join condition, not null. */
- private Criterion joinCondition = null;
-
- /**
- * The left table of the join,
- * or null to be determined from join condition.
- */
- private PreparedStatementPart leftTable = null;
-
- /**
- * The right table of the join,
- * or null to be determined from join condition.
- */
- private PreparedStatementPart rightTable = null;
- /**
- * The type of the join (LEFT JOIN, ...),
- * or null for an implicit inner join.
- */
- private JoinType joinType = null;
-
- /**
- * Constructor with the comparison operator.
- *
- * @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 comparison the comparison, not null.
- * The operator CUSTOM is not supported.
- * @param joinType the type of the join, or null
- * (adding the join condition to the where clause).
- *
- * @throws NullPointerException if leftColumn, comparison or rightColumn
- * are null.
- * @throws IllegalArgumentException if comparison id SqlEnum.CUSTOM
- */
- @SuppressWarnings("deprecation")
- public Join(
- final Column leftColumn,
- final Column rightColumn,
- final SqlEnum comparison,
- final JoinType joinType)
- {
- if (leftColumn == null)
- {
- throw new NullPointerException("leftColumn is null");
- }
- if (rightColumn == null)
- {
- throw new NullPointerException("rightColumn is null");
- }
- if (comparison == null)
- {
- throw new NullPointerException("comparison is null");
- }
- if (comparison == SqlEnum.CUSTOM)
- {
- throw new IllegalArgumentException(
- "The comparison SqlEnum.CUSTOM is not supported for Joins.");
- }
- this.joinCondition = new Criterion(leftColumn, rightColumn, comparison);
- this.joinType = joinType;
- }
-
- /**
- * Constructor.
- *
- * @param leftTable the left table of the join, might contain an alias name,
- * or null to be determined from the join clause.
- * @param rightTable the right table of the join, might contain an alias
- * name, or null to be determined from the join clause.
- * @param joinCondition the join condition, not null.
- * @param joinType the type of the join, or null
- * (adding the join condition to the where clause).
- */
- public Join(
- final PreparedStatementPart leftTable,
- final PreparedStatementPart rightTable,
- final Criterion joinCondition,
- final JoinType joinType)
- {
- if (joinCondition == null)
- {
- throw new NullPointerException("joinCondition is null");
- }
- this.leftTable = leftTable;
- this.rightTable = rightTable;
- this.joinCondition = joinCondition;
- 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 Criterion getJoinCondition()
- {
- return joinCondition;
- }
-
- /**
- * @return the type of the join, i.e. SqlEnum.LEFT_JOIN, ...,
- * or null for adding the join condition to the where Clause
- */
- public final JoinType getJoinType()
- {
- return joinType;
- }
-
- /**
- * @return the left table of the join condition.
- */
- public final PreparedStatementPart getLeftTable()
- {
- return leftTable;
- }
-
- /**
- * @return the right table of the join condition.
- */
- public final PreparedStatementPart getRightTable()
- {
- return rightTable;
- }
-
- /**
- * Returns a String representation of the class,
- * mainly for debugging purposes.
- *
- * @return a String representation of the class
- */
- @Override
- public String toString()
- {
-
- return joinType + "(" + leftTable + ", " + rightTable + "): "
- + joinCondition.toString();
- }
-
- /**
- * This method checks another Criteria.Join to see if they contain the
- * same attributes.
- */
- @Override
- 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(leftTable, join.leftTable)
- .append(rightTable, join.rightTable)
- .append(joinCondition, join.joinCondition)
- .append(joinType, join.getJoinType())
- .isEquals();
- }
-
- /**
- * Returns the hash code value for this Join.
- *
- * @return a hash code value for this object.
- */
- @Override
- public int hashCode()
- {
- return new HashCodeBuilder()
- .append(leftTable)
- .append(rightTable)
- .append(joinCondition)
- .append(joinType)
- .toHashCode();
- }
-}
+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>
+ */
+public class Join implements Serializable
+{
+ /** Version id for serializing. */
+ private static final long serialVersionUID = 1L;
+
+ /** The join condition, not null. */
+ private Criterion joinCondition = null;
+
+ /**
+ * The left table of the join,
+ * or null to be determined from join condition.
+ */
+ private PreparedStatementPart leftTable = null;
+
+ /**
+ * The right table of the join,
+ * or null to be determined from join condition.
+ */
+ private PreparedStatementPart rightTable = null;
+ /**
+ * The type of the join (LEFT JOIN, ...),
+ * or null for an implicit inner join.
+ */
+ private JoinType joinType = null;
+
+ /**
+ * Constructor with the comparison operator.
+ *
+ * @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 comparison the comparison, not null.
+ * The operator CUSTOM is not supported.
+ * @param joinType the type of the join, or null
+ * (adding the join condition to the where clause).
+ *
+ * @throws NullPointerException if leftColumn, comparison or rightColumn
+ * are null.
+ * @throws IllegalArgumentException if comparison id SqlEnum.CUSTOM
+ */
+ @SuppressWarnings("deprecation")
+ public Join(
+ final Column leftColumn,
+ final Column rightColumn,
+ final SqlEnum comparison,
+ final JoinType joinType)
+ {
+ if (leftColumn == null)
+ {
+ throw new NullPointerException("leftColumn is null");
+ }
+ if (rightColumn == null)
+ {
+ throw new NullPointerException("rightColumn is null");
+ }
+ if (comparison == null)
+ {
+ throw new NullPointerException("comparison is null");
+ }
+ if (comparison == SqlEnum.CUSTOM)
+ {
+ throw new IllegalArgumentException(
+ "The comparison SqlEnum.CUSTOM is not supported for Joins.");
+ }
+ this.joinCondition = new Criterion(leftColumn, rightColumn, comparison);
+ this.joinType = joinType;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param leftTable the left table of the join, might contain an alias name,
+ * or null to be determined from the join clause.
+ * @param rightTable the right table of the join, might contain an alias
+ * name, or null to be determined from the join clause.
+ * @param joinCondition the join condition, not null.
+ * @param joinType the type of the join, or null
+ * (adding the join condition to the where clause).
+ */
+ public Join(
+ final PreparedStatementPart leftTable,
+ final PreparedStatementPart rightTable,
+ final Criterion joinCondition,
+ final JoinType joinType)
+ {
+ if (joinCondition == null)
+ {
+ throw new NullPointerException("joinCondition is null");
+ }
+ this.leftTable = leftTable;
+ this.rightTable = rightTable;
+ this.joinCondition = joinCondition;
+ 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 Criterion getJoinCondition()
+ {
+ return joinCondition;
+ }
+
+ /**
+ * @return the type of the join, i.e. SqlEnum.LEFT_JOIN, ...,
+ * or null for adding the join condition to the where Clause
+ */
+ public final JoinType getJoinType()
+ {
+ return joinType;
+ }
+
+ /**
+ * @return the left table of the join condition.
+ */
+ public final PreparedStatementPart getLeftTable()
+ {
+ return leftTable;
+ }
+
+ /**
+ * @return the right table of the join condition.
+ */
+ public final PreparedStatementPart getRightTable()
+ {
+ return rightTable;
+ }
+
+ /**
+ * Returns a String representation of the class,
+ * mainly for debugging purposes.
+ *
+ * @return a String representation of the class
+ */
+ @Override
+ public String toString()
+ {
+
+ return joinType + "(" + leftTable + ", " + rightTable + "): "
+ + joinCondition.toString();
+ }
+
+ /**
+ * This method checks another Criteria.Join to see if they contain the
+ * same attributes.
+ */
+ @Override
+ 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(leftTable, join.leftTable)
+ .append(rightTable, join.rightTable)
+ .append(joinCondition, join.joinCondition)
+ .append(joinType, join.getJoinType())
+ .isEquals();
+ }
+
+ /**
+ * Returns the hash code value for this Join.
+ *
+ * @return a hash code value for this object.
+ */
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder()
+ .append(leftTable)
+ .append(rightTable)
+ .append(joinCondition)
+ .append(joinType)
+ .toHashCode();
+ }
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/Join.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/JoinType.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/JoinType.java?rev=1448414&r1=1448413&r2=1448414&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/JoinType.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/JoinType.java Wed Feb 20 21:06:35 2013
@@ -1,59 +1,59 @@
-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.
- */
-/**
- *
- * The possible explicit join types.
- *
- * @version $Id$
- */
-public enum JoinType
-{
- /** SQL Expression " LEFT JOIN ". */
- LEFT_JOIN(" LEFT JOIN "),
- /** SQL Expression " RIGHT JOIN ". */
- RIGHT_JOIN(" RIGHT JOIN "),
- /** SQL Expression " INNER JOIN ". */
- INNER_JOIN(" INNER JOIN ");
-
- /** The SQL expression for the join type. */
- private String sql;
-
- /**
- * Constructor.
- *
- * @param sql The SQL expression for the join type.
- */
- private JoinType(String sql)
- {
- this.sql = sql;
- }
-
- /**
- * Returns the SQL expression for the join type.
- *
- * @return the SQL expression, not null.
- */
- public String toString()
- {
- return sql;
- }
-
-}
+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.
+ */
+/**
+ *
+ * The possible explicit join types.
+ *
+ * @version $Id$
+ */
+public enum JoinType
+{
+ /** SQL Expression " LEFT JOIN ". */
+ LEFT_JOIN(" LEFT JOIN "),
+ /** SQL Expression " RIGHT JOIN ". */
+ RIGHT_JOIN(" RIGHT JOIN "),
+ /** SQL Expression " INNER JOIN ". */
+ INNER_JOIN(" INNER JOIN ");
+
+ /** The SQL expression for the join type. */
+ private String sql;
+
+ /**
+ * Constructor.
+ *
+ * @param sql The SQL expression for the join type.
+ */
+ private JoinType(String sql)
+ {
+ this.sql = sql;
+ }
+
+ /**
+ * Returns the SQL expression for the join type.
+ *
+ * @return the SQL expression, not null.
+ */
+ public String toString()
+ {
+ return sql;
+ }
+
+}
Propchange: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/criteria/JoinType.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org