Search in sources :

Example 46 with InvalidItemStateException

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

the class RepositoryTest method saveRefreshConflict.

@Test
public void saveRefreshConflict() throws RepositoryException {
    Session session1 = createAdminSession();
    Session session2 = createAdminSession();
    try {
        session1.getRootNode().addNode("node").setProperty("p", "v1");
        session2.getRootNode().addNode("node").setProperty("p", "v2");
        assertTrue(session1.getRootNode().hasNode("node"));
        assertTrue(session2.getRootNode().hasNode("node"));
        session1.save();
        assertTrue(session1.getRootNode().hasNode("node"));
        assertTrue(session2.getRootNode().hasNode("node"));
        session2.refresh(true);
        assertTrue(session1.getRootNode().hasNode("node"));
        assertTrue(session2.getRootNode().hasNode("node"));
        try {
            session2.save();
            fail("Expected InvalidItemStateException");
        } catch (InvalidItemStateException expected) {
        }
    } finally {
        session1.logout();
        session2.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 47 with InvalidItemStateException

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

the class RepositoryTest method accessRemovedProperty.

@Test
public void accessRemovedProperty() throws RepositoryException {
    Node foo = getNode("/foo");
    Property p = foo.setProperty("name", "value");
    p.remove();
    try {
        p.getPath();
        fail("Expected InvalidItemStateException");
    } catch (InvalidItemStateException expected) {
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) Property(javax.jcr.Property) Test(org.junit.Test)

Example 48 with InvalidItemStateException

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

the class RepositoryTest method saveConflict.

@Test
public void saveConflict() throws RepositoryException {
    getAdminSession().getRootNode().addNode("node");
    getAdminSession().save();
    Session session1 = createAdminSession();
    Session session2 = createAdminSession();
    try {
        session1.getNode("/node").remove();
        session2.getNode("/node").addNode("2");
        assertFalse(session1.getRootNode().hasNode("node"));
        assertTrue(session2.getRootNode().hasNode("node"));
        assertTrue(session2.getRootNode().getNode("node").hasNode("2"));
        session1.save();
        assertFalse(session1.getRootNode().hasNode("node"));
        assertFalse(session2.getRootNode().hasNode("node"));
        try {
            session2.save();
            fail("Expected InvalidItemStateException");
        } catch (InvalidItemStateException expected) {
        }
    } finally {
        session1.logout();
        session2.logout();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 49 with InvalidItemStateException

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

the class CompatibilityIssuesTest method removeNodeInDifferentSession.

/**
     * OAK-939 - Change in behaviour from JR2. Following test case leads to
     * CommitFailedException but it passes in JR2
     */
@Test
public void removeNodeInDifferentSession() throws Throwable {
    final String testNode = "test_node";
    final String testNodePath = '/' + testNode;
    // Create the test node
    Session session = getAdminSession();
    session.getRootNode().addNode(testNode);
    session.save();
    // Test case would pass if the sessionRefreshInterval is set to zero
    boolean refreshIntervalZero = false;
    Session s3 = newSession(refreshIntervalZero);
    Session s2 = newSession(refreshIntervalZero);
    s2.getNode(testNodePath).setProperty("foo", "bar");
    s2.save();
    s3.getNode(testNodePath).remove();
    try {
        s3.save();
    } catch (InvalidItemStateException e) {
        assertTrue(e.getCause() instanceof CommitFailedException);
    }
    s2.logout();
    s3.logout();
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Session(javax.jcr.Session) Test(org.junit.Test)

Example 50 with InvalidItemStateException

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

the class ItemValidator method checkCondition.

private void checkCondition(ItemImpl item, int options, int permissions, boolean isRemoval) throws RepositoryException {
    if ((options & CHECK_PENDING_CHANGES) == CHECK_PENDING_CHANGES) {
        if (item.getSession().hasPendingChanges()) {
            String msg = "Unable to perform operation. Session has pending changes.";
            log.debug(msg);
            throw new InvalidItemStateException(msg);
        }
    }
    if ((options & CHECK_PENDING_CHANGES_ON_NODE) == CHECK_PENDING_CHANGES_ON_NODE) {
        if (item.isNode() && ((NodeImpl) item).hasPendingChanges()) {
            String msg = "Unable to perform operation. Session has pending changes.";
            log.debug(msg);
            throw new InvalidItemStateException(msg);
        }
    }
    if ((options & CHECK_CONSTRAINTS) == CHECK_CONSTRAINTS) {
        if (isProtected(item)) {
            String msg = "Unable to perform operation. Node is protected.";
            log.debug(msg);
            throw new ConstraintViolationException(msg);
        }
    }
    if ((options & CHECK_CHECKED_OUT) == CHECK_CHECKED_OUT) {
        NodeImpl node = (item.isNode()) ? (NodeImpl) item : (NodeImpl) item.getParent();
        if (!node.isCheckedOut()) {
            String msg = "Unable to perform operation. Node is checked-in.";
            log.debug(msg);
            throw new VersionException(msg);
        }
    }
    if ((options & CHECK_LOCK) == CHECK_LOCK) {
        checkLock(item);
    }
    if (permissions > Permission.NONE) {
        Path path = item.getPrimaryPath();
        context.getAccessManager().checkPermission(path, permissions);
    }
    if ((options & CHECK_HOLD) == CHECK_HOLD) {
        if (hasHold(item, isRemoval)) {
            throw new RepositoryException("Unable to perform operation. Node is affected by a hold.");
        }
    }
    if ((options & CHECK_RETENTION) == CHECK_RETENTION) {
        if (hasRetention(item, isRemoval)) {
            throw new RepositoryException("Unable to perform operation. Node is affected by a retention.");
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) InvalidItemStateException(javax.jcr.InvalidItemStateException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) RepositoryException(javax.jcr.RepositoryException) VersionException(javax.jcr.version.VersionException)

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