You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by Eric Dobbs <er...@dobbse.net> on 2001/04/26 02:18:39 UTC
[PATCH] Criteria.java
Hi All.
When building a compound criteria object like this
(using peers from the tdk13 sample application):
criteria.add(RdfPeer.TITLE,(Object)("%"+search+"%"),
Criteria.LIKE);
Criteria.Criterion criterion = criteria
.getCriterion(RdfPeer.TITLE);
criterion.or(criteria.getNewCriterion(
RdfPeer.TABLE_NAME,
RdfPeer.AUTHOR,
(Object)("%"+search+"%"),
Criteria.LIKE));
The resulting search fails because...
1. RdfPeer.TABLE_NAME=RDF and RdfPeer.AUTHOR=RDF.AUTHOR, and
2. the current method criteria.getNewCriterion(...) is
expecting ("RDF","AUTHOR",...) not ("RDF", "RDF.AUTHOR")
This patch adds another getNewCriterion(...) method
that will do the right thing without a table name and with
a full column name. For example:
criterion.or(criteria.getNewCriterion(
RdfPeer.AUTHOR,
(Object)("%"+search+"%"),
Criteria.LIKE));
-Eric
dobbs% cvs diff -u src/java/org/apache/turbine/util/db/Criteria.java
Index: src/java/org/apache/turbine/util/db/Criteria.java
===================================================================
RCS file: /home/cvspublic/jakarta-
turbine/src/java/org/apache/turbine/util/db/Criteria.java,v
retrieving revision 1.23
diff -u -r1.23 Criteria.java
--- src/java/org/apache/turbine/util/db/Criteria.java 2001/03/06
06:13:57 1.23
+++ src/java/org/apache/turbine/util/db/Criteria.java 2001/04/25
23:52:09
@@ -78,6 +78,7 @@
* @author <a href="mailto:frank.kim@clearink.com">Frank Y. Kim</a>
* @author <a href="mailto:john.mcnally@clearink.com">John D.
McNally</a>
* @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
+ * @author <a href="mailto:eric@dobbse.net">Eric Dobbs</a>
* @version $Id: Criteria.java,v 1.23 2001/03/06 06:13:57 chrise Exp $
*/
public class Criteria extends Hashtable
@@ -360,6 +361,20 @@
new StringBuffer(table.length() + column.length() + 1)
.append(table).append('.').append(column)
.toString() );
+ }
+
+ /**
+ * Method to return criterion that is not added automatically
+ * to this Criteria. This can be used to chain the
+ * Criterions to form a more complex where clause.
+ *
+ * @param column String full name of column (for example
TABLE.COLUMN).
+ * @return A Criterion.
+ */
+ public Criterion getNewCriterion(String column,
+ Object value, String comparison)
+ {
+ return new Criterion(column,value,comparison);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org