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 2009/06/18 16:17:53 UTC
svn commit: r786075 [1/2] - in /jackrabbit/trunk:
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/
jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/
jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/q...
Author: mreutegg
Date: Thu Jun 18 14:17:52 2009
New Revision: 786075
URL: http://svn.apache.org/viewvc?rev=786075&view=rev
Log:
JCR-2076: JSR 283: QOM and SQL2
- test cases and some minor fixes
Added:
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/QOMFormatter.java (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AndConstraintTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ColumnTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/FullTextSearchScoreTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NotConstraintTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrConstraintTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrderingTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyExistenceTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyValueTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/QueryObjectModelFactoryTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SameNodeJoinConditionTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SameNodeTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/SelectorTest.java
jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/UpperLowerCaseTest.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/QueryObjectModelBuilder.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/Parser.java
jackrabbit/trunk/jackrabbit-spi-commons/src/main/java/org/apache/jackrabbit/spi/commons/query/sql2/SQL2QOMBuilder.java
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/QueryObjectModelImpl.java Thu Jun 18 14:17:52 2009
@@ -29,6 +29,7 @@
import org.apache.jackrabbit.core.SessionImpl;
import org.apache.jackrabbit.spi.commons.name.NameConstants;
import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.spi.commons.query.QueryObjectModelBuilderRegistry;
/**
* <code>QueryObjectModelImpl</code>...
@@ -94,7 +95,7 @@
this.language = language;
this.handler = handler;
this.qomTree = qomTree;
- this.statement = null; // TODO: format qomTree into a SQL2 statement
+ this.statement = QueryObjectModelBuilderRegistry.getQueryObjectModelBuilder(language).toString(this);
this.query = handler.createExecutableQuery(session, itemMgr, qomTree);
setInitialized();
}
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/QueryObjectModelImpl.java Thu Jun 18 14:17:52 2009
@@ -22,6 +22,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.nodetype.PropertyDefinition;
import javax.jcr.query.QueryResult;
+import javax.jcr.query.InvalidQueryException;
import javax.jcr.query.qom.QueryObjectModelFactory;
import org.apache.jackrabbit.core.ItemManager;
@@ -57,14 +58,17 @@
* @param index the search index.
* @param propReg the property type registry.
* @param qomTree the query object model tree.
+ * @throws InvalidQueryException if the QOM tree is invalid.
*/
public QueryObjectModelImpl(SessionImpl session,
ItemManager itemMgr,
SearchIndex index,
PropertyTypeRegistry propReg,
- QueryObjectModelTree qomTree) {
+ QueryObjectModelTree qomTree)
+ throws InvalidQueryException {
super(session, itemMgr, index, propReg);
this.qomTree = qomTree;
+ checkNodeTypes();
extractBindVariableNames();
}
@@ -156,4 +160,26 @@
// will never happen
}
}
+
+ /**
+ * Checks if the selector node types are valid.
+ *
+ * @throws InvalidQueryException if one of the selector node types is
+ * unknown.
+ */
+ private void checkNodeTypes() throws InvalidQueryException {
+ try {
+ qomTree.accept(new DefaultTraversingQOMTreeVisitor() {
+ public Object visit(SelectorImpl node, Object data) throws Exception {
+ String ntName = node.getNodeTypeName();
+ if (!session.getNodeTypeManager().hasNodeType(ntName)) {
+ throw new Exception(ntName + " is not a known node type");
+ }
+ return super.visit(node, data);
+ }
+ }, null);
+ } catch (Exception e) {
+ throw new InvalidQueryException(e.getMessage());
+ }
+ }
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractJoinTest.java Thu Jun 18 14:17:52 2009
@@ -48,6 +48,11 @@
//--------------------------< utilities >-----------------------------------
+ protected void checkQOM(QueryObjectModel qom, Node[][] nodes)
+ throws RepositoryException {
+ checkQOM(qom, SELECTOR_NAMES, nodes);
+ }
+
protected void checkResult(QueryResult result, Node[][] nodes)
throws RepositoryException {
checkResult(result, SELECTOR_NAMES, nodes);
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AbstractQOMTest.java Thu Jun 18 14:17:52 2009
@@ -29,6 +29,7 @@
import javax.jcr.query.QueryResult;
import javax.jcr.query.Row;
import javax.jcr.query.RowIterator;
+import javax.jcr.query.qom.QueryObjectModel;
import org.apache.jackrabbit.test.api.query.AbstractQueryTest;
@@ -53,6 +54,15 @@
q.bindValue(var, value);
}
+ protected void checkResultOrder(QueryObjectModel qom,
+ String[] selectorNames,
+ Node[][] nodes)
+ throws RepositoryException {
+ checkResultOrder(qom.execute(), selectorNames, nodes);
+ checkResultOrder(qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(),
+ selectorNames, nodes);
+ }
+
protected void checkResultOrder(QueryResult result,
String[] selectorNames,
Node[][] nodes)
@@ -86,6 +96,43 @@
assertEquals("wrong result order", expectedPaths, resultPaths);
}
+ /**
+ * Checks the query object model by executing it directly and matching the
+ * result against the given <code>nodes</code>. Then the QOM is executed
+ * again using {@link QueryObjectModel#getStatement()} with {@link
+ * Query#JCR_SQL2}.
+ *
+ * @param qom the query object model to check.
+ * @param nodes the result nodes.
+ * @throws RepositoryException if an error occurs while executing the
+ * query.
+ */
+ protected void checkQOM(QueryObjectModel qom, Node[] nodes)
+ throws RepositoryException {
+ checkResult(qom.execute(), nodes);
+ checkResult(qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(), nodes);
+ }
+
+ /**
+ * Checks the query object model by executing it directly and matching the
+ * result against the given <code>nodes</code>. Then the QOM is executed
+ * again using {@link QueryObjectModel#getStatement()} with
+ * {@link Query#JCR_SQL2}.
+ *
+ * @param qom the query object model to check.
+ * @param selectorNames the selector names of the qom.
+ * @param nodes the result nodes.
+ * @throws RepositoryException if an error occurs while executing the
+ * query.
+ */
+ protected void checkQOM(QueryObjectModel qom,
+ String[] selectorNames,
+ Node[][] nodes) throws RepositoryException {
+ checkResult(qom.execute(), selectorNames, nodes);
+ checkResult(qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute(),
+ selectorNames, nodes);
+ }
+
protected void checkResult(QueryResult result,
String[] selectorNames,
Node[][] nodes)
@@ -145,4 +192,27 @@
return "";
}
}
+
+ /**
+ * Calls back the <code>callable</code> first with the <code>qom</code> and
+ * then a JCR_SQL2 query created from {@link QueryObjectModel#getStatement()}.
+ *
+ * @param qom a query object model.
+ * @param callable the callback.
+ * @throws RepositoryException if an error occurs.
+ */
+ protected void forQOMandSQL2(QueryObjectModel qom, Callable callable)
+ throws RepositoryException {
+ List queries = new ArrayList();
+ queries.add(qom);
+ queries.add(qm.createQuery(qom.getStatement(), Query.JCR_SQL2));
+ for (Iterator it = queries.iterator(); it.hasNext();) {
+ callable.call((Query) it.next());
+ }
+ }
+
+ protected interface Callable {
+
+ public Object call(Query query) throws RepositoryException;
+ }
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AndConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AndConstraintTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AndConstraintTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/AndConstraintTest.java Thu Jun 18 14:17:52 2009
@@ -19,6 +19,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Node;
import javax.jcr.query.QueryResult;
+import javax.jcr.query.Query;
/**
* <code>AndConstraintTest</code> contains tests that check AND constraints.
@@ -46,5 +47,12 @@
null
).execute();
checkResult(result, new Node[]{n1});
+
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+ "ISDESCENDANTNODE(s, [" + testRootNode.getPath() + "]) " +
+ "AND s.[" + propertyName1 + "] IS NOT NULL " +
+ "AND s.[" + propertyName2 + "] IS NOT NULL";
+ result = qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ checkResult(result, new Node[]{n1});
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/BindVariableValueTest.java Thu Jun 18 14:17:52 2009
@@ -45,11 +45,13 @@
private static final String URI_VALUE = "http://example.com/";
- private Query query;
+ private Query qomQuery;
+
+ private Query sqlQuery;
protected void setUp() throws Exception {
super.setUp();
- query = qf.createQuery(
+ qomQuery = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.childNode("s", testRoot),
@@ -59,16 +61,23 @@
qf.bindVariable("v")
)
), null, null);
+ sqlQuery = qm.createQuery(qomQuery.getStatement(), Query.JCR_SQL2);
}
protected void tearDown() throws Exception {
- query = null;
+ qomQuery = null;
super.tearDown();
}
public void testIllegalArgumentException() throws RepositoryException {
try {
- bindVariableValue(query, "x", vf.createValue(STRING_VALUE));
+ bindVariableValue(qomQuery, "x", vf.createValue(STRING_VALUE));
+ fail("Query.bindValue() must throw IllegalArgumentException for unknown variable name");
+ } catch (IllegalArgumentException e) {
+ // expected
+ }
+ try {
+ bindVariableValue(sqlQuery, "x", vf.createValue(STRING_VALUE));
fail("Query.bindValue() must throw IllegalArgumentException for unknown variable name");
} catch (IllegalArgumentException e) {
// expected
@@ -80,8 +89,11 @@
n.setProperty(propertyName1, STRING_VALUE);
superuser.save();
- bindVariableValue(query, "v", vf.createValue(STRING_VALUE));
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", vf.createValue(STRING_VALUE));
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", vf.createValue(STRING_VALUE));
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testDate() throws RepositoryException {
@@ -89,8 +101,11 @@
n.setProperty(propertyName1, DATE_VALUE);
superuser.save();
- bindVariableValue(query, "v", vf.createValue(DATE_VALUE));
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(sqlQuery, "v", vf.createValue(DATE_VALUE));
+ checkResult(sqlQuery.execute(), new Node[]{n});
+
+ bindVariableValue(qomQuery, "v", vf.createValue(DATE_VALUE));
+ checkResult(qomQuery.execute(), new Node[]{n});
}
public void testLong() throws RepositoryException {
@@ -98,8 +113,11 @@
n.setProperty(propertyName1, LONG_VALUE);
superuser.save();
- bindVariableValue(query, "v", vf.createValue(LONG_VALUE));
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", vf.createValue(LONG_VALUE));
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", vf.createValue(LONG_VALUE));
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testDouble() throws RepositoryException {
@@ -107,8 +125,11 @@
n.setProperty(propertyName1, DOUBLE_VALUE);
superuser.save();
- bindVariableValue(query, "v", vf.createValue(DOUBLE_VALUE));
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", vf.createValue(DOUBLE_VALUE));
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", vf.createValue(DOUBLE_VALUE));
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testBoolean() throws RepositoryException {
@@ -116,8 +137,11 @@
n.setProperty(propertyName1, BOOLEAN_VALUE);
superuser.save();
- bindVariableValue(query, "v", vf.createValue(BOOLEAN_VALUE));
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", vf.createValue(BOOLEAN_VALUE));
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", vf.createValue(BOOLEAN_VALUE));
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testName() throws RepositoryException {
@@ -126,8 +150,11 @@
n.setProperty(propertyName1, name);
superuser.save();
- bindVariableValue(query, "v", name);
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", name);
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", name);
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testPath() throws RepositoryException {
@@ -136,8 +163,11 @@
n.setProperty(propertyName1, path);
superuser.save();
- bindVariableValue(query, "v", path);
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", path);
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", path);
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testReference() throws RepositoryException {
@@ -152,8 +182,11 @@
superuser.save();
- bindVariableValue(query, "v", vf.createValue(n));
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", vf.createValue(n));
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", vf.createValue(n));
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testWeakReference() throws RepositoryException {
@@ -167,9 +200,11 @@
n.setProperty(propertyName1, vf.createValue(n, true));
superuser.save();
+ bindVariableValue(qomQuery, "v", vf.createValue(n, true));
+ checkResult(qomQuery.execute(), new Node[]{n});
- bindVariableValue(query, "v", vf.createValue(n, true));
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(sqlQuery, "v", vf.createValue(n, true));
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testURI() throws RepositoryException {
@@ -178,8 +213,11 @@
n.setProperty(propertyName1, value);
superuser.save();
- bindVariableValue(query, "v", value);
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", value);
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", value);
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
public void testDecimal() throws RepositoryException {
@@ -188,7 +226,10 @@
n.setProperty(propertyName1, value);
superuser.save();
- bindVariableValue(query, "v", value);
- checkResult(query.execute(), new Node[]{n});
+ bindVariableValue(qomQuery, "v", value);
+ checkResult(qomQuery.execute(), new Node[]{n});
+
+ bindVariableValue(sqlQuery, "v", value);
+ checkResult(sqlQuery.execute(), new Node[]{n});
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeJoinConditionTest.java Thu Jun 18 14:17:52 2009
@@ -40,19 +40,19 @@
n1 = testRootNode.addNode(nodeName1, testNodeType);
n2 = n1.addNode(nodeName2, testNodeType);
n2.addMixin(mixReferenceable);
- testRootNode.save();
+ superuser.save();
}
public void testInnerJoin() throws RepositoryException {
JoinCondition c = qf.childNodeJoinCondition(LEFT, RIGHT);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
- checkResult(qom.execute(), new Node[][]{{n2, n1}});
+ checkQOM(qom, new Node[][]{{n2, n1}});
}
public void testRightOuterJoin() throws RepositoryException {
JoinCondition c = qf.childNodeJoinCondition(LEFT, RIGHT);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
- checkResult(qom.execute(), new Node[][]{{n2, n1}, {null, n2}});
+ checkQOM(qom, new Node[][]{{n2, n1}, {null, n2}});
}
public void testLeftOuterJoin() throws RepositoryException {
@@ -65,6 +65,6 @@
} else {
result.add(new Node[]{n1, null});
}
- checkResult(qom.execute(), (Node[][]) result.toArray(new Node[result.size()][]));
+ checkQOM(qom, (Node[][]) result.toArray(new Node[result.size()][]));
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ChildNodeTest.java Thu Jun 18 14:17:52 2009
@@ -25,43 +25,45 @@
import javax.jcr.nodetype.NodeType;
import javax.jcr.query.Query;
import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.qom.QueryObjectModel;
/**
- * <code>ChildNodeTest</code>...
+ * <code>ChildNodeTest</code> contains test cases that cover the QOM ChildNode
+ * condition.
*/
public class ChildNodeTest extends AbstractQOMTest {
public void testChildNode() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
- testRootNode.save();
+ superuser.save();
- Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+ QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
qf.childNode("s", testRoot), null, null);
- checkResult(q.execute(), new Node[]{n});
+ checkQOM(qom, new Node[]{n});
}
public void testChildNodes() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
Node n2 = testRootNode.addNode(nodeName2, testNodeType);
Node n3 = testRootNode.addNode(nodeName3, testNodeType);
- testRootNode.save();
+ superuser.save();
- Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+ QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
qf.childNode("s", testRoot), null, null);
- checkResult(q.execute(), new Node[]{n1, n2, n3});
+ checkQOM(qom, new Node[]{n1, n2, n3});
}
public void testPathDoesNotExist() throws RepositoryException {
- Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+ QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
qf.childNode("s", testRoot + "/" + nodeName1),
null, null);
- checkResult(q.execute(), new Node[]{});
+ checkQOM(qom, new Node[]{});
}
public void testChildNodesDoNotMatchSelector()
throws RepositoryException, NotExecutableException {
testRootNode.addNode(nodeName1, testNodeType);
- testRootNode.save();
+ superuser.save();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
@@ -70,9 +72,10 @@
NodeType nt = it.nextNodeType();
if (!testNt.isNodeType(nt.getName())) {
// perform test
- Query q = qf.createQuery(qf.selector(nt.getName(), "s"),
+ QueryObjectModel qom = qf.createQuery(
+ qf.selector(nt.getName(), "s"),
qf.childNode("s", testRoot), null, null);
- checkResult(q.execute(), new Node[]{});
+ checkQOM(qom, new Node[]{});
return;
}
}
@@ -89,18 +92,35 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+ "ISCHILDNODE(s, [" + testPath + "])";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("ISCHILDNODE() with relative path argument must throw InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testSyntacticallyInvalidPath() throws RepositoryException {
+ String invalidPath = testRoot + "/" + nodeName1 + "[";
try {
Query q = qf.createQuery(qf.selector(testNodeType, "s"),
- qf.childNode("s", testRoot + "/" + nodeName1 + "["),
+ qf.childNode("s", invalidPath),
null, null);
q.execute();
fail("ChildNode with syntactically invalid path argument must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+ "ISCHILDNODE(s, [" + invalidPath + "])";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("ISCHILDNODE() with syntactically invalid path argument must throw InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testNotASelectorName() throws RepositoryException {
@@ -108,10 +128,17 @@
Query q = qf.createQuery(qf.selector(testNodeType, "s"),
qf.childNode("x", testRoot), null, null);
q.execute();
- fail("ChildNode with an invalid selector name must throw InvalidQueryException");
+ fail("ChildNode with an unknown selector name must throw InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+ "ISCHILDNODE(x, [" + testRoot + "])";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("ISCHILDNODE() with an unknown selector name must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
}
-
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ColumnTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ColumnTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ColumnTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/ColumnTest.java Thu Jun 18 14:17:52 2009
@@ -32,6 +32,7 @@
import javax.jcr.query.QueryResult;
import javax.jcr.query.RowIterator;
import javax.jcr.query.Row;
+import javax.jcr.query.Query;
/**
* <code>ColumnTest</code> contains test cases related to QOM column.
@@ -61,22 +62,27 @@
null,
null,
new Column[]{qf.column(SELECTOR_1, null, null)});
- QueryResult result = qom.execute();
- List names = new ArrayList(Arrays.asList(result.getColumnNames()));
- NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
- NodeType nt = ntMgr.getNodeType(testNodeType);
- PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
- for (int i = 0; i < propDefs.length; i++) {
- PropertyDefinition propDef = propDefs[i];
- if (!propDef.isMultiple() && !propDef.getName().equals("*")) {
- String columnName = SELECTOR_1 + "." + propDef.getName();
- assertTrue("Missing column: " + columnName,
- names.remove(columnName));
+ forQOMandSQL2(qom, new Callable() {
+ public Object call(Query query) throws RepositoryException {
+ QueryResult result = query.execute();
+ List names = new ArrayList(Arrays.asList(result.getColumnNames()));
+ NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
+ NodeType nt = ntMgr.getNodeType(testNodeType);
+ PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
+ for (int i = 0; i < propDefs.length; i++) {
+ PropertyDefinition propDef = propDefs[i];
+ if (!propDef.isMultiple() && !propDef.getName().equals("*")) {
+ String columnName = SELECTOR_1 + "." + propDef.getName();
+ assertTrue("Missing column: " + columnName,
+ names.remove(columnName));
+ }
+ }
+ for (Iterator it = names.iterator(); it.hasNext(); ) {
+ fail(it.next() + " is not a property on node type " + testNodeType);
+ }
+ return null;
}
- }
- for (Iterator it = names.iterator(); it.hasNext(); ) {
- fail(it.next() + " is not a property on node type " + testNodeType);
- }
+ });
}
/**
@@ -91,12 +97,17 @@
null,
null,
new Column[]{qf.column(SELECTOR_1, propertyName1, propertyName1)});
- QueryResult result = qom.execute();
- List names = new ArrayList(Arrays.asList(result.getColumnNames()));
- assertTrue("Missing column: " + propertyName1, names.remove(propertyName1));
- for (Iterator it = names.iterator(); it.hasNext(); ) {
- fail(it.next() + " was not declared as a column");
- }
+ forQOMandSQL2(qom, new Callable() {
+ public Object call(Query query) throws RepositoryException {
+ QueryResult result = query.execute();
+ List names = new ArrayList(Arrays.asList(result.getColumnNames()));
+ assertTrue("Missing column: " + propertyName1, names.remove(propertyName1));
+ for (Iterator it = names.iterator(); it.hasNext(); ) {
+ fail(it.next() + " was not declared as a column");
+ }
+ return null;
+ }
+ });
}
public void testMultiColumn() throws RepositoryException {
@@ -104,8 +115,8 @@
n.setProperty(propertyName1, TEST_VALUE);
superuser.save();
- String columnName1 = SELECTOR_1 + "." + propertyName1;
- String columnName2 = SELECTOR_2 + "." + propertyName1;
+ final String columnName1 = SELECTOR_1 + "." + propertyName1;
+ final String columnName2 = SELECTOR_2 + "." + propertyName1;
QueryObjectModel qom = qf.createQuery(
qf.join(
qf.selector(testNodeType, SELECTOR_1),
@@ -120,10 +131,15 @@
qf.column(SELECTOR_2, propertyName1, columnName2)
}
);
- RowIterator rows = qom.execute().getRows();
- assertTrue("empty result", rows.hasNext());
- Row r = rows.nextRow();
- assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName1).getString());
- assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName2).getString());
+ forQOMandSQL2(qom, new Callable() {
+ public Object call(Query query) throws RepositoryException {
+ RowIterator rows = query.execute().getRows();
+ assertTrue("empty result", rows.hasNext());
+ Row r = rows.nextRow();
+ assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName1).getString());
+ assertEquals("unexpected value", TEST_VALUE, r.getValue(columnName2).getString());
+ return null;
+ }
+ });
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeJoinConditionTest.java Thu Jun 18 14:17:52 2009
@@ -40,19 +40,19 @@
n1 = testRootNode.addNode(nodeName1, testNodeType);
n2 = n1.addNode(nodeName2, testNodeType);
n2.addMixin(mixReferenceable);
- testRootNode.save();
+ superuser.save();
}
public void testInnerJoin() throws RepositoryException {
JoinCondition c = qf.descendantNodeJoinCondition(LEFT, RIGHT);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
- checkResult(qom.execute(), new Node[][]{{n2, n1}});
+ checkQOM(qom, new Node[][]{{n2, n1}});
}
public void testRightOuterJoin() throws RepositoryException {
JoinCondition c = qf.descendantNodeJoinCondition(LEFT, RIGHT);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
- checkResult(qom.execute(), new Node[][]{{n2, n1}, {null, n2}});
+ checkQOM(qom, new Node[][]{{n2, n1}, {null, n2}});
}
public void testLeftOuterJoin() throws RepositoryException {
@@ -79,6 +79,6 @@
// n1 not yet covered
result.add(new Node[]{n1, null});
}
- checkResult(qom.execute(), (Node[][]) result.toArray(new Node[result.size()][]));
+ checkQOM(qom, (Node[][]) result.toArray(new Node[result.size()][]));
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/DescendantNodeTest.java Thu Jun 18 14:17:52 2009
@@ -25,43 +25,45 @@
import javax.jcr.nodetype.NodeType;
import javax.jcr.query.Query;
import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.qom.QueryObjectModel;
/**
- * <code>DescendantNodeTest</code>...
+ * <code>DescendantNodeTest</code> contains test cases related to QOM
+ * DescendantNode constraints.
*/
public class DescendantNodeTest extends AbstractQOMTest {
public void testDescendantNode() throws RepositoryException {
Node n = testRootNode.addNode(nodeName1, testNodeType);
- testRootNode.save();
+ superuser.save();
- Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+ QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
qf.descendantNode("s", testRoot), null, null);
- checkResult(q.execute(), new Node[]{n});
+ checkQOM(qom, new Node[]{n});
}
public void testDescendantNodes() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
Node n2 = testRootNode.addNode(nodeName2, testNodeType);
Node n21 = n2.addNode(nodeName1, testNodeType);
- testRootNode.save();
+ superuser.save();
- Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+ QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
qf.descendantNode("s", testRoot), null, null);
- checkResult(q.execute(), new Node[]{n1, n2, n21});
+ checkQOM(qom, new Node[]{n1, n2, n21});
}
public void testPathDoesNotExist() throws RepositoryException {
- Query q = qf.createQuery(qf.selector(testNodeType, "s"),
+ QueryObjectModel qom = qf.createQuery(qf.selector(testNodeType, "s"),
qf.descendantNode("s", testRoot + "/" + nodeName1),
null, null);
- checkResult(q.execute(), new Node[]{});
+ checkQOM(qom, new Node[]{});
}
public void testDescendantNodesDoNotMatchSelector()
throws RepositoryException, NotExecutableException {
testRootNode.addNode(nodeName1, testNodeType);
- testRootNode.save();
+ superuser.save();
NodeTypeManager ntMgr = superuser.getWorkspace().getNodeTypeManager();
NodeTypeIterator it = ntMgr.getPrimaryNodeTypes();
@@ -70,9 +72,9 @@
NodeType nt = it.nextNodeType();
if (!testNt.isNodeType(nt.getName())) {
// perform test
- Query q = qf.createQuery(qf.selector(nt.getName(), "s"),
+ QueryObjectModel qom = qf.createQuery(qf.selector(nt.getName(), "s"),
qf.descendantNode("s", testRoot), null, null);
- checkResult(q.execute(), new Node[]{});
+ checkQOM(qom, new Node[]{});
return;
}
}
@@ -89,18 +91,34 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+ "ISDESCENDANTNODE(s, [" + testPath + "])";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("ISDESCENDANTNODE() with relative path argument must throw InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testSyntacticallyInvalidPath() throws RepositoryException {
+ String invalidPath = testRoot + "/" + nodeName1 + "[";
try {
Query q = qf.createQuery(qf.selector(testNodeType, "s"),
- qf.descendantNode("s", testRoot + "/" + nodeName1 +
- "["), null, null);
+ qf.descendantNode("s", invalidPath), null, null);
q.execute();
fail("DescendantNode with syntactically invalid path argument must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+ "ISDESCENDANTNODE(s, [" + invalidPath + "])";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("ISDESCENDANTNODE() with syntactically invalid path argument must throw InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testNotASelectorName() throws RepositoryException {
@@ -108,7 +126,15 @@
Query q = qf.createQuery(qf.selector(testNodeType, "s"),
qf.descendantNode("x", testRoot), null, null);
q.execute();
- fail("DescendantNode with an invalid selector name must throw InvalidQueryException");
+ fail("DescendantNode with an unknown selector name must throw InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s WHERE " +
+ "ISDESCENDANTNODE(x, [" + testRoot + "])";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("ISDESCENDANTNODE() with an unknown selector name must throw InvalidQueryException");
} catch (InvalidQueryException e) {
// expected
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/EquiJoinConditionTest.java Thu Jun 18 14:17:52 2009
@@ -42,42 +42,42 @@
n2.setProperty(propertyName1, value);
n2.setProperty(propertyName2, value);
n2.addMixin(mixReferenceable);
- testRootNode.save();
+ superuser.save();
}
public void testInnerJoin1() throws RepositoryException {
JoinCondition c = qf.equiJoinCondition(
LEFT, propertyName1, RIGHT, propertyName2);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
- checkResult(qom.execute(), new Node[][]{{n1, n2}, {n2, n2}});
+ checkQOM(qom, new Node[][]{{n1, n2}, {n2, n2}});
}
public void testInnerJoin2() throws RepositoryException {
JoinCondition c = qf.equiJoinCondition(
LEFT, propertyName2, RIGHT, propertyName1);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_INNER, c);
- checkResult(qom.execute(), new Node[][]{{n2, n1}, {n2, n2}});
+ checkQOM(qom, new Node[][]{{n2, n1}, {n2, n2}});
}
public void testRightOuterJoin1() throws RepositoryException {
JoinCondition c = qf.equiJoinCondition(
LEFT, propertyName1, RIGHT, propertyName2);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
- checkResult(qom.execute(), new Node[][]{{null, n1}, {n1, n2}, {n2, n2}});
+ checkQOM(qom, new Node[][]{{null, n1}, {n1, n2}, {n2, n2}});
}
public void testRightOuterJoin2() throws RepositoryException {
JoinCondition c = qf.equiJoinCondition(
LEFT, propertyName2, RIGHT, propertyName1);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_RIGHT_OUTER, c);
- checkResult(qom.execute(), new Node[][]{{n2, n1}, {n2, n2}});
+ checkQOM(qom, new Node[][]{{n2, n1}, {n2, n2}});
}
public void testLeftOuterJoin1() throws RepositoryException {
JoinCondition c = qf.equiJoinCondition(
LEFT, propertyName1, RIGHT, propertyName2);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, c);
- checkResult(qom.execute(), new Node[][]{{n1, n2}, {n2, n2}});
+ checkQOM(qom, new Node[][]{{n1, n2}, {n2, n2}});
}
@@ -85,6 +85,6 @@
JoinCondition c = qf.equiJoinCondition(
LEFT, propertyName2, RIGHT, propertyName1);
QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_JOIN_TYPE_LEFT_OUTER, c);
- checkResult(qom.execute(), new Node[][]{{n1, null}, {n2, n1}, {n2, n2}});
+ checkQOM(qom, new Node[][]{{n1, null}, {n2, n1}, {n2, n2}});
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/FullTextSearchScoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/FullTextSearchScoreTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/FullTextSearchScoreTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/FullTextSearchScoreTest.java Thu Jun 18 14:17:52 2009
@@ -20,8 +20,9 @@
import javax.jcr.Node;
import javax.jcr.query.qom.Ordering;
import javax.jcr.query.qom.QueryObjectModelFactory;
-import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.QueryObjectModel;
import javax.jcr.query.RowIterator;
+import javax.jcr.query.Query;
/**
* <code>FullTextSearchScoreTest</code> contains fulltext search score tests.
@@ -41,7 +42,7 @@
}
public void testOrdering() throws RepositoryException {
- QueryResult result = qf.createQuery(
+ QueryObjectModel qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.fullTextSearch("s", null, "fox"),
@@ -49,21 +50,25 @@
),
new Ordering[]{qf.ascending(qf.fullTextSearchScore("s"))},
null
- ).execute();
-
- RowIterator rows = result.getRows();
- double previousScore = Double.NaN;
- while (rows.hasNext()) {
- double score = rows.nextRow().getScore("s");
- if (!Double.isNaN(previousScore)) {
- assertTrue("wrong order", previousScore <= score);
+ );
+ forQOMandSQL2(qom, new Callable() {
+ public Object call(Query query) throws RepositoryException {
+ RowIterator rows = query.execute().getRows();
+ double previousScore = Double.NaN;
+ while (rows.hasNext()) {
+ double score = rows.nextRow().getScore("s");
+ if (!Double.isNaN(previousScore)) {
+ assertTrue("wrong order", previousScore <= score);
+ }
+ previousScore = score;
+ }
+ return null;
}
- previousScore = score;
- }
+ });
}
public void testConstraint() throws RepositoryException {
- QueryResult result = qf.createQuery(
+ QueryObjectModel qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.and(
@@ -78,14 +83,18 @@
),
new Ordering[]{qf.descending(qf.fullTextSearchScore("s"))},
null
- ).execute();
-
- RowIterator rows = result.getRows();
- while (rows.hasNext()) {
- double score = rows.nextRow().getScore("s");
- if (!Double.isNaN(score)) {
- assertTrue("wrong full text search score", Double.MIN_VALUE < score);
+ );
+ forQOMandSQL2(qom, new Callable() {
+ public Object call(Query query) throws RepositoryException {
+ RowIterator rows = query.execute().getRows();
+ while (rows.hasNext()) {
+ double score = rows.nextRow().getScore("s");
+ if (!Double.isNaN(score)) {
+ assertTrue("wrong full text search score", Double.MIN_VALUE < score);
+ }
+ }
+ return null;
}
- }
+ });
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/LengthTest.java Thu Jun 18 14:17:52 2009
@@ -25,7 +25,9 @@
import javax.jcr.Binary;
import javax.jcr.query.QueryResult;
import javax.jcr.query.InvalidQueryException;
+import javax.jcr.query.Query;
import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModel;
import java.io.ByteArrayInputStream;
import java.util.Calendar;
@@ -153,7 +155,7 @@
superuser.save();
String length = String.valueOf(node.getProperty(propertyName1).getLength());
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
}
public void testLengthBinaryLiteral() throws RepositoryException {
@@ -163,7 +165,7 @@
String length = String.valueOf(node.getProperty(propertyName1).getLength());
Binary b = vf.createBinary(new ByteArrayInputStream(length.getBytes()));
try {
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
vf.createValue(b));
} finally {
b.dispose();
@@ -175,7 +177,7 @@
superuser.save();
double length = node.getProperty(propertyName1).getLength();
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
}
public void testLengthDateLiteral() throws RepositoryException {
@@ -184,12 +186,12 @@
Calendar length = Calendar.getInstance();
length.setTimeInMillis(node.getProperty(propertyName1).getLength());
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
}
public void testLengthBooleanLiteral() throws RepositoryException {
try {
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(false));
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(false));
fail("Boolean literal cannot be converted to long");
} catch (InvalidQueryException e) {
// expected
@@ -198,7 +200,7 @@
public void testLengthNameLiteral() throws RepositoryException {
try {
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(
propertyName1, PropertyType.NAME));
fail("Name literal cannot be converted to long");
} catch (InvalidQueryException e) {
@@ -208,7 +210,7 @@
public void testLengthPathLiteral() throws RepositoryException {
try {
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(
node.getPath(), PropertyType.PATH));
fail("Path literal cannot be converted to long");
} catch (InvalidQueryException e) {
@@ -226,7 +228,7 @@
throw new NotExecutableException("Cannot add mix:referenceable to node");
}
try {
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(node));
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(node));
fail("Reference literal cannot be converted to long");
} catch (InvalidQueryException e) {
// expected
@@ -243,7 +245,7 @@
throw new NotExecutableException("Cannot add mix:referenceable to node");
}
try {
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(node, true));
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(node, true));
fail("Reference literal cannot be converted to long");
} catch (InvalidQueryException e) {
// expected
@@ -252,7 +254,7 @@
public void testLengthURILiteral() throws RepositoryException {
try {
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
vf.createValue(node.getPath(), PropertyType.URI));
fail("URI literal cannot be converted to long");
} catch (InvalidQueryException e) {
@@ -265,7 +267,7 @@
superuser.save();
BigDecimal length = new BigDecimal(node.getProperty(propertyName1).getLength());
- executeQuery(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
+ executeQueries(propertyName1, QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, vf.createValue(length));
}
//------------------------< internal helpers >------------------------------
@@ -295,26 +297,31 @@
String operator,
long length,
boolean matches) throws RepositoryException {
- Node[] result;
+ Node[] expected;
if (matches) {
- result = new Node[]{node};
+ expected = new Node[]{node};
} else {
- result = new Node[0];
+ expected = new Node[0];
+ }
+ QueryResult[] results = executeQueries(propertyName, operator, length);
+ for (int i = 0; i < results.length; i++) {
+ checkResult(results[i], expected);
}
- checkResult(executeQuery(propertyName, operator, length), result);
}
- private QueryResult executeQuery(String propertyName,
- String operator,
- long length) throws RepositoryException {
+ private QueryResult[] executeQueries(String propertyName,
+ String operator,
+ long length)
+ throws RepositoryException {
Value v = vf.createValue(length);
- return executeQuery(propertyName, operator, v);
+ return executeQueries(propertyName, operator, v);
}
- private QueryResult executeQuery(String propertyName,
- String operator,
- Value length) throws RepositoryException {
- return qf.createQuery(
+ private QueryResult[] executeQueries(String propertyName,
+ String operator,
+ Value length)
+ throws RepositoryException {
+ QueryObjectModel qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.childNode("s", testRoot),
@@ -325,6 +332,10 @@
operator,
qf.literal(length))
- ), null, null).execute();
+ ), null, null);
+ QueryResult[] results = new QueryResult[2];
+ results[0] = qom.execute();
+ results[1] = qm.createQuery(qom.getStatement(), Query.JCR_SQL2).execute();
+ return results;
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeLocalNameTest.java Thu Jun 18 14:17:52 2009
@@ -22,6 +22,7 @@
import javax.jcr.PropertyType;
import javax.jcr.query.Query;
import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModel;
import java.util.Calendar;
import java.math.BigDecimal;
@@ -68,62 +69,62 @@
public void testBinaryLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(
nodeLocalName, PropertyType.BINARY);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
}
public void testDateLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(Calendar.getInstance());
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testDoubleLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(Math.PI);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testDecimalLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(new BigDecimal(283));
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testLongLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(283);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testBooleanLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(true);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testNameLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(
nodeLocalName, PropertyType.NAME);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
}
public void testPathLiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue(
nodeLocalName, PropertyType.PATH);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
literal = superuser.getValueFactory().createValue(
node1.getPath(), PropertyType.PATH);
- q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
literal = superuser.getValueFactory().createValue(
nodeName1 + "/" + nodeName1, PropertyType.PATH);
- q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testReferenceLiteral() throws RepositoryException {
@@ -132,8 +133,8 @@
}
superuser.save();
Value literal = superuser.getValueFactory().createValue(node1);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testWeakReferenceLiteral() throws RepositoryException {
@@ -142,14 +143,14 @@
}
superuser.save();
Value literal = superuser.getValueFactory().createValue(node1, true);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testURILiteral() throws RepositoryException {
Value literal = superuser.getValueFactory().createValue("http://example.com", PropertyType.URI);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{});
}
public void testEqualTo() throws RepositoryException {
@@ -197,8 +198,8 @@
boolean matches)
throws RepositoryException {
Value value = superuser.getValueFactory().createValue(literal);
- Query q = createQuery(operator, value);
- checkResult(q.execute(), matches ? new Node[]{node1} : new Node[0]);
+ QueryObjectModel qom = createQuery(operator, value);
+ checkQOM(qom, matches ? new Node[]{node1} : new Node[0]);
}
private String createLexicographicallyGreater(String name) {
@@ -213,7 +214,7 @@
return tmp.toString();
}
- private Query createQuery(String operator, Value literal)
+ private QueryObjectModel createQuery(String operator, Value literal)
throws RepositoryException {
return qf.createQuery(
qf.selector(testNodeType, "s"),
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NodeNameTest.java Thu Jun 18 14:17:52 2009
@@ -23,6 +23,7 @@
import javax.jcr.query.Query;
import javax.jcr.query.InvalidQueryException;
import javax.jcr.query.qom.QueryObjectModelConstants;
+import javax.jcr.query.qom.QueryObjectModel;
import java.util.Calendar;
import java.math.BigDecimal;
@@ -48,8 +49,8 @@
public void testStringLiteral() throws RepositoryException {
Value literal = vf.createValue(nodeName1);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
}
public void testStringLiteralInvalidName() throws RepositoryException {
@@ -60,13 +61,21 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = '" + literal.getString() + "'";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with STRING that cannot be converted to NAME must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testBinaryLiteral() throws RepositoryException {
Value literal = vf.createValue(
nodeName1, PropertyType.BINARY);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
}
public void testDateLiteral() throws RepositoryException {
@@ -77,6 +86,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS DATE)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with DATE must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testDoubleLiteral() throws RepositoryException {
@@ -87,6 +104,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS DOUBLE)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with DOUBLE must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testDecimalLiteral() throws RepositoryException {
@@ -97,6 +122,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS DECIMAL)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with DECIMAL must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testLongLiteral() throws RepositoryException {
@@ -107,6 +140,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = " + literal.getString();
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with LONG must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testBooleanLiteral() throws RepositoryException {
@@ -117,18 +158,26 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = " + literal.getString();
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with BOOLEAN must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testNameLiteral() throws RepositoryException {
Value literal = vf.createValue(nodeName1, PropertyType.NAME);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
}
public void testPathLiteral() throws RepositoryException {
Value literal = vf.createValue(nodeName1, PropertyType.PATH);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
literal = vf.createValue(node1.getPath(), PropertyType.PATH);
try {
@@ -137,6 +186,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS PATH)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with absolute PATH must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
literal = vf.createValue(nodeName1 + "/" + nodeName1, PropertyType.PATH);
try {
@@ -145,6 +202,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS PATH)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with PATH length >1 must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testReferenceLiteral() throws RepositoryException {
@@ -159,6 +224,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS REFERENCE)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with REFERENCE must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testWeakReferenceLiteral() throws RepositoryException {
@@ -173,6 +246,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS WEAKREFERENCE)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with absolute WEAKREFERENCE must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
/**
@@ -186,8 +267,8 @@
*/
public void testURILiteral() throws RepositoryException {
Value literal = vf.createValue("./" + nodeName1, PropertyType.URI);
- Query q = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
- checkResult(q.execute(), new Node[]{node1});
+ QueryObjectModel qom = createQuery(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, literal);
+ checkQOM(qom, new Node[]{node1});
literal = vf.createValue("http://example.com", PropertyType.URI);
try {
@@ -196,6 +277,14 @@
} catch (InvalidQueryException e) {
// expected
}
+ try {
+ String stmt = "SELECT * FROM [" + testNodeType + "] AS s " +
+ "WHERE NAME(s) = CAST('" + literal.getString() + "' AS URI)";
+ qm.createQuery(stmt, Query.JCR_SQL2).execute();
+ fail("NAME() comparison with URI that cannot be converted to NAME must fail with InvalidQueryException");
+ } catch (InvalidQueryException e) {
+ // expected
+ }
}
public void testEqualTo() throws RepositoryException {
@@ -223,8 +312,8 @@
boolean matches)
throws RepositoryException {
Value value = vf.createValue(literal);
- Query q = createQuery(operator, value);
- checkResult(q.execute(), matches ? new Node[]{node1} : new Node[0]);
+ QueryObjectModel qom = createQuery(operator, value);
+ checkQOM(qom, matches ? new Node[]{node1} : new Node[0]);
}
private String createLexicographicallyGreater(String name) {
@@ -239,7 +328,8 @@
return tmp.toString();
}
- private Query createQuery(String operator, Value literal) throws RepositoryException {
+ private QueryObjectModel createQuery(String operator, Value literal)
+ throws RepositoryException {
return qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NotConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NotConstraintTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NotConstraintTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/NotConstraintTest.java Thu Jun 18 14:17:52 2009
@@ -18,7 +18,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Node;
-import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.QueryObjectModel;
/**
* <code>NotConstraintTest</code> contains tests that check NOT constraints.
@@ -32,7 +32,7 @@
n2.setProperty(propertyName2, "bar");
superuser.save();
- QueryResult result = qf.createQuery(
+ QueryObjectModel qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.descendantNode("s", testRootNode.getPath()),
@@ -42,7 +42,7 @@
),
null,
null
- ).execute();
- checkResult(result, new Node[]{n2});
+ );
+ checkQOM(qom, new Node[]{n2});
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrConstraintTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrConstraintTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrConstraintTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrConstraintTest.java Thu Jun 18 14:17:52 2009
@@ -18,7 +18,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Node;
-import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.QueryObjectModel;
/**
* <code>OrConstraintTest</code> contains tests that check OR constraints.
@@ -32,7 +32,7 @@
n2.setProperty(propertyName2, "bar");
superuser.save();
- QueryResult result = qf.createQuery(
+ QueryObjectModel qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.descendantNode("s", testRootNode.getPath()),
@@ -43,7 +43,7 @@
),
null,
null
- ).execute();
- checkResult(result, new Node[]{n1, n2});
+ );
+ checkQOM(qom, new Node[]{n1, n2});
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrderingTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrderingTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrderingTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/OrderingTest.java Thu Jun 18 14:17:52 2009
@@ -51,12 +51,12 @@
qf.ascending(qf.propertyValue(RIGHT, propertyName2))
};
QueryObjectModel qom = createQuery(orderings);
- checkResultOrder(qom.execute(), SELECTOR_NAMES, new Node[][]{{n2, n2}, {n1, n2}});
+ checkResultOrder(qom, SELECTOR_NAMES, new Node[][]{{n2, n2}, {n1, n2}});
// descending
orderings[0] = qf.descending(qf.propertyValue(RIGHT, propertyName2));
qom = createQuery(orderings);
- checkResultOrder(qom.execute(), SELECTOR_NAMES, new Node[][]{{n1, n2}, {n2, n2}});
+ checkResultOrder(qom, SELECTOR_NAMES, new Node[][]{{n1, n2}, {n2, n2}});
}
protected QueryObjectModel createQuery(Ordering[] orderings)
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyExistenceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyExistenceTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyExistenceTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyExistenceTest.java Thu Jun 18 14:17:52 2009
@@ -18,7 +18,7 @@
import javax.jcr.RepositoryException;
import javax.jcr.Node;
-import javax.jcr.query.QueryResult;
+import javax.jcr.query.qom.QueryObjectModel;
/**
* <code>PropertyExistenceTest</code> performs a test with
@@ -33,20 +33,20 @@
n2.setProperty(propertyName2, "abc");
superuser.save();
- QueryResult result = qf.createQuery(
+ QueryObjectModel qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.childNode("s", testRoot),
qf.propertyExistence("s", propertyName1)
- ), null, null).execute();
- checkResult(result, new Node[]{n1});
+ ), null, null);
+ checkQOM(qom, new Node[]{n1});
- result = qf.createQuery(
+ qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.childNode("s", testRoot),
qf.propertyExistence("s", propertyName2)
- ), null, null).execute();
- checkResult(result, new Node[]{n2});
+ ), null, null);
+ checkQOM(qom, new Node[]{n2});
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyValueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyValueTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyValueTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/PropertyValueTest.java Thu Jun 18 14:17:52 2009
@@ -18,8 +18,8 @@
import javax.jcr.RepositoryException;
import javax.jcr.Node;
-import javax.jcr.query.QueryResult;
import javax.jcr.query.qom.QueryObjectModelFactory;
+import javax.jcr.query.qom.QueryObjectModel;
/**
* <code>PropertyValueTest</code> performs a test with property value
@@ -36,7 +36,7 @@
n2.setProperty(propertyName2, TEXT);
superuser.save();
- QueryResult result = qf.createQuery(
+ QueryObjectModel qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.childNode("s", testRoot),
@@ -45,10 +45,10 @@
QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO,
qf.literal(vf.createValue(TEXT))
)
- ), null, null).execute();
- checkResult(result, new Node[]{n1});
+ ), null, null);
+ checkQOM(qom, new Node[]{n1});
- result = qf.createQuery(
+ qom = qf.createQuery(
qf.selector(testNodeType, "s"),
qf.and(
qf.childNode("s", testRoot),
@@ -57,7 +57,7 @@
QueryObjectModelFactory.JCR_OPERATOR_EQUAL_TO,
qf.literal(vf.createValue(TEXT))
)
- ), null, null).execute();
- checkResult(result, new Node[]{n2});
+ ), null, null);
+ checkQOM(qom, new Node[]{n2});
}
}
Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/QueryObjectModelFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/QueryObjectModelFactoryTest.java?rev=786075&r1=786074&r2=786075&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/QueryObjectModelFactoryTest.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/query/qom/QueryObjectModelFactoryTest.java Thu Jun 18 14:17:52 2009
@@ -175,10 +175,10 @@
* Test case for {@link QueryObjectModelFactory#column(String, String, String)}
*/
public void testColumn() throws RepositoryException {
- Column col = qf.column(SELECTOR_NAME1, propertyName1, null);
+ Column col = qf.column(SELECTOR_NAME1, propertyName1, propertyName1);
assertEquals("Wrong selector name", SELECTOR_NAME1, col.getSelectorName());
assertEquals("Wrong property name", propertyName1, col.getPropertyName());
- assertNull("Column name must be null", col.getColumnName());
+ assertEquals("Wrong column name", propertyName1, col.getColumnName());
}
/**
@@ -264,7 +264,7 @@
PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1);
Ordering ordering = qf.ascending(propValue);
- Column column = qf.column(SELECTOR_NAME1, propertyName1, null);
+ Column column = qf.column(SELECTOR_NAME1, propertyName1, propertyName1);
QueryObjectModel qom = qf.createQuery(selector, propExist,
new Ordering[]{ordering}, new Column[]{column});
assertTrue("Not a selector source", qom.getSource() instanceof Selector);
@@ -311,7 +311,7 @@
PropertyExistence propExist = qf.propertyExistence(SELECTOR_NAME1, propertyName1);
PropertyValue propValue = qf.propertyValue(SELECTOR_NAME1, propertyName1);
Ordering ordering = qf.ascending(propValue);
- Column column = qf.column(SELECTOR_NAME1, propertyName1, null);
+ Column column = qf.column(SELECTOR_NAME1, propertyName1, propertyName1);
QueryObjectModel qom = qf.createQuery(selector, propExist,
new Ordering[]{ordering}, new Column[]{column});
assertTrue("Not a selector source", qom.getSource() instanceof Selector);