use of javax.jcr.Node in project jackrabbit by apache.
the class AutoFixCorruptNode method testAutoFix.
public void testAutoFix() throws Exception {
// new repository
TransientRepository rep = new TransientRepository(new File(TEST_DIR));
Session s = openSession(rep, false);
Node root = s.getRootNode();
// add nodes /test and /test/missing
Node test = root.addNode("test");
Node missing = test.addNode("missing");
missing.addMixin("mix:referenceable");
UUID id = UUID.fromString(missing.getIdentifier());
s.save();
s.logout();
destroyBundle(id, "workspaces/default");
// login and try the operation
s = openSession(rep, false);
test = s.getRootNode().getNode("test");
// try to add a node with the same name
try {
test.addNode("missing");
s.save();
} catch (RepositoryException e) {
// expected
}
s.logout();
s = openSession(rep, true);
test = s.getRootNode().getNode("test");
// iterate over all child nodes fixes the corruption
NodeIterator it = test.getNodes();
while (it.hasNext()) {
it.nextNode();
}
// try to add a node with the same name
test.addNode("missing");
s.save();
// try to delete the parent node
test.remove();
s.save();
s.logout();
rep.shutdown();
FileUtils.deleteDirectory(new File("repository"));
}
use of javax.jcr.Node in project jackrabbit by apache.
the class FulltextQueryTest method testContainsPropScopeXPath.
public void testContainsPropScopeXPath() throws RepositoryException {
Node n = testRootNode.addNode("node1");
n.setProperty("title", new String[] { "tEst text" });
n.setProperty("mytext", new String[] { "The quick brown Fox jumps over the lazy dog." });
n = testRootNode.addNode("node2");
n.setProperty("title", new String[] { "The quick brown Fox jumps over the lazy dog." });
n.setProperty("mytext", new String[] { "text text" });
testRootNode.save();
String sql = "/jcr:root" + testRoot + "/element(*, nt:unstructured)" + "[jcr:contains(@title, 'quick fox')]";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.XPATH);
checkResult(q.execute(), 1);
}
use of javax.jcr.Node in project jackrabbit by apache.
the class FulltextSQL2QueryTest method testFulltextSimpleSQL.
public void testFulltextSimpleSQL() throws Exception {
Node foo = testRootNode.addNode("foo");
foo.setProperty("mytext", new String[] { "the quick brown fox jumps over the lazy dog." });
testRootNode.save();
String sql = "SELECT * FROM [nt:unstructured]" + " WHERE ISCHILDNODE([" + testRoot + "])" + " AND CONTAINS(mytext, 'fox')";
Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
QueryResult result = q.execute();
checkResult(result, 1);
}
use of javax.jcr.Node in project jackrabbit by apache.
the class JoinTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
node = testRootNode.addNode("jointest", "nt:unstructured");
Node n1a = node.addNode("n1a", "nt:unstructured");
n1a.addMixin(NodeType.MIX_REFERENCEABLE);
n1a.setProperty("type", "parent");
Node n1b = node.addNode("n1b", "nt:unstructured");
n1b.addMixin(NodeType.MIX_REFERENCEABLE);
n1b.setProperty("type", "parent");
n1b.setProperty("testJoinWithOR4", "testJoinWithOR4");
Node n1c = node.addNode("n1c", "nt:unstructured");
n1c.addMixin(NodeType.MIX_REFERENCEABLE);
n1c.setProperty("type", "parent");
Node n3 = node.addNode("node3", "nt:unstructured");
n3.addMixin(NodeType.MIX_REFERENCEABLE);
n3.setProperty("testref", new String[] { n1a.getIdentifier() }, PropertyType.REFERENCE);
n3.setProperty("type", "child");
n3.setProperty("testJoinWithOR4", "testJoinWithOR4");
Node n4 = node.addNode("node4", "nt:unstructured");
n4.addMixin(NodeType.MIX_REFERENCEABLE);
n4.setProperty("testref", new String[] { n1b.getIdentifier() }, PropertyType.REFERENCE);
n4.setProperty("type", "child");
Node n5 = node.addNode("node5", "nt:unstructured");
n5.addMixin(NodeType.MIX_REFERENCEABLE);
n5.setProperty("testref", new String[] { n1c.getIdentifier() }, PropertyType.REFERENCE);
n5.setProperty("type", "child");
Node parent2 = testRootNode.addNode("jointest_other", "nt:unstructured");
parent2.setProperty("p", "abc");
Node p2n1 = parent2.addNode("p2n1", "nt:unstructured");
p2n1.setProperty("p", "abc");
Node p2n2 = parent2.addNode("p2n2", "nt:unstructured");
p2n2.setProperty("p", "xyz");
testRootNode.getSession().save();
}
use of javax.jcr.Node in project jackrabbit by apache.
the class ChildAxisQueryTest method testNotIsDescendantNodeQuery.
/**
* JCR-3337
*/
public void testNotIsDescendantNodeQuery() throws Exception {
Node foo = testRootNode.addNode("foo");
testRootNode.getSession().save();
String sql = "SELECT a.* FROM [nt:base] as a WHERE isdescendantnode(a,'" + testRootNode.getPath() + "') and not isdescendantnode(a,'" + foo.getPath() + "')";
executeSQL2Query(sql, new Node[] { foo });
}
Aggregations