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();
}
}
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) {
}
}
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();
}
}
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();
}
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.");
}
}
}
Aggregations