Search in sources :

Example 51 with InvalidItemStateException

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

the class SessionItemStateManager method createTransientNodeState.

//------< methods for creating & discarding transient ItemState instances >
/**
     * @param id
     * @param nodeTypeName
     * @param parentId
     * @param initialStatus
     * @return
     * @throws RepositoryException
     */
public NodeState createTransientNodeState(NodeId id, Name nodeTypeName, NodeId parentId, int initialStatus) throws RepositoryException {
    if (initialStatus == ItemState.STATUS_NEW && id != null && hasItemState(id)) {
        throw new InvalidItemStateException("Node " + id + " already exists");
    }
    // check map; synchronized to ensure an entry is not created twice.
    synchronized (transientStore) {
        if (id == null) {
            id = stateMgr.getNodeIdFactory().newNodeId();
        } else if (transientStore.containsKey(id)) {
            throw new RepositoryException("There is already a transient state for node " + id);
        }
        NodeState state = new NodeState(id, nodeTypeName, parentId, initialStatus, true);
        // put transient state in the map
        transientStore.put(state.getId(), state);
        state.setContainer(this);
        return state;
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) RepositoryException(javax.jcr.RepositoryException)

Example 52 with InvalidItemStateException

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

the class MoveRemoveTest method testMoveRemove.

public void testMoveRemove() throws RepositoryException, NotExecutableException {
    Session session1 = getHelper().getSuperuserSession();
    Session session2 = getHelper().getSuperuserSession();
    session1.move(folder1Path + "/node", folder2Path + "/node");
    session2.getNode(folder1Path + "/node").remove();
    session1.save();
    try {
        session2.save();
    } catch (InvalidItemStateException e) {
        if (e.getCause() == null || e.getCause().getClass() != StaleItemStateException.class) {
            throw e;
        }
    }
    ConsistencyReport consistencyReport = TestHelper.checkConsistency(testRootNode.getSession(), false, null);
    //for (ReportItem item : consistencyReport.getItems()) {
    //    System.out.println(item.getMessage());
    //}
    assertTrue(consistencyReport.getItems().size() == 0);
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) ConsistencyReport(org.apache.jackrabbit.core.persistence.check.ConsistencyReport) Session(javax.jcr.Session)

Example 53 with InvalidItemStateException

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

the class ConcurrentAddRemoveMoveTest method testMoveFromWithRemove.

public void testMoveFromWithRemove() throws Exception {
    Node d = session.getNode(testRoot).getNode("A").addNode("D");
    session.save();
    superuser.move(testRoot + "/A/B", testRoot + "/C/B");
    d.remove();
    superuser.save();
    try {
        session.save();
    } catch (InvalidItemStateException e) {
        fail("must not throw exception");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 54 with InvalidItemStateException

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

the class ConcurrentAddRemovePropertyTest method testRemove.

public void testRemove() throws Exception {
    Node n = testRootNode.addNode(nodeName1);
    n.setProperty(propertyName1, "foo");
    n.setProperty(propertyName2, "bar");
    superuser.save();
    n.getProperty(propertyName1).remove();
    session.getNode(testRoot).getNode(nodeName1).getProperty(propertyName2).remove();
    superuser.save();
    try {
        session.save();
    } catch (InvalidItemStateException e) {
        fail("must not throw InvalidItemStateException");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 55 with InvalidItemStateException

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

the class ConcurrentAddRemovePropertyTest method testAdd.

public void testAdd() throws Exception {
    Node n = testRootNode.addNode(nodeName1);
    superuser.save();
    n.setProperty(propertyName1, "foo");
    session.getNode(testRoot).getNode(nodeName1).setProperty(propertyName2, "bar");
    superuser.save();
    try {
        session.save();
    } catch (InvalidItemStateException e) {
        fail("must not throw InvalidItemStateException");
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

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