use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class RestoreTest method testRestoreOrder2Jcr2_3.
/**
* Test the child ordering of restored nodes.
* @throws RepositoryException
*/
public void testRestoreOrder2Jcr2_3() throws RepositoryException, NotExecutableException {
// create a test-root that has orderable child nodes
Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
ensureMixinType(testRoot, mixVersionable);
versionableNode.getSession().save();
// create children of vNode and checkin
Node child1 = testRoot.addNode(nodeName1);
ensureMixinType(child1, mixVersionable);
Node child2 = testRoot.addNode(nodeName2);
ensureMixinType(child2, mixVersionable);
testRoot.getSession().save();
versionManager.checkin(child1.getPath());
versionManager.checkin(child2.getPath());
Version v1 = versionManager.checkin(testRoot.getPath());
// reoder nodes
versionManager.checkout(testRoot.getPath());
testRoot.orderBefore(nodeName2, nodeName1);
testRoot.getSession().save();
versionManager.checkin(testRoot.getPath());
// restore version 1.0
versionManager.restore(v1, true);
// check order
NodeIterator iter = testRoot.getNodes();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n1 = iter.nextNode();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n2 = iter.nextNode();
String orderOk = nodeName1 + ", " + nodeName2;
String order = n1.getName() + ", " + n2.getName();
assertEquals("Invalid child node ordering", orderOk, order);
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class RestoreTest method testRestoreOrderJcr2.
/**
* Test the child ordering of restored nodes.
* @throws RepositoryException
*/
public void testRestoreOrderJcr2() throws RepositoryException, NotExecutableException {
// create a test-root that has orderable child nodes
Node testRoot = versionableNode.addNode(nodeName4, "nt:unstructured");
ensureMixinType(testRoot, mixVersionable);
versionableNode.getSession().save();
// create children of vNode and checkin
Node child1 = testRoot.addNode(nodeName1);
ensureMixinType(child1, mixVersionable);
Node child2 = testRoot.addNode(nodeName2);
ensureMixinType(child2, mixVersionable);
testRoot.getSession().save();
versionManager.checkin(child1.getPath());
versionManager.checkin(child2.getPath());
Version v1 = versionManager.checkin(testRoot.getPath());
// remove node 1
versionManager.checkout(testRoot.getPath());
child1.remove();
testRoot.getSession().save();
versionManager.checkout(testRoot.getPath());
// restore version 1.0
versionManager.restore(v1, true);
// check order
NodeIterator iter = testRoot.getNodes();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n1 = iter.nextNode();
assertTrue(testRoot.getName() + " should have 2 child nodes.", iter.hasNext());
Node n2 = iter.nextNode();
String orderOk = nodeName1 + ", " + nodeName2;
String order = n1.getName() + ", " + n2.getName();
assertEquals("Invalid child node ordering", orderOk, order);
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class QueryTest method testQueryChildNodesOfRoot.
/**
* Queries the child nodes of the root node.
* @throws NotExecutableException
*/
public void testQueryChildNodesOfRoot() throws RepositoryException, NotExecutableException {
List<Node> nodes = new ArrayList<Node>();
for (NodeIterator it = superuser.getRootNode().getNodes(); it.hasNext(); ) {
nodes.add(it.nextNode());
}
Node[] children = nodes.toArray(new Node[nodes.size()]);
executeXPathQuery(superuser, "/jcr:root/*", children);
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class QueryTest method testSQL2Limit.
/**
* https://issues.apache.org/jira/browse/JCR-2543
*/
public void testSQL2Limit() throws Exception {
Query q = qm.createQuery("SELECT * FROM [nt:unstructured]", Query.JCR_SQL2);
q.setLimit(1);
QueryResult r = q.execute();
NodeIterator it = r.getNodes();
assertTrue(it.hasNext());
it.next();
assertFalse(it.hasNext());
}
use of javax.jcr.NodeIterator in project jackrabbit by apache.
the class ClearWorkspace method execute.
/**
* {@inheritDoc}
*/
public boolean execute(Context ctx) throws Exception {
Session s = CommandHelper.getSession(ctx);
if (log.isDebugEnabled()) {
log.debug("removing all content from workspace " + s.getWorkspace().getName());
}
// Set current node to root
CommandHelper.setCurrentNode(ctx, s.getRootNode());
NodeIterator iter = s.getRootNode().getNodes();
while (iter.hasNext()) {
Node n = (Node) iter.next();
if (!n.getName().equals(JcrConstants.JCR_SYSTEM)) {
n.remove();
}
}
PropertyIterator pIter = s.getRootNode().getProperties();
while (pIter.hasNext()) {
Property p = pIter.nextProperty();
if (!p.getName().equals(JcrConstants.JCR_PRIMARYTYPE)) {
p.remove();
}
}
return false;
}
Aggregations