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 2003/12/10 22:27:45 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql SqlQueryStatement.java
brj 2003/12/10 13:27:44
Modified: src/java/org/apache/ojb/broker/query Criteria.java
src/java/org/apache/ojb/broker/accesslayer/sql
SqlQueryStatement.java
Log:
support negative criteria resulting in SQL NOT(...)
Revision Changes Path
1.35 +28 -4 db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java
Index: Criteria.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/query/Criteria.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- Criteria.java 25 Oct 2003 23:59:27 -0000 1.34
+++ Criteria.java 10 Dec 2003 21:27:44 -0000 1.35
@@ -94,6 +94,7 @@
private Vector 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;
@@ -131,14 +132,20 @@
addSelectionCriteria(aSelectionCriteria);
}
- /**
- * make a copy of the criteria
- */
+ /**
+ * make a copy of the criteria
+ * @param includeGroupBy
+ * @param includeOrderBy
+ * @param includePrefetchedRelationships
+ * @return
+ */
public Criteria copy(boolean includeGroupBy, boolean includeOrderBy, boolean includePrefetchedRelationships)
{
Criteria copy = new Criteria();
copy.m_criteria = this.m_criteria;
+ copy.m_negative = this.m_negative;
+
if (includeGroupBy)
{
copy.groupby = this.groupby;
@@ -1086,5 +1093,22 @@
{
return m_criteria.toString();
}
+
+ /**
+ * @return Returns the negative.
+ */
+ public boolean isNegative()
+ {
+ return m_negative;
+ }
+
+ /**
+ * Flags the whole Criteria as negative.
+ * @param negative The negative to set.
+ */
+ public void setNegative(boolean negative)
+ {
+ m_negative = negative;
+ }
}
1.58 +22 -3 db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java
Index: SqlQueryStatement.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/sql/SqlQueryStatement.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- SqlQueryStatement.java 5 Nov 2003 20:33:11 -0000 1.57
+++ SqlQueryStatement.java 10 Dec 2003 21:27:44 -0000 1.58
@@ -453,6 +453,9 @@
/**
* appends a WHERE-clause to the Statement
+ * @param where
+ * @param crit
+ * @param stmt
*/
protected void appendWhereClause(StringBuffer where, Criteria crit, StringBuffer stmt)
{
@@ -470,6 +473,9 @@
/**
* appends a HAVING-clause to the Statement
+ * @param having
+ * @param crit
+ * @param stmt
*/
protected void appendHavingClause(StringBuffer having, Criteria crit, StringBuffer stmt)
{
@@ -487,6 +493,9 @@
/**
* appends a WHERE/HAVING-clause to the Statement
+ * @param clause
+ * @param crit
+ * @param stmt
*/
protected void appendClause(StringBuffer clause, Criteria crit, StringBuffer stmt)
{
@@ -514,16 +523,20 @@
stmt.append(asSQLStatement(crit));
stmt.append(")");
}
- }
+
+ }
}
/**
- * selection criteria
+ * create SQL-String based on Criteria
+ * @param crit
+ * @return
*/
private String asSQLStatement(Criteria crit)
{
Enumeration e = crit.getElements();
StringBuffer statement = new StringBuffer();
+
while (e.hasMoreElements())
{
Object o = e.nextElement();
@@ -581,6 +594,12 @@
}
} // while
+ // BRJ : negative Criteria surrounded by NOT (...)
+ if (crit.isNegative())
+ {
+ statement.insert(0, " NOT (");
+ statement.append(")");
+ }
return (statement.length() == 0 ? null : statement.toString());
}
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org