You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by br...@apache.org on 2006/01/08 13:39:56 UTC
svn commit: r367025 [1/2] - in
/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker:
accesslayer/ accesslayer/sql/ core/ query/ util/
Author: brj
Date: Sun Jan 8 04:39:31 2006
New Revision: 367025
URL: http://svn.apache.org/viewcvs?rev=367025&view=rev
Log:
Backported Criteria from ojb 1.x
Added:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractCriterion.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criterion.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/IdentityCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriterion.java
Modified:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/BetweenCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/CriteriaUtils.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/ExistsCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/FieldCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/LikeCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/NullCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Query.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryByCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/SelectionCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/SqlCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/UserAlias.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/ValueCriteria.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/StatementManager.java Sun Jan 8 04:39:31 2006
@@ -41,7 +41,7 @@
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.ExistsCriteria;
import org.apache.ojb.broker.query.FieldCriteria;
-import org.apache.ojb.broker.query.InCriteria;
+import org.apache.ojb.broker.query.InCriterion;
import org.apache.ojb.broker.query.NullCriteria;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.SelectionCriteria;
@@ -307,7 +307,7 @@
* @param cld the ClassDescriptor
* @return next index for PreparedStatement
*/
- private int bindStatement(PreparedStatement stmt, int index, InCriteria crit, ClassDescriptor cld) throws SQLException
+ private int bindStatement(PreparedStatement stmt, int index, InCriterion crit, ClassDescriptor cld) throws SQLException
{
if (crit.getValue() instanceof Collection)
{
@@ -412,8 +412,8 @@
index = bindStatement(stmt, index, (NullCriteria) crit);
else if (crit instanceof BetweenCriteria)
index = bindStatement(stmt, index, (BetweenCriteria) crit, cld);
- else if (crit instanceof InCriteria)
- index = bindStatement(stmt, index, (InCriteria) crit, cld);
+ else if (crit instanceof InCriterion)
+ index = bindStatement(stmt, index, (InCriterion) crit, cld);
else if (crit instanceof SqlCriteria)
index = bindStatement(stmt, index, (SqlCriteria) crit);
else if (crit instanceof FieldCriteria)
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlGeneratorDefaultImpl.java Sun Jan 8 04:39:31 2006
@@ -27,7 +27,7 @@
import org.apache.ojb.broker.query.Criteria;
import org.apache.ojb.broker.query.ExistsCriteria;
import org.apache.ojb.broker.query.FieldCriteria;
-import org.apache.ojb.broker.query.InCriteria;
+import org.apache.ojb.broker.query.InCriterion;
import org.apache.ojb.broker.query.NullCriteria;
import org.apache.ojb.broker.query.Query;
import org.apache.ojb.broker.query.SelectionCriteria;
@@ -407,8 +407,8 @@
if (c instanceof BetweenCriteria)
return toSQLClause((BetweenCriteria) c, cld);
- if (c instanceof InCriteria)
- return toSQLClause((InCriteria) c);
+ if (c instanceof InCriterion)
+ return toSQLClause((InCriterion) c);
if (c instanceof SqlCriteria)
return toSQLClause((SqlCriteria) c);
@@ -473,11 +473,11 @@
}
/**
- * Answer the SQL-Clause for an InCriteria
+ * Answer the SQL-Clause for an InCriterion
*
* @param c SelectionCriteria
*/
- private String toSQLClause(InCriteria c)
+ private String toSQLClause(InCriterion c)
{
StringBuffer buf = new StringBuffer();
Collection values = (Collection) c.getValue();
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java Sun Jan 8 04:39:31 2006
@@ -38,6 +38,7 @@
import org.apache.ojb.broker.query.ExistsCriteria;
import org.apache.ojb.broker.query.FieldCriteria;
import org.apache.ojb.broker.query.InCriteria;
+import org.apache.ojb.broker.query.InCriterion;
import org.apache.ojb.broker.query.LikeCriteria;
import org.apache.ojb.broker.query.MtoNQuery;
import org.apache.ojb.broker.query.NullCriteria;
@@ -220,7 +221,8 @@
/**
* pathName might be an alias, so check this first
*/
- tableAlias = getTableAlias(pathName, useOuterJoins, new UserAlias(pathName, pathName, pathName), null, pathClasses);
+// tableAlias = getTableAlias(pathName, useOuterJoins, new UserAlias(pathName, pathName, pathName), null, pathClasses);
+ tableAlias = getTableAlias(pathName, useOuterJoins, aUserAlias, null, pathClasses);
}
if (tableAlias != null)
@@ -760,7 +762,7 @@
* @param c InCriteria
* @param buf
*/
- private void appendInCriteria(TableAlias alias, PathInfo pathInfo, InCriteria c, StringBuffer buf)
+ private void appendInCriteria(TableAlias alias, PathInfo pathInfo, InCriterion c, StringBuffer buf)
{
appendColName(alias, pathInfo, c.isTranslateAttribute(), buf);
buf.append(c.getClause());
@@ -861,9 +863,9 @@
{
appendBetweenCriteria(alias, pathInfo, (BetweenCriteria) c, buf);
}
- else if (c instanceof InCriteria)
+ else if (c instanceof InCriterion)
{
- appendInCriteria(alias, pathInfo, (InCriteria) c, buf);
+ appendInCriteria(alias, pathInfo, (InCriterion) c, buf);
}
else if (c instanceof SqlCriteria)
{
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/core/PersistenceBrokerImpl.java Sun Jan 8 04:39:31 2006
@@ -2059,6 +2059,8 @@
throws PersistenceBrokerException
{
query.setFetchSize(1);
+ query.preprocess(this);
+
if (query instanceof QueryBySQL)
{
if(logger.isDebugEnabled()) logger.debug("Creating SQL-RsIterator for class ["+cld.getClassNameOfObject()+"]");
Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractCriterion.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractCriterion.java?rev=367025&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractCriterion.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractCriterion.java Sun Jan 8 04:39:31 2006
@@ -0,0 +1,53 @@
+package org.apache.ojb.broker.query;
+
+/* Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import org.apache.ojb.broker.PersistenceBrokerInternal;
+
+/**
+ * Abstract Implementation of Criterion.
+ *
+ * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
+ * @version $Id: AbstractCriterion.java 364328 2004-12-01 20:08:27Z brj $
+ */
+public abstract class AbstractCriterion implements Criterion
+{
+ private Criterion m_parentCriterion = null;
+
+ /**
+ * @see org.apache.ojb.broker.query.Criterion#preprocess(org.apache.ojb.broker.PersistenceBrokerInternal)
+ */
+ public void preprocess(PersistenceBrokerInternal aPb)
+ {
+ // do nothing
+ }
+
+ /**
+ * @see org.apache.ojb.broker.query.Criterion#getParentCriterion()
+ */
+ public Criterion getParentCriterion()
+ {
+ return m_parentCriterion;
+ }
+
+ /**
+ * @param criteria
+ */
+ protected void setParentCriterion(Criterion parent)
+ {
+ m_parentCriterion = parent;
+ }
+
+}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/AbstractQueryImpl.java Sun Jan 8 04:39:31 2006
@@ -18,6 +18,8 @@
import java.io.Serializable;
import java.util.List;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
+
/**
* Abstract implemenation of Query interface
*
@@ -174,6 +176,14 @@
public int getFetchSize()
{
return fetchSize;
+ }
+
+ /**
+ * @see org.apache.ojb.broker.query.Query#preprocess(org.apache.ojb.broker.PersistenceBrokerInternal)
+ */
+ public void preprocess(PersistenceBrokerInternal aPb)
+ {
+ // do nothing
}
}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/BetweenCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/BetweenCriteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/BetweenCriteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/BetweenCriteria.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,7 @@
package org.apache.ojb.broker.query;
-/* Copyright 2002-2005 The Apache Software Foundation
+
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,20 +24,16 @@
*/
public class BetweenCriteria extends ValueCriteria
{
+ private static final long serialVersionUID = 9133718225959345499L;
+
private Object value2;
- BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, String aClause, String anAlias)
+ BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, String aClause)
{
- super(anAttribute, aValue1, aClause, anAlias);
+ super(anAttribute, aValue1, aClause);
setValue2(aValue2);
}
- // PAW
- BetweenCriteria(Object anAttribute, Object aValue1, Object aValue2, String aClause, UserAlias aUserAlias)
- {
- super(anAttribute, aValue1, aClause, aUserAlias);
- setValue2(aValue2);
- }
/**
* sets the value of the criteria to newValue.
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criteria.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.query;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,17 +17,18 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.StringTokenizer;
import java.util.Vector;
-import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
import org.apache.ojb.broker.metadata.FieldHelper;
-import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
-import org.apache.ojb.broker.util.configuration.ConfigurationException;
/**
* Persistent Criteria can be used to retrieve sets of objects based on their attributes
@@ -45,7 +46,7 @@
* @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
* @version $Id$
*/
-public class Criteria implements java.io.Serializable
+public class Criteria extends AbstractCriterion
{
static final long serialVersionUID = 7384550404778187808L;
@@ -59,33 +60,21 @@
/** prefix to identify attributes referencing enclosing query */
public static final String PARENT_QUERY_PREFIX = "parentQuery.";
- private Vector m_criteria;
+ private List m_criteria;
private int m_type;
private boolean m_embraced;
private boolean m_negative = false;
- // holding CriteriaFields for orderBy and groupBy
- private List orderby = null;
- private List groupby = null;
- private List prefetchedRelationships = null;
-
- // an optional alias to be used for this criteria
- private String m_alias = null;
-
- // PAW
- // an aliasPath to be used for this criteria
- private String m_aliasPath = null;
-
// holds the path segment(s) to which the alias applies
private UserAlias m_userAlias = null;
- /** the max. number of parameters in a IN-statement */
- protected static final int IN_LIMIT = getSqlInLimit();
+ // holding CriteriaFields for orderBy and groupBy
+ private List m_orderby = null;
+ private List m_groupby = null;
+ private List m_prefetchedRelationships = null;
private QueryByCriteria m_query;
- private Criteria m_parentCriteria;
- // PAW
// hint classes for paths of this criteria
private Map m_pathClasses;
@@ -94,10 +83,10 @@
*/
public Criteria()
{
- m_criteria = new Vector();
- groupby = new ArrayList();
- orderby = new ArrayList();
- prefetchedRelationships = new ArrayList();
+ m_criteria = new ArrayList();
+ m_groupby = new ArrayList();
+ m_orderby = new ArrayList();
+ m_prefetchedRelationships = new ArrayList();
m_type = NONE;
m_embraced = false;
// PAW
@@ -105,7 +94,8 @@
}
/**
- * Constructor with a SelectionCriteria
+ * Constructor with a SelectionCriteria.
+ *
* @param aSelectionCriteria SelectionCriteria
*/
public Criteria(SelectionCriteria aSelectionCriteria)
@@ -115,45 +105,46 @@
}
/**
- * make a copy of the criteria
- * @param includeGroupBy if true
- * @param includeOrderBy if ture
- * @param includePrefetchedRelationships if true
- * @return a copy of the criteria
+ * Copy Constructor.
+ *
+ * @param aCriteria Criteria
+ * @param includeGroupBy if true (groupBy is deprecated)
+ * @param includeOrderBy if ture (orderBy is deprecated)
+ * @param includePrefetchedRelationships if true (prefectchedRel. is deprecated)
*/
- public Criteria copy(boolean includeGroupBy, boolean includeOrderBy, boolean includePrefetchedRelationships)
+ public Criteria(Criteria aCriteria, boolean includeGroupBy, boolean includeOrderBy, boolean includePrefetchedRelationships)
{
- Criteria copy = new Criteria();
-
- copy.m_criteria = new Vector(this.m_criteria);
- copy.m_negative = this.m_negative;
+ this();
+
+ m_criteria = new Vector(aCriteria.m_criteria);
+ m_negative = aCriteria.m_negative;
if (includeGroupBy)
{
- copy.groupby = this.groupby;
+ m_groupby = aCriteria.m_groupby;
}
if (includeOrderBy)
{
- copy.orderby = this.orderby;
+ m_orderby = aCriteria.m_orderby;
}
if (includePrefetchedRelationships)
{
- copy.prefetchedRelationships = this.prefetchedRelationships;
+ m_prefetchedRelationships = aCriteria.m_prefetchedRelationships;
}
-
- return copy;
}
protected void addSelectionCriteria(SelectionCriteria selectionCrit)
{
- selectionCrit.setCriteria(this);
- m_criteria.addElement(selectionCrit);
+ updateUserAlias(selectionCrit.getAttribute());
+
+ selectionCrit.setParentCriterion(this);
+ m_criteria.add(selectionCrit);
}
protected void addCriteria(Criteria crit)
{
- crit.setParentCriteria(this);
- m_criteria.addElement(crit);
+ crit.setParentCriterion(this);
+ m_criteria.add(crit);
}
protected void addCriteria(Vector criteria)
@@ -175,71 +166,28 @@
}
/**
- * Answer a List of InCriteria based on values, each InCriteria
- * contains only inLimit values
- * @param attribute
- * @param values
- * @param negative
- * @param inLimit the maximum number of values for IN (-1 for no limit)
- * @return List of InCriteria
- */
- protected List splitInCriteria(Object attribute, Collection values, boolean negative, int inLimit)
- {
- List result = new ArrayList();
- Collection inCollection = new ArrayList();
-
- if (values == null || values.isEmpty())
- {
- // OQL creates empty Criteria for late binding
- result.add(buildInCriteria(attribute, negative, values));
- }
- else
- {
- Iterator iter = values.iterator();
-
- while (iter.hasNext())
- {
- inCollection.add(iter.next());
- if (inCollection.size() == inLimit || !iter.hasNext())
- {
- result.add(buildInCriteria(attribute, negative, inCollection));
- inCollection = new ArrayList();
- }
- }
- }
- return result;
- }
-
- private InCriteria buildInCriteria(Object attribute, boolean negative, Collection values)
- {
- if (negative)
- {
- // PAW
- // return ValueCriteria.buildNotInCriteria(attribute, values, getAlias());
- return ValueCriteria.buildNotInCriteria(attribute, values, getUserAlias(attribute));
- }
- else
- {
- // PAW
- // return ValueCriteria.buildInCriteria(attribute, values, getAlias());
- return ValueCriteria.buildInCriteria(attribute, values, getUserAlias(attribute));
- }
- }
-
- /**
* Get an Enumeration with all sub criteria
* @return Enumeration
*/
public Enumeration getElements()
{
- return getCriteria().elements();
+ return Collections.enumeration(getCriteria());
}
/**
- * Get a Vector with all sub criteria
- * @return Vector
+ * Get an Iterator with all sub criteria
+ * @return Iterator
+ */
+ public Iterator getIterator()
+ {
+ return getCriteria().iterator();
+ }
+
+ /**
+ * Get a List with all sub criteria
+ * @return List
*/
- protected Vector getCriteria()
+ protected List getCriteria()
{
return m_criteria;
}
@@ -257,9 +205,10 @@
* Set the type
* @param type OR, AND, NONE
*/
- public void setType(int type)
+ public Criteria setType(int type)
{
m_type = type;
+ return this;
}
/**
@@ -275,9 +224,10 @@
* Set embraced
* @param embraced true if criteria is to be surrounded by braces
*/
- public void setEmbraced(boolean embraced)
+ public Criteria setEmbraced(boolean embraced)
{
m_embraced = embraced;
+ return this;
}
/**
@@ -287,13 +237,13 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addEqualTo(String attribute, Object value)
+ public Criteria addEqualTo(String attribute, Object value)
{
- // PAW
-// addSelectionCriteria(ValueCriteria.buildEqualToCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildEqualToCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildEqualToCriteria(attribute, value));
+ return this;
}
+
/**
* Adds and equals (=) criteria,
* CUST_ID = 10034
@@ -302,13 +252,12 @@
* @param column The column name to be used without translation
* @param value An object representing the value of the column
*/
- public void addColumnEqualTo(String column, Object value)
+ public Criteria addColumnEqualTo(String column, Object value)
{
- // PAW
-// SelectionCriteria c = ValueCriteria.buildEqualToCriteria(column, value, getAlias());
- SelectionCriteria c = ValueCriteria.buildEqualToCriteria(column, value, getUserAlias(column));
+ SelectionCriteria c = ValueCriteria.buildEqualToCriteria(column, value);
c.setTranslateAttribute(false);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -319,13 +268,12 @@
* @param column The column name to be used without translation
* @param fieldName An object representing the value of the field
*/
- public void addColumnEqualToField(String column, Object fieldName)
+ public Criteria addColumnEqualToField(String column, Object fieldName)
{
- // PAW
- //SelectionCriteria c = FieldCriteria.buildEqualToCriteria(column, fieldName, getAlias());
- SelectionCriteria c = FieldCriteria.buildEqualToCriteria(column, fieldName, getUserAlias(column));
+ SelectionCriteria c = FieldCriteria.buildEqualToCriteria(column, fieldName);
c.setTranslateAttribute(false);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -337,12 +285,11 @@
* @param attribute The field name to be used
* @param fieldName The field name to compare with
*/
- public void addEqualToField(String attribute, String fieldName)
+ public Criteria addEqualToField(String attribute, String fieldName)
{
- // PAW
- // FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, fieldName, getAlias());
- FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, fieldName, getUserAlias(attribute));
+ FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, fieldName);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -354,12 +301,11 @@
* @param attribute The field name to be used
* @param fieldName The field name to compare with
*/
- public void addNotEqualToField(String attribute, String fieldName)
+ public Criteria addNotEqualToField(String attribute, String fieldName)
{
- // PAW
- // SelectionCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, fieldName, getAlias());
- SelectionCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, fieldName, getUserAlias(attribute));
+ SelectionCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, fieldName);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -371,13 +317,12 @@
* @param attribute The field name to be used
* @param colName The name of the column to compare with
*/
- public void addNotEqualToColumn(String attribute, String colName)
+ public Criteria addNotEqualToColumn(String attribute, String colName)
{
- // PAW
- // FieldCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, colName, getAlias());
- FieldCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, colName, getUserAlias(attribute));
+ FieldCriteria c = FieldCriteria.buildNotEqualToCriteria(attribute, colName);
c.setTranslateField(false);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -389,12 +334,12 @@
* @param attribute The field name to be used
* @param colName The name of the column to compare with
*/
- public void addEqualToColumn(String attribute, String colName)
+ public Criteria addEqualToColumn(String attribute, String colName)
{
- // FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, colName, getAlias());
- FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, colName, getUserAlias(attribute));
+ FieldCriteria c = FieldCriteria.buildEqualToCriteria(attribute, colName);
c.setTranslateField(false);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -404,11 +349,10 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addGreaterOrEqualThan(Object attribute, Object value)
+ public Criteria addGreaterOrEqualThan(Object attribute, Object value)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildNotLessCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNotLessCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNotLessCriteria(attribute, value));
+ return this;
}
/**
@@ -418,11 +362,10 @@
* @param attribute The field name to be used
* @param value The field name to compare with
*/
- public void addGreaterOrEqualThanField(String attribute, Object value)
+ public Criteria addGreaterOrEqualThanField(String attribute, Object value)
{
- // PAW
- // addSelectionCriteria(FieldCriteria.buildNotLessCriteria(attribute, value, getAlias()));
- addSelectionCriteria(FieldCriteria.buildNotLessCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(FieldCriteria.buildNotLessCriteria(attribute, value));
+ return this;
}
/**
@@ -432,11 +375,10 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addLessOrEqualThan(Object attribute, Object value)
+ public Criteria addLessOrEqualThan(Object attribute, Object value)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildNotGreaterCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNotGreaterCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNotGreaterCriteria(attribute, value));
+ return this;
}
/**
@@ -446,11 +388,10 @@
* @param attribute The field name to be used
* @param value The field name to compare with
*/
- public void addLessOrEqualThanField(String attribute, Object value)
+ public Criteria addLessOrEqualThanField(String attribute, Object value)
{
- // PAW
- // addSelectionCriteria(FieldCriteria.buildNotGreaterCriteria(attribute, value, getAlias()));
- addSelectionCriteria(FieldCriteria.buildNotGreaterCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(FieldCriteria.buildNotGreaterCriteria(attribute, value));
+ return this;
}
/**
@@ -461,11 +402,10 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addLike(Object attribute, Object value)
+ public Criteria addLike(Object attribute, Object value)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildLikeCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildLikeCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildLikeCriteria(attribute, value));
+ return this;
}
/**
@@ -476,11 +416,10 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addNotLike(String attribute, Object value)
+ public Criteria addNotLike(String attribute, Object value)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildNotLikeCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNotLikeCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNotLikeCriteria(attribute, value));
+ return this;
}
/**
@@ -490,11 +429,10 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addNotEqualTo(Object attribute, Object value)
+ public Criteria addNotEqualTo(Object attribute, Object value)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildNotEqualToCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNotEqualToCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNotEqualToCriteria(attribute, value));
+ return this;
}
/**
@@ -504,11 +442,10 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addGreaterThan(Object attribute, Object value)
+ public Criteria addGreaterThan(Object attribute, Object value)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildGreaterCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildGreaterCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildGreaterCriteria(attribute, value));
+ return this;
}
/**
@@ -518,11 +455,10 @@
* @param attribute The field name to be used
* @param value The field to compare with
*/
- public void addGreaterThanField(String attribute, Object value)
+ public Criteria addGreaterThanField(String attribute, Object value)
{
- // PAW
- // addSelectionCriteria(FieldCriteria.buildGreaterCriteria(attribute, value, getAlias()));
- addSelectionCriteria(FieldCriteria.buildGreaterCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(FieldCriteria.buildGreaterCriteria(attribute, value));
+ return this;
}
/**
@@ -532,11 +468,10 @@
* @param attribute The field name to be used
* @param value An object representing the value of the field
*/
- public void addLessThan(Object attribute, Object value)
+ public Criteria addLessThan(Object attribute, Object value)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildLessCriteria(attribute, value, getAlias()));
- addSelectionCriteria(ValueCriteria.buildLessCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildLessCriteria(attribute, value));
+ return this;
}
/**
@@ -546,11 +481,10 @@
* @param attribute The field name to be used
* @param value The field to compare with
*/
- public void addLessThanField(String attribute, Object value)
+ public Criteria addLessThanField(String attribute, Object value)
{
- // PAW
- // addSelectionCriteria(FieldCriteria.buildLessCriteria(attribute, value, getAlias()));
- addSelectionCriteria(FieldCriteria.buildLessCriteria(attribute, value, getUserAlias(attribute)));
+ addSelectionCriteria(FieldCriteria.buildLessCriteria(attribute, value));
+ return this;
}
/**
@@ -640,7 +574,7 @@
*/
protected List _getOrderby()
{
- return orderby;
+ return m_orderby;
}
/**
@@ -650,7 +584,7 @@
* </pre>
* @param pc criteria
*/
- public void addOrCriteria(Criteria pc)
+ public Criteria addOrCriteria(Criteria pc)
{
if (!m_criteria.isEmpty())
{
@@ -664,6 +598,7 @@
pc.setType(OR);
addCriteria(pc);
}
+ return this;
}
/**
@@ -672,11 +607,10 @@
*
* @param attribute The field name to be used
*/
- public void addIsNull(String attribute)
+ public Criteria addIsNull(String attribute)
{
- // PAW
- //addSelectionCriteria(ValueCriteria.buildNullCriteria(attribute, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNullCriteria(attribute, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNullCriteria(attribute));
+ return this;
}
/**
@@ -686,13 +620,12 @@
*
* @param column The column name to be used without translation
*/
- public void addColumnIsNull(String column)
+ public Criteria addColumnIsNull(String column)
{
- // PAW
- //SelectionCriteria c = ValueCriteria.buildNullCriteria(column, getAlias());
- SelectionCriteria c = ValueCriteria.buildNullCriteria(column, getUserAlias(column));
+ SelectionCriteria c = ValueCriteria.buildNullCriteria(column);
c.setTranslateAttribute(false);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -701,11 +634,10 @@
*
* @param attribute The field name to be used
*/
- public void addNotNull(String attribute)
+ public Criteria addNotNull(String attribute)
{
- // PAW
- //addSelectionCriteria(ValueCriteria.buildNotNullCriteria(attribute, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNotNullCriteria(attribute, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNotNullCriteria(attribute));
+ return this;
}
/**
@@ -715,13 +647,12 @@
*
* @param column The column name to be used without translation
*/
- public void addColumnNotNull(String column)
+ public Criteria addColumnNotNull(String column)
{
- // PAW
- // SelectionCriteria c = ValueCriteria.buildNotNullCriteria(column, getAlias());
- SelectionCriteria c = ValueCriteria.buildNotNullCriteria(column, getUserAlias(column));
+ SelectionCriteria c = ValueCriteria.buildNotNullCriteria(column);
c.setTranslateAttribute(false);
addSelectionCriteria(c);
+ return this;
}
/**
@@ -732,11 +663,10 @@
* @param value1 The lower boundary
* @param value2 The upper boundary
*/
- public void addBetween(Object attribute, Object value1, Object value2)
+ public Criteria addBetween(Object attribute, Object value1, Object value2)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildBeweenCriteria(attribute, value1, value2, getAlias()));
- addSelectionCriteria(ValueCriteria.buildBeweenCriteria(attribute, value1, value2, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildBeweenCriteria(attribute, value1, value2));
+ return this;
}
/**
@@ -747,11 +677,10 @@
* @param value1 The lower boundary
* @param value2 The upper boundary
*/
- public void addNotBetween(Object attribute, Object value1, Object value2)
+ public Criteria addNotBetween(Object attribute, Object value1, Object value2)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildNotBeweenCriteria(attribute, value1, value2, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNotBeweenCriteria(attribute, value1, value2, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNotBeweenCriteria(attribute, value1, value2));
+ return this;
}
/**
@@ -763,23 +692,10 @@
* @param attribute The field name to be used
* @param values The value Collection
*/
- public void addIn(String attribute, Collection values)
+ public Criteria addIn(String attribute, Collection values)
{
- List list = splitInCriteria(attribute, values, false, IN_LIMIT);
- int index = 0;
- InCriteria inCrit;
- Criteria allInCritaria;
-
- inCrit = (InCriteria) list.get(index);
- allInCritaria = new Criteria(inCrit);
-
- for (index = 1; index < list.size(); index++)
- {
- inCrit = (InCriteria) list.get(index);
- allInCritaria.addOrCriteria(new Criteria(inCrit));
- }
-
- addAndCriteria(allInCritaria);
+ addAndCriteria(InCriteria.buildInCriteria(attribute, values));
+ return this;
}
/**
@@ -792,27 +708,13 @@
* @param column The column name to be used without translation
* @param values The value Collection
*/
- public void addColumnIn(String column, Collection values)
+ public Criteria addColumnIn(String column, Collection values)
{
- List list = splitInCriteria(column, values, false, IN_LIMIT);
- int index = 0;
- InCriteria inCrit;
- Criteria allInCritaria;
-
- inCrit = (InCriteria) list.get(index);
- inCrit.setTranslateAttribute(false);
- allInCritaria = new Criteria(inCrit);
-
- for (index = 1; index < list.size(); index++)
- {
- inCrit = (InCriteria) list.get(index);
- inCrit.setTranslateAttribute(false);
- allInCritaria.addOrCriteria(new Criteria(inCrit));
- }
-
- addAndCriteria(allInCritaria);
+ addAndCriteria(InCriteria.buildColumnInCriteria(column, values));
+ return this;
}
+
/**
* Adds NOT IN criteria,
* customer_id not in(1,10,33,44)
@@ -822,15 +724,10 @@
* @param attribute The field name to be used
* @param values The value Collection
*/
- public void addNotIn(String attribute, Collection values)
+ public Criteria addNotIn(String attribute, Collection values)
{
- List list = splitInCriteria(attribute, values, true, IN_LIMIT);
- InCriteria inCrit;
- for (int index = 0; index < list.size(); index++)
- {
- inCrit = (InCriteria) list.get(index);
- addSelectionCriteria(inCrit);
- }
+ addAndCriteria(InCriteria.buildNotInCriteria(attribute, values));
+ return this;
}
/**
@@ -838,11 +735,10 @@
* @param attribute The field name to be used
* @param subQuery The subQuery
*/
- public void addIn(Object attribute, Query subQuery)
+ public Criteria addIn(Object attribute, Query subQuery)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildInCriteria(attribute, subQuery, getAlias()));
- addSelectionCriteria(ValueCriteria.buildInCriteria(attribute, subQuery, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildInCriteria(attribute, subQuery));
+ return this;
}
/**
@@ -850,11 +746,10 @@
* @param attribute The field name to be used
* @param subQuery The subQuery
*/
- public void addNotIn(String attribute, Query subQuery)
+ public Criteria addNotIn(String attribute, Query subQuery)
{
- // PAW
- // addSelectionCriteria(ValueCriteria.buildNotInCriteria(attribute, subQuery, getAlias()));
- addSelectionCriteria(ValueCriteria.buildNotInCriteria(attribute, subQuery, getUserAlias(attribute)));
+ addSelectionCriteria(ValueCriteria.buildNotInCriteria(attribute, subQuery));
+ return this;
}
/**
@@ -863,9 +758,10 @@
*
* @param anSqlStatment The free form SQL-Statement
*/
- public void addSql(String anSqlStatment)
+ public Criteria addSql(String anSqlStatment)
{
addSelectionCriteria(new SqlCriteria(anSqlStatment));
+ return this;
}
/**
@@ -873,7 +769,7 @@
*
* @param pc criteria
*/
- public void addAndCriteria(Criteria pc)
+ public Criteria addAndCriteria(Criteria pc)
{
// by combining a second criteria by 'AND' the existing criteria needs to be enclosed
// in parenthesis
@@ -890,6 +786,7 @@
pc.setType(AND);
addCriteria(pc);
}
+ return this;
}
/**
@@ -897,9 +794,10 @@
*
* @param subQuery sub-query
*/
- public void addExists(Query subQuery)
+ public Criteria addExists(Query subQuery)
{
addSelectionCriteria(new ExistsCriteria(subQuery, false));
+ return this;
}
/**
@@ -907,12 +805,39 @@
*
* @param subQuery sub-query
*/
- public void addNotExists(Query subQuery)
+ public Criteria addNotExists(Query subQuery)
{
addSelectionCriteria(new ExistsCriteria(subQuery, true));
+ return this;
}
/**
+ * Adds and equals (=) criteria for an identity
+ * customer = Identity()
+ *
+ * @param attribute The field name to be used
+ * @param identity An identity representing an Object
+ */
+ public Criteria addIdentityEqualTo(String attribute, Identity identity)
+ {
+ addAndCriteria(IdentityCriteria.buildEqualToCriteria(attribute, identity));
+ return this;
+ }
+
+ /**
+ * Adds and equals (!=) criteria for an identity
+ * customer != Identity()
+ *
+ * @param attribute The field name to be used
+ * @param identity An identity representing an Object
+ */
+ public Criteria addIdentityNotEqualTo(String attribute, Identity identity)
+ {
+ addAndCriteria(IdentityCriteria.buildNotEqualToCriteria(attribute, identity));
+ return this;
+ }
+
+ /**
* Answer true if no sub criteria available
* @return boolean
*/
@@ -951,7 +876,7 @@
*/
protected List _getGroupby()
{
- return groupby;
+ return m_groupby;
}
/**
@@ -999,7 +924,7 @@
*/
List getPrefetchedRelationships()
{
- return prefetchedRelationships;
+ return m_prefetchedRelationships;
}
/**
@@ -1013,149 +938,99 @@
}
/**
- * read the prefetchInLimit from Config based on OJB.properties
- */
- private static int getSqlInLimit()
- {
- try
- {
- PersistenceBrokerConfiguration config = (PersistenceBrokerConfiguration) PersistenceBrokerFactory
- .getConfigurator().getConfigurationFor(null);
- return config.getSqlInLimit();
- }
- catch (ConfigurationException e)
- {
- return 200;
- }
- }
-
- /**
- * @return String
+ * Retrieves the user alias to be used by a child criteria.
+ * The attribute is added to the user alias
+ * @param attribute
*/
- public String getAlias()
+ private void updateUserAlias(Object attribute)
{
- return m_alias;
- }
+ UserAlias ua = getUserAlias();
- /**
- * @return String
- */
- // PAW
- public UserAlias getUserAlias()
- {
- return m_userAlias;
- }
-
- // PAW
- /**
- * Retrieves or if necessary, creates a user alias to be used
- * by a child criteria
- * @param attribute The alias to set
- */
- private UserAlias getUserAlias(Object attribute)
- {
- if (m_userAlias != null)
- {
- return m_userAlias;
- }
- if (!(attribute instanceof String))
- {
- return null;
- }
- if (m_alias == null)
- {
- return null;
- }
- if (m_aliasPath == null)
+ if (ua != null)
{
- boolean allPathsAliased = true;
- return new UserAlias(m_alias, (String)attribute, allPathsAliased);
+ if (attribute instanceof String)
+ {
+ ua.addAttributePath((String)attribute);
+ }
}
- return new UserAlias(m_alias, (String)attribute, m_aliasPath);
}
-
+
/**
* Sets the alias. Empty String is regarded as null.
- * @param alias The alias to set
+ * @param ua The alias to set
*/
- public void setAlias(String alias)
+ private void setImplicitAlias(ImplicitUserAlias ua)
{
- if (alias == null || alias.trim().equals(""))
- {
- m_alias = null;
- }
- else
- {
- m_alias = alias;
- }
+ setAlias(ua);
- // propagate to SelectionCriteria,not to Criteria
- for (int i = 0; i < m_criteria.size(); i++)
+ Iterator iter = getIterator();
+
+ while (iter.hasNext())
{
- if (!(m_criteria.elementAt(i) instanceof Criteria))
+ Object obj = iter.next();
+ // propagate to SelectionCriteria,not to Criteria
+ if (obj instanceof SelectionCriteria)
{
- ((SelectionCriteria) m_criteria.elementAt(i)).setAlias(m_alias);
+ SelectionCriteria sc = (SelectionCriteria) obj;
+ if (sc.getAttribute() instanceof String)
+ {
+ ua.addAttributePath((String)sc.getAttribute());
+ }
}
}
}
-
- // PAW
+
/**
* Sets the alias. Empty String is regarded as null.
* @param alias The alias to set
- * @param aliasPath The path segment(s) to which the alias applies
*/
- public void setAlias(String alias, String aliasPath)
+ public Criterion setAlias(String alias)
{
- if (alias == null || alias.trim().equals(""))
- {
- m_alias = null;
- }
- else
- {
- m_alias = alias;
- m_aliasPath = aliasPath;
- }
+ setImplicitAlias(new ImplicitUserAlias(alias));
- // propagate to SelectionCriteria,not to Criteria
- for (int i = 0; i < m_criteria.size(); i++)
- {
- if (!(m_criteria.elementAt(i) instanceof Criteria))
- {
- ((SelectionCriteria) m_criteria.elementAt(i)).setAlias(m_alias, aliasPath);
- }
- }
+ return this;
}
- // PAW
/**
- * Sets the alias using a userAlias object.
- * @param userAlias The alias to set
+ * Sets the alias. Empty String is regarded as null.
+ * @param alias The alias to set
+ * @param aliasPath The path segment(s) to which the alias applies
*/
- public void setAlias(UserAlias userAlias)
+ public Criterion setAlias(String alias, String aliasPath)
{
- m_alias = userAlias.getName();
-
- // propagate to SelectionCriteria,not to Criteria
- for (int i = 0; i < m_criteria.size(); i++)
- {
- if (!(m_criteria.elementAt(i) instanceof Criteria))
- {
- ((SelectionCriteria) m_criteria.elementAt(i)).setAlias(userAlias);
- }
- }
+ setImplicitAlias(new ImplicitUserAlias(alias, aliasPath));
+
+ return this;
}
+ /**
+ * @see org.apache.ojb.broker.query.Criterion#getUserAlias()
+ */
+ public UserAlias getUserAlias()
+ {
+ return m_userAlias;
+ }
+
+
+ /**
+ * Sets the alias using a userAlias object.
+ * @param userAlias The alias to set
+ */
+ public Criteria setAlias(UserAlias userAlias)
+ {
+ m_userAlias = userAlias;
+ return this;
+ }
/**
* @return the query containing the criteria
*/
public QueryByCriteria getQuery()
{
- if (getParentCriteria() != null)
+ if (getParentCriterion() != null)
{
- return getParentCriteria().getQuery();
+ return getParentCriterion().getQuery();
}
else
{
@@ -1172,21 +1047,6 @@
m_query = query;
}
- /**
- * @return the parent criteria
- */
- public Criteria getParentCriteria()
- {
- return m_parentCriteria;
- }
-
- /**
- * @param criteria
- */
- void setParentCriteria(Criteria criteria)
- {
- m_parentCriteria = criteria;
- }
/**
* @see Object#toString()
@@ -1215,34 +1075,36 @@
* Flags the whole Criteria as negative.
* @param negative The negative to set.
*/
- public void setNegative(boolean negative)
+ public Criteria setNegative(boolean negative)
{
m_negative = negative;
+ return this;
}
- // PAW
/**
* Add a hint Class for a path. Used for relationships to extents.<br>
* SqlStatment will use these hint classes when resolving the path.
* Without these hints SqlStatment will use the base class the
* relationship points to ie: Article instead of CdArticle.
- *
+ * Usage see in OJB test-suite QueryTest#testInversePathExpression()QueryTest#testInversePathExpression().
+ *
* @param aPath the path segment ie: allArticlesInGroup
* @param aClass the Class ie: CdArticle
- * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
*/
- public void addPathClass(String aPath, Class aClass)
+ public Criteria addPathClass(String aPath, Class aClass)
{
- List pathClasses = (List) m_pathClasses.get(aPath);
+ Object pathClasses = m_pathClasses.get(aPath);
if(pathClasses == null)
{
setPathClass(aPath,aClass);
}
else
{
- pathClasses.add(aClass);
- //m_pathClasses.put(aPath, pathClasses);
+ List hints = (List)pathClasses;
+ hints.add(aClass);
+ m_pathClasses.put(aPath, hints);
}
+ return this;
}
/**
@@ -1251,36 +1113,37 @@
* Without this hint SqlStatment will use the base class the
* relationship points to ie: Article instead of CdArticle.
* Using this method is the same as adding just one hint
- *
+ * Usage see in OJB test-suite QueryTest#testInversePathExpression().
+ *
* @param aPath the path segment ie: allArticlesInGroup
* @param aClass the Class ie: CdArticle
- * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
* @see #addPathClass
*/
- public void setPathClass(String aPath, Class aClass)
+ public Criteria setPathClass(String aPath, Class aClass)
{
List pathClasses = new ArrayList(1);
pathClasses.add(aClass);
m_pathClasses.put(aPath, pathClasses);
+ return this;
}
/**
* Get the a List of Class objects used as hints for a path
- *
+ * Usage see in OJB test-suite QueryTest#testInversePathExpression()
+ *
* @param aPath the path segment ie: allArticlesInGroup
* @return a List o Class objects to be used in SqlStatment
* @see #addPathClass
- * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
*/
public List getClassesForPath(String aPath)
{
return (List)getPathClasses().get(aPath);
}
-
+
/**
* Gets the pathClasses.
* A Map containing hints about what Class to be used for what path segment
- * If local instance not set, try parent Criteria's instance. If this is
+ * If local instance not set, try parent Criteria's instance. If this is
* the top-level Criteria, try the m_query's instance
* @return Returns a Map
*/
@@ -1288,7 +1151,7 @@
{
if (m_pathClasses.isEmpty())
{
- if (m_parentCriteria == null)
+ if (getParentCriterion() == null)
{
if (m_query == null)
{
@@ -1301,7 +1164,7 @@
}
else
{
- return m_parentCriteria.getPathClasses();
+ return getParentCriterion().getPathClasses();
}
}
else
@@ -1310,6 +1173,108 @@
}
}
+ /**
+ * Preprocess the Criteria using a PersistenceBroker.
+ *
+ * @param aPb the PersistenceBroker
+ */
+ public void preprocess(PersistenceBrokerInternal aPb)
+ {
+ Iterator iter = getIterator();
+
+ while (iter.hasNext())
+ {
+ Criterion crit = (Criterion) iter.next();
+ crit.preprocess(aPb);
+ }
+ }
+
+ /**
+ * Inner class for an implicit UserAlias. This class is used for
+ * Crieria.setAlias(String) or Criteria.setAlias(String, String).
+ *
+ * @see Criteria#setAlias(String)
+ * @see Criteria#setAlias(String, String)
+ *
+ * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
+ */
+ private static final class ImplicitUserAlias extends UserAlias
+ {
+ private static final long serialVersionUID = 13895194959486705L;
+
+ private String m_aliasedPath;
+ private List m_tokenizedAliasedPath;
+
+ /**
+ * Constructor.
+ * @param name the name of the alias
+ * @param aliasedPath the part of the path that is aliased
+ */
+ ImplicitUserAlias(String name, String aliasedPath)
+ {
+ this(name);
+ m_aliasedPath = aliasedPath;
+
+ if (aliasedPath != null)
+ {
+ m_tokenizedAliasedPath = pathToSegments(m_aliasedPath);
+ }
+ }
+
+ /**
+ * Constructor.
+ * @param name the name of the alias
+ */
+ ImplicitUserAlias(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Creates the pathSegments based on attributePath and aliasPath.
+ * @param attributePath the attributePath
+ */
+ void addAttributePath(String attributePath)
+ {
+ if (m_tokenizedAliasedPath == null)
+ {
+ return;
+ }
+
+ Iterator itr = m_tokenizedAliasedPath.iterator();
+ String currPath = "";
+ String separator = "";
+ while (itr.hasNext())
+ {
+ currPath = currPath + separator + (String) itr.next();
+ int beginIndex = attributePath.indexOf(currPath);
+ if (beginIndex == -1)
+ {
+ break;
+ }
+ int endIndex = beginIndex + currPath.length();
+
+ add(attributePath.substring(0, endIndex));
+ separator = ".";
+ }
+ }
+
+ /**
+ * split the path into its segments
+ */
+ private List pathToSegments(String path)
+ {
+ ArrayList segments = new ArrayList();
+ StringTokenizer st = new StringTokenizer(path,".");
+
+ while (st.hasMoreTokens())
+ {
+ segments.add(st.nextToken());
+ }
+
+ return segments;
+ }
-
-}
\ No newline at end of file
+ }
+
+}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/CriteriaUtils.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/CriteriaUtils.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/CriteriaUtils.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/CriteriaUtils.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.query;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criterion.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criterion.java?rev=367025&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criterion.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Criterion.java Sun Jan 8 04:39:31 2006
@@ -0,0 +1,77 @@
+
+package org.apache.ojb.broker.query;
+
+/* Copyright 2002-2004 The Apache Software Foundation
+*
+* Licensed 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.ojb.broker.PersistenceBrokerInternal;
+
+/**
+ * Interface for Criterion
+ *
+ * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
+ * @version $Id: Criterion.java 364328 2004-12-01 20:08:27Z brj $
+ */
+public interface Criterion extends java.io.Serializable
+{
+ /**
+ * Preprocess the Criterion using a PersistenceBroker.
+ *
+ * @param aPb the PersistenceBroker
+ */
+ public void preprocess(PersistenceBrokerInternal aPb);
+
+ /**
+ * Return the parent Criterion.
+ *
+ * @return the parent Criterion or null
+ */
+ public Criterion getParentCriterion();
+
+ /**
+ * Return the Query.
+ *
+ * @return the Query
+ */
+ public QueryByCriteria getQuery();
+
+ /**
+ * Gets the pathClasses from the parent Criteria.
+ * A Map containing hints about what Class to be used for what path segment
+ *
+ * @return Returns a Map
+ */
+ public Map getPathClasses();
+
+ /**
+ * Get the a List of Class objects used as hints for a path.
+ *
+ * @param aPath the path segment ie: allArticlesInGroup
+ * @return a List o Class objects to be used in SqlStatment
+ * @see org.apache.ojb.broker.QueryTest#testInversePathExpression()
+ */
+ public List getClassesForPath(String aPath);
+
+ /**
+ * Get the Alias for this Criterion.
+ *
+ * @return UserAlias
+ */
+ public UserAlias getUserAlias();
+
+}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/ExistsCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/ExistsCriteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/ExistsCriteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/ExistsCriteria.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.query;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,8 @@
*/
public class ExistsCriteria extends SelectionCriteria
{
+ private static final long serialVersionUID = -7625975364586624215L;
+
private boolean m_negative = false;
/**
* Constructor for ExistsCriteria.
@@ -31,7 +33,7 @@
*/
ExistsCriteria(Query subQuery, boolean negative)
{
- super("", subQuery, (String)null);
+ super("", subQuery);
m_negative = negative;
}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/FieldCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/FieldCriteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/FieldCriteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/FieldCriteria.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.query;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,46 +23,36 @@
*/
public class FieldCriteria extends SelectionCriteria
{
- // PAW
-// static FieldCriteria buildEqualToCriteria(Object anAttribute, Object aValue, String anAlias)
- static FieldCriteria buildEqualToCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
+ private static final long serialVersionUID = -5653727742069553957L;
+
+ static FieldCriteria buildEqualToCriteria(Object anAttribute, Object aValue)
{
- return new FieldCriteria(anAttribute, aValue, EQUAL, anAlias);
+ return new FieldCriteria(anAttribute, aValue, EQUAL);
}
- // PAW
-// static FieldCriteria buildNotEqualToCriteria(Object anAttribute, Object aValue, String anAlias)
- static FieldCriteria buildNotEqualToCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
+ static FieldCriteria buildNotEqualToCriteria(Object anAttribute, Object aValue)
{
- return new FieldCriteria(anAttribute, aValue, NOT_EQUAL, anAlias);
+ return new FieldCriteria(anAttribute, aValue, NOT_EQUAL);
}
- // PAW
-// static FieldCriteria buildGreaterCriteria(Object anAttribute, Object aValue, String anAlias)
- static FieldCriteria buildGreaterCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
+ static FieldCriteria buildGreaterCriteria(Object anAttribute, Object aValue)
{
- return new FieldCriteria(anAttribute, aValue,GREATER, anAlias);
+ return new FieldCriteria(anAttribute, aValue,GREATER);
}
- // PAW
-// static FieldCriteria buildNotGreaterCriteria(Object anAttribute, Object aValue, String anAlias)
- static FieldCriteria buildNotGreaterCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
+ static FieldCriteria buildNotGreaterCriteria(Object anAttribute, Object aValue)
{
- return new FieldCriteria(anAttribute, aValue, NOT_GREATER, anAlias);
+ return new FieldCriteria(anAttribute, aValue, NOT_GREATER);
}
- // PAW
-// static FieldCriteria buildLessCriteria(Object anAttribute, Object aValue, String anAlias)
- static FieldCriteria buildLessCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
+ static FieldCriteria buildLessCriteria(Object anAttribute, Object aValue)
{
- return new FieldCriteria(anAttribute, aValue, LESS, anAlias);
+ return new FieldCriteria(anAttribute, aValue, LESS);
}
- // PAW
-// static FieldCriteria buildNotLessCriteria(Object anAttribute, Object aValue, String anAlias)
- static FieldCriteria buildNotLessCriteria(Object anAttribute, Object aValue, UserAlias anAlias)
+ static FieldCriteria buildNotLessCriteria(Object anAttribute, Object aValue)
{
- return new FieldCriteria(anAttribute, aValue, NOT_LESS, anAlias);
+ return new FieldCriteria(anAttribute, aValue, NOT_LESS);
}
// BRJ: indicate whether field name should be translated into column name
@@ -75,13 +65,10 @@
* @param anAttribute column- or fieldName
* @param aValue the value to compare with
* @param negative criteria is negated (ie NOT LIKE instead of LIKE)
- * @param alias use alias to link anAttribute to
*/
- // PAW
-// FieldCriteria(Object anAttribute, Object aValue, String aClause, String alias)
- FieldCriteria(Object anAttribute, Object aValue, String aClause, UserAlias alias)
+ FieldCriteria(Object anAttribute, Object aValue, String aClause)
{
- super(anAttribute, aValue, alias);
+ super(anAttribute, aValue);
m_clause = aClause;
}
Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/IdentityCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/IdentityCriteria.java?rev=367025&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/IdentityCriteria.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/IdentityCriteria.java Sun Jan 8 04:39:31 2006
@@ -0,0 +1,132 @@
+
+package org.apache.ojb.broker.query;
+
+/* Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.ojb.broker.Identity;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
+import org.apache.ojb.broker.metadata.ClassDescriptor;
+import org.apache.ojb.broker.metadata.DescriptorRepository;
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+
+/**
+ * Criteria for Identity.
+ * The Identity is translated into a list of ordinary SelectionCriteria reflecting the primary key.
+ *
+ * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
+ * @version $Id: IdentityCriteria.java 364332 2004-12-02 21:37:46Z brj $
+ */
+public class IdentityCriteria extends Criteria
+{
+ private static final long serialVersionUID = -2349356771591660674L;
+
+ /**
+ * Build IdentityCriteria with EQUAL clause
+ * @param anAttribute the name of the attribute
+ * @param aValue an Identity
+ */
+ static IdentityCriteria buildEqualToCriteria(Object anAttribute, Identity anIdentity)
+ {
+ return new IdentityCriteria(anAttribute, anIdentity, false);
+ }
+
+ /**
+ * Build IdentityCriteria with NOT EQUAL clause
+ * @param anAttribute the name of the attribute
+ * @param aValue an Identity
+ */
+ static IdentityCriteria buildNotEqualToCriteria(Object anAttribute, Identity anIdentity)
+ {
+ return new IdentityCriteria(anAttribute, anIdentity, true);
+ }
+
+ private Object m_attribute;
+ private Identity m_identity;
+ private boolean m_preprocessed = false;
+
+ /**
+ * Constructor.
+ *
+ * @param anAttribute the name of the attribute
+ * @param aValue an Identity
+ * @param negative clause-indicator : true=NOT EQUAL, false=EQUAL
+ */
+ IdentityCriteria(Object anAttribute, Identity identity, boolean negative)
+ {
+ m_attribute = anAttribute;
+ m_identity = identity;
+ setNegative(negative);
+ }
+
+
+ /**
+ * Build SelectionCriteria based on Identity.
+ *
+ * @param aPb the Broker used to access the repository
+ */
+ protected void buildCriteria(PersistenceBrokerInternal aPb)
+ {
+ DescriptorRepository repository = aPb.getDescriptorRepository();
+ ClassDescriptor cld = repository.getDescriptorFor(m_identity.getObjectsRealClass());
+ FieldDescriptor[] pkFields = cld.getPkFields();
+ Object[] pkValues = m_identity.getPrimaryKeyValues();
+ String attribute = ((String) m_attribute).trim();
+ boolean negative = isNegative();
+
+ if (attribute != null && attribute.length() > 0)
+ {
+ attribute = attribute + ".";
+ }
+
+ for (int i = 0;i < pkFields.length; i++)
+ {
+ String pkAttribute = attribute + pkFields[i].getAttributeName();
+ ValueCriteria c;
+ if (!negative)
+ {
+ c = ValueCriteria.buildEqualToCriteria(pkAttribute, pkValues[i]);
+ }
+ else
+ {
+ c = ValueCriteria.buildNotEqualToCriteria(pkAttribute, pkValues[i]);
+ }
+ addSelectionCriteria(c);
+ }
+ }
+
+ /**
+ * Preprocess the Criteria using a PersistenceBroker.
+ *
+ * @param aPb the PersistenceBroker
+ */
+ public void preprocess(PersistenceBrokerInternal aPb)
+ {
+ if (!m_preprocessed)
+ {
+ buildCriteria(aPb);
+ m_preprocessed = true;
+ }
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ String clause = isNegative() ? SelectionCriteria.NOT_EQUAL : SelectionCriteria.EQUAL;
+ return "IdentityCriterion:" + m_attribute + clause + super.toString();
+ }
+}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriteria.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,7 @@
+
package org.apache.ojb.broker.query;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,42 +16,177 @@
* limitations under the License.
*/
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ojb.broker.PersistenceBrokerFactory;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
+import org.apache.ojb.broker.core.PersistenceBrokerConfiguration;
+import org.apache.ojb.broker.util.configuration.ConfigurationException;
/**
- * SelectionCriteria for 'in (a,b,c..)'
- *
+ * Criteria for IN-Clause holding a list of InCriterion.
+ * The IN is translated into a list of ordinary InCriterion according to SQL-IN-LIMIT.
+ *
* @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
* @version $Id$
*/
-public class InCriteria extends ValueCriteria
+public class InCriteria extends Criteria
{
- InCriteria(Object anAttribute, Object aValue, String aClause, String anAlias)
+ private static final long serialVersionUID = -2349356771591660674L;
+
+ /**
+ * Build InCriteria with IN clause
+ * @param anAttribute the name of the attribute
+ * @param aValue an Identity
+ */
+ static InCriteria buildInCriteria(Object anAttribute, Collection values)
{
- super(anAttribute, aValue, aClause, anAlias);
+ return new InCriteria(anAttribute, values, false, true);
}
-
- InCriteria(Object anAttribute, Object aValue, String aClause, UserAlias anAlias)
+
+ /**
+ * Build InCriteria with IN clause
+ * @param aColumn the name of the column (do not translate)
+ * @param aValue an Identity
+ */
+ static InCriteria buildColumnInCriteria(Object aColumn, Collection values)
{
- super(anAttribute, aValue, aClause, anAlias);
+ return new InCriteria(aColumn, values, false, false);
}
-
- /**
- * @see org.apache.ojb.broker.query.SelectionCriteria#isBindable()
- * BRJ: empty Collection is bindable
- */
- protected boolean isBindable()
+
+ /**
+ * Build InCriteria with NOT IN clause
+ * @param anAttribute the name of the attribute
+ * @param aValue an Identity
+ */
+ static InCriteria buildNotInCriteria(Object anAttribute, Collection values)
{
- if (getValue() instanceof Collection)
- {
- Collection coll = (Collection)getValue();
- return coll.isEmpty();
- }
- else
- {
- return true;
- }
+ return new InCriteria(anAttribute, values, true, true);
}
+
+ private Object m_attribute;
+ private Collection m_values;
+ private boolean m_translateAttribute;
+ private boolean m_preprocessed = false;
-}
+ /**
+ * Constructor.
+ *
+ * @param anAttribute the name of the attribute
+ * @param values the Collection
+ * @param negative clause-indicator : true=NOT IN, false=IN
+ * @param translate if false the attribute name is not translated into column name
+ */
+ InCriteria(Object anAttribute, Collection values, boolean negative, boolean translate)
+ {
+ m_attribute = anAttribute;
+ m_values = values;
+ m_translateAttribute = translate;
+ setNegative(negative);
+ }
+
+ private InCriterion buildInCriterion(Collection values)
+ {
+ InCriterion crit;
+
+ crit = ValueCriteria.buildInCriteria(m_attribute, values);
+ crit.setTranslateAttribute(m_translateAttribute);
+
+ return crit;
+ }
+
+ /**
+ * Answer a List of InCriterion based on values, each InCriteria
+ * contains only inLimit values.
+ * @return
+ */
+ private List buildList(PersistenceBrokerInternal aPb)
+ {
+ List result = new ArrayList();
+ Collection inCollection = new ArrayList();
+ int inLimit = getSqlInLimit(aPb);
+
+ if (m_values == null || m_values.isEmpty())
+ {
+ // OQL creates empty Criteria for late binding
+ result.add(buildInCriterion(m_values));
+ }
+ else
+ {
+ Iterator iter = m_values.iterator();
+
+ while (iter.hasNext())
+ {
+ inCollection.add(iter.next());
+ if (inCollection.size() == inLimit || !iter.hasNext())
+ {
+ result.add(buildInCriterion(inCollection));
+ inCollection = new ArrayList();
+ }
+ }
+ }
+ return result;
+ }
+
+ private void buildInCriteria(PersistenceBrokerInternal aPb)
+ {
+ List list = buildList(aPb);
+ int index = 0;
+ InCriterion inCrit;
+ // add the first InCriterion (to be ANDed)
+ inCrit = (InCriterion) list.get(index);
+ addSelectionCriteria(inCrit);
+
+ // add the other InCriterion (to be ORed)
+ for (index = 1; index < list.size(); index++)
+ {
+ inCrit = (InCriterion) list.get(index);
+ addOrCriteria(new Criteria(inCrit));
+ }
+ }
+
+ /**
+ * Preprocess the Criteria using a PersistenceBroker.
+ * Build list of InCriterion based on SQL-IN-LIMIT.
+ *
+ * @param aPb the PersistenceBroker
+ */
+ public void preprocess(PersistenceBrokerInternal aPb)
+ {
+ if (!m_preprocessed)
+ {
+ buildInCriteria(aPb);
+ m_preprocessed = true;
+ }
+ }
+
+ /**
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ String clause = isNegative() ? SelectionCriteria.NOT_IN : SelectionCriteria.IN;
+ return "InCriteria:" + m_attribute + clause + super.toString();
+ }
+
+ /**
+ * read the prefetchInLimit from Config based on OJB.properties
+ */
+ private int getSqlInLimit(PersistenceBrokerInternal aPb)
+ {
+ try
+ {
+ PersistenceBrokerConfiguration config = (PersistenceBrokerConfiguration) PersistenceBrokerFactory
+ .getConfigurator().getConfigurationFor(aPb);
+ return config.getSqlInLimit();
+ }
+ catch (ConfigurationException e)
+ {
+ return 200;
+ }
+ }
+}
Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriterion.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriterion.java?rev=367025&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriterion.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/InCriterion.java Sun Jan 8 04:39:31 2006
@@ -0,0 +1,54 @@
+package org.apache.ojb.broker.query;
+
+import java.util.Collection;
+
+/* Copyright 2002-2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ */
+
+/**
+ * SelectionCriterion for 'in (a,b,c..)'
+ *
+ * @author <a href="mailto:jbraeuchi@gmx.ch">Jakob Braeuchi</a>
+ * @version $Id: InCriterion.java 364332 2004-12-02 21:37:46Z brj $
+ */
+public class InCriterion extends ValueCriteria
+{
+ private static final long serialVersionUID = 6583090573034862381L;
+
+ InCriterion(Object anAttribute, Object aValue, String aClause)
+ {
+ super(anAttribute, aValue, aClause);
+ }
+
+
+ /**
+ * @see org.apache.ojb.broker.query.SelectionCriteria#isBindable()
+ * BRJ: empty Collection is bindable
+ */
+ protected boolean isBindable()
+ {
+ if (getValue() instanceof Collection)
+ {
+ Collection coll = (Collection)getValue();
+ return coll.isEmpty();
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+}
+
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/LikeCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/LikeCriteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/LikeCriteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/LikeCriteria.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,4 @@
-package org.apache.ojb.broker.query;
-
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +13,8 @@
* limitations under the License.
*/
+package org.apache.ojb.broker.query;
+
/**
* Model a Like Criteria</br>
* Escape Processing by Paul R. Nase
@@ -33,6 +33,8 @@
*/
public class LikeCriteria extends ValueCriteria
{
+ private static final long serialVersionUID = 726440067589184708L;
+
/**
* The Dfault-Character used for Escaping Wildcards
*/
@@ -47,23 +49,12 @@
* @param anAttribute
* @param aValue
* @param aClause
- * @param anAlias
*/
- public LikeCriteria(Object anAttribute, Object aValue, String aClause, String anAlias)
+ public LikeCriteria(Object anAttribute, Object aValue, String aClause)
{
- super(anAttribute, generateSQLSearchPattern(aValue), aClause, anAlias);
+ super(anAttribute, generateSQLSearchPattern(aValue), aClause);
}
- /**
- * @param anAttribute
- * @param aValue
- * @param aClause
- * @param anAlias
- */
- public LikeCriteria(Object anAttribute, Object aValue, String aClause, UserAlias anAlias)
- {
- super(anAttribute, generateSQLSearchPattern(aValue), aClause, anAlias);
- }
/**
* @see org.apache.ojb.broker.query.SelectionCriteria#bind(java.lang.Object)
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/NullCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/NullCriteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/NullCriteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/NullCriteria.java Sun Jan 8 04:39:31 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.query;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +23,13 @@
*/
public class NullCriteria extends ValueCriteria
{
- NullCriteria(String anAttribute, String aClause, String anAlias)
- {
- super(anAttribute, null, aClause, anAlias);
- }
+ private static final long serialVersionUID = 7594056580776626019L;
- NullCriteria(String anAttribute, String aClause, UserAlias anAlias)
+ NullCriteria(String anAttribute, String aClause)
{
- super(anAttribute, null, aClause, anAlias);
+ super(anAttribute, null, aClause);
}
+
public String toString()
{
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Query.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Query.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Query.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/Query.java Sun Jan 8 04:39:31 2006
@@ -17,6 +17,8 @@
import java.util.List;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
+
/**
* represents Queries that can be used by the OJB PersistenceBroker
* to retrieve Objects from the underlying DB.
@@ -163,5 +165,12 @@
* (or 0 if not set / using driver default)
*/
int getFetchSize();
+
+ /**
+ * Preprocess the Query using a PersistenceBroker.
+ *
+ * @param aPb the PersistenceBroker
+ */
+ public void preprocess(PersistenceBrokerInternal aPb);
}
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryByCriteria.java
URL: http://svn.apache.org/viewcvs/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryByCriteria.java?rev=367025&r1=367024&r2=367025&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryByCriteria.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/query/QueryByCriteria.java Sun Jan 8 04:39:31 2006
@@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.ojb.broker.PersistenceBrokerInternal;
import org.apache.ojb.broker.metadata.ClassDescriptor;
import org.apache.ojb.broker.metadata.FieldDescriptor;
import org.apache.ojb.broker.metadata.FieldHelper;
@@ -533,4 +534,15 @@
m_objectProjectionAttribute = objectProjectionAttribute;
m_searchClass = objectProjectionClass;
}
+
+ /**
+ * @see org.apache.ojb.broker.query.Query#preprocess(org.apache.ojb.broker.PersistenceBrokerInternal)
+ */
+ public void preprocess(PersistenceBrokerInternal aPb)
+ {
+ if (getCriteria() != null)
+ {
+ getCriteria().preprocess(aPb);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org