use of javax.jcr.NodeIterator 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.NodeIterator in project jackrabbit by apache.
the class LazyResultSetQueryTest method tearDown.
protected void tearDown() throws Exception {
int count = 0;
for (NodeIterator it = testRootNode.getNodes(); it.hasNext(); ) {
it.nextNode().remove();
count++;
if (count % 10000 == 0) {
testRootNode.getSession().save();
}
}
testRootNode.getSession().save();
super.tearDown();
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class DerefTest method testDerefToVersionNode.
/**
* Checks if jcr:deref works when dereferencing into the version storage.
*/
public void testDerefToVersionNode() throws RepositoryException {
Node referenced = testRootNode.addNode(nodeName1);
referenced.addMixin(mixVersionable);
testRootNode.save();
Version version = referenced.checkin();
Node referencedVersionNode = version.getNode(jcrFrozenNode);
Node referencer = testRootNode.addNode(nodeName2);
referencer.setProperty(propertyName1, referencedVersionNode);
testRootNode.save();
String query = "/" + testRoot + "/*[@" + propertyName1 + "]/jcr:deref(@" + propertyName1 + ",'*')";
QueryManager qm = superuser.getWorkspace().getQueryManager();
Query q = qm.createQuery(query, Query.XPATH);
QueryResult qr = q.execute();
NodeIterator ni = qr.getNodes();
assertEquals("Must find one result in query", 1, ni.getSize());
while (ni.hasNext()) {
Node node = (Node) ni.next();
assertTrue(node.getProperty("jcr:frozenUuid").getString().equals(referenced.getUUID()));
}
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class LimitAndOffsetTest method testOffsetAndLimitWithGetSize.
public void testOffsetAndLimitWithGetSize() throws Exception {
query.setOffset(1);
QueryResult result = query.execute();
NodeIterator nodes = result.getNodes();
assertEquals(2, nodes.getSize());
if (result instanceof JackrabbitQueryResult) {
assertEquals(3, ((JackrabbitQueryResult) result).getTotalSize());
}
// JCR-2684: offset higher than total result => size == 0
query.setOffset(10);
result = query.execute();
nodes = result.getNodes();
assertFalse(nodes.hasNext());
assertEquals(0, nodes.getSize());
if (result instanceof JackrabbitQueryResult) {
assertEquals(3, ((JackrabbitQueryResult) result).getTotalSize());
}
query.setOffset(1);
query.setLimit(1);
result = query.execute();
nodes = result.getNodes();
assertEquals(1, nodes.getSize());
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class LimitAndOffsetTest method testOffsetAndSkip.
public void testOffsetAndSkip() throws Exception {
query.setOffset(1);
QueryResult result = query.execute();
NodeIterator nodes = result.getNodes();
nodes.skip(1);
assertTrue(node3.isSame(nodes.nextNode()));
}
Aggregations