Search in sources :

Example 36 with InvalidItemStateException

use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.

the class UUIDLookupTest method beforeSuite.

@Override
public void beforeSuite() throws RepositoryException {
    session = getRepository().login(getCredentials());
    try {
        ensurePropertyIndexes();
    } catch (InvalidItemStateException e) {
        // some other oak instance probably created the same
        // index definition concurrently. refresh and try again
        // do not catch exception if it fails again.
        session.refresh(false);
        ensurePropertyIndexes();
    }
    root = session.getRootNode().addNode("testroot" + TEST_ID, "nt:unstructured");
    for (int i = 0; i < NODE_COUNT; i++) {
        Node node = root.addNode("node" + i, "nt:unstructured");
        node.setProperty("jcr:uuid", createUUID(i));
        session.save();
    }
    String lookupMode = lookupByQuery ? "query" : "Session#getNodeByIdentifier";
    System.out.printf("No of indexes (%s) %d, Lookup by (%s)[%s] %n", noOfIndex, noOfIndex, "lookupByQuery", lookupMode);
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 37 with InvalidItemStateException

use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.

the class RemoveNodeTest method testInvalidStateRemovedNode3.

public void testInvalidStateRemovedNode3() throws RepositoryException {
    Node childNode = testRootNode.addNode(nodeName1, testNodeType);
    superuser.save();
    // get the node with session 2
    Session otherSession = getHelper().getReadWriteSession();
    try {
        Node childNode2 = (Node) otherSession.getItem(childNode.getPath());
        childNode.remove();
        superuser.save();
        // try to remove already removed node with session 2
        try {
            childNode2.refresh(false);
            childNode2.remove();
            otherSession.save();
            fail("Removing a node already removed by other session should throw an InvalidItemStateException!");
        } catch (InvalidItemStateException e) {
        //ok, works as expected
        }
    } finally {
        otherSession.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session)

Example 38 with InvalidItemStateException

use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.

the class MoveMultipleTest method testRevertingMoveParentAndNewChild.

/**
     * Separately move the persisted 'moveNode' and its 'new' child node.
     * Check if reverting the changes removes the 'new' child and moves
     * the persisted moveNode back.
     */
public void testRevertingMoveParentAndNewChild() throws RepositoryException {
    Node moveNode2 = moveNode.addNode(nodeName3, testNodeType);
    doMove(moveNode.getPath(), destinationPath);
    doMove(moveNode2.getPath(), srcParentNode.getPath() + "/" + moveNode2.getName());
    doMove(moveNode.getPath(), originalPath);
    testRootNode.refresh(false);
    // moveNode2 which has never been saved, must be removed
    try {
        moveNode2.getParent();
        fail("Reverting the move of a 'new' node must remove the new node as well.");
    } catch (InvalidItemStateException e) {
    // ok
    }
    // the persistent 'moveNode' must be moved back to its original position.
    assertTrue(moveNode.getParent().isSame(srcParentNode));
    assertFalse(destParentNode.hasNodes());
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 39 with InvalidItemStateException

use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.

the class ConflictResolutionTest method deleteChangedNodeOps.

private void deleteChangedNodeOps(String node) throws RepositoryException {
    getAdminSession().getRootNode().addNode(node).addNode("jcr:content").addNode("metadata");
    getAdminSession().save();
    Session session1 = createAdminSession();
    Session session2 = createAdminSession();
    try {
        session1.getNode("/" + node + "/jcr:content").remove();
        session2.getNode("/" + node + "/jcr:content/metadata").setProperty("updated", "myself");
        session2.save();
        try {
            session1.save();
            fail("Expected InvalidItemStateException");
        } catch (InvalidItemStateException expected) {
            assertThat("Expecting 'Unresolved conflicts in /" + node + "'", expected.getMessage(), containsString("OakState0001: Unresolved conflicts in /" + node + ""));
        }
    } finally {
        session1.logout();
        session2.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Session(javax.jcr.Session)

Example 40 with InvalidItemStateException

use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.

the class MoveRemoveTest method removeExistingNodeRefresh.

@Test
public void removeExistingNodeRefresh() throws RepositoryException {
    Session session = getAdminSession();
    session.getRootNode().addNode("new");
    session.save();
    Session session2 = createAdminSession();
    Node n2 = session2.getNode("/new");
    Node n = session.getNode("/new");
    n.remove();
    session.save();
    session2.refresh(false);
    try {
        n2.getPath();
        fail();
    } catch (InvalidItemStateException e) {
    }
    session.getRootNode().addNode("new");
    session.save();
    session2.refresh(false);
    assertEquals("/new", n2.getPath());
    session2.logout();
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

InvalidItemStateException (javax.jcr.InvalidItemStateException)100 Node (javax.jcr.Node)67 Session (javax.jcr.Session)35 Test (org.junit.Test)21 Property (javax.jcr.Property)15 RepositoryException (javax.jcr.RepositoryException)14 NodeIterator (javax.jcr.NodeIterator)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 QueryResult (javax.jcr.query.QueryResult)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 ItemNotFoundException (javax.jcr.ItemNotFoundException)4 NodeType (javax.jcr.nodetype.NodeType)3 SessionImpl (org.apache.jackrabbit.core.SessionImpl)3 NodeId (org.apache.jackrabbit.core.id.NodeId)3 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)3 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 PathNotFoundException (javax.jcr.PathNotFoundException)2 UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)2 Version (javax.jcr.version.Version)2