You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2005/10/24 11:54:48 UTC
svn commit: r328018 - in /incubator/jackrabbit/trunk/src:
java/org/apache/jackrabbit/core/query/RelationQueryNode.java
java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
test/org/apache/jackrabbit/core/query/SimpleQueryTest.java
Author: mreutegg
Date: Mon Oct 24 02:54:41 2005
New Revision: 328018
URL: http://svn.apache.org/viewcvs?rev=328018&view=rev
Log:
JCR-259: XPath query with negative numbers incorrect
Modified:
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java
incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/SimpleQueryTest.java
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java?rev=328018&r1=328017&r2=328018&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/RelationQueryNode.java Mon Oct 24 02:54:41 2005
@@ -31,6 +31,12 @@
private QName property;
/**
+ * If <code>true</code> this relation query node contains a value preceded
+ * with an unary minus.
+ */
+ private boolean unaryMinus;
+
+ /**
* The <code>long</code> value of the relation if this is a query is of type
* <code>long</code>
*/
@@ -167,6 +173,16 @@
}
/**
+ * If <code>b</code> is <code>true</code> then the value in this relation
+ * node contains a receding unary minus.
+ *
+ * @param b <code>true</code> if this relation contains a unary minus.
+ */
+ public void setUnaryMinus(boolean b) {
+ unaryMinus = b;
+ }
+
+ /**
* Returns the type of the value.
*
* @return the type of the value.
@@ -209,7 +225,7 @@
* @param value the new value.
*/
public void setLongValue(long value) {
- valueLong = value;
+ valueLong = unaryMinus ? -value : value;
type = TYPE_LONG;
}
@@ -248,7 +264,7 @@
* @param value the new value.
*/
public void setDoubleValue(double value) {
- valueDouble = value;
+ valueDouble = unaryMinus ? -value : value;
type = TYPE_DOUBLE;
}
Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java?rev=328018&r1=328017&r2=328018&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/query/xpath/XPathQueryBuilder.java Mon Oct 24 02:54:41 2005
@@ -432,7 +432,14 @@
exceptions.add(new InvalidQueryException("LocationStep only allows integer literal as position index"));
}
} else {
- exceptions.add(new InvalidQueryException("Internal error: data is not a RelationQueryNode"));
+ exceptions.add(new InvalidQueryException("Parse error: data is not a RelationQueryNode"));
+ }
+ break;
+ case JJTUNARYMINUS:
+ if (queryNode.getType() == QueryNode.TYPE_RELATION) {
+ ((RelationQueryNode) queryNode).setUnaryMinus(true);
+ } else {
+ exceptions.add(new InvalidQueryException("Parse error: data is not a RelationQueryNode"));
}
break;
case JJTFUNCTIONCALL:
Modified: incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/SimpleQueryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/SimpleQueryTest.java?rev=328018&r1=328017&r2=328018&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/SimpleQueryTest.java (original)
+++ incubator/jackrabbit/trunk/src/test/org/apache/jackrabbit/core/query/SimpleQueryTest.java Mon Oct 24 02:54:41 2005
@@ -340,6 +340,35 @@
checkResult(result, 1);
}
+ public void testNegativeNumber() throws Exception {
+ Node foo = testRootNode.addNode("foo");
+ foo.setProperty("number", -10);
+ Node bar = testRootNode.addNode("bar");
+ bar.setProperty("number", -20);
+
+ testRootNode.save();
+
+ String sql = "SELECT * FROM nt:unstructured WHERE number = -10";
+ Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
+ QueryResult result = q.execute();
+ checkResult(result, 1);
+
+ String xpath = "//*[@jcr:primaryType='nt:unstructured' and @number = -10]";
+ q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+ result = q.execute();
+ checkResult(result, 1);
+
+ sql = "SELECT * FROM nt:unstructured WHERE number <= -10";
+ q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
+ result = q.execute();
+ checkResult(result, 2);
+
+ xpath = "//*[@jcr:primaryType='nt:unstructured' and @number <= -10]";
+ q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+ result = q.execute();
+ checkResult(result, 2);
+ }
+
public void testGeneralComparison() throws Exception {
Node foo = testRootNode.addNode("foo");
foo.setProperty("text", new String[]{"foo", "bar"}); // mvp