use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class InternalVersionManagerImpl method createVersionHistory.
/**
* {@inheritDoc}
* <p>
* This method must not be synchronized since it could cause deadlocks with
* item-reading listeners in the observation thread.
*/
@Override
protected VersionHistoryInfo createVersionHistory(Session session, final NodeState node, final NodeId copiedFrom) throws RepositoryException {
NodeStateEx state = (NodeStateEx) escFactory.doSourced((SessionImpl) session, new SourcedTarget() {
public Object run() throws RepositoryException {
return internalCreateVersionHistory(node, copiedFrom);
}
});
if (state == null) {
throw new InvalidItemStateException("History already exists for node " + node.getNodeId());
}
Name root = NameConstants.JCR_ROOTVERSION;
return new VersionHistoryInfo(state.getNodeId(), state.getState().getChildNodeEntry(root, 1).getId());
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class VersionImpl method getInternalVersion.
/**
* Returns the internal version. Subclass responsibility.
* @return internal version
* @throws RepositoryException if the internal version is not available
*/
protected InternalVersion getInternalVersion() throws RepositoryException {
SessionImpl session = sessionContext.getSessionImpl();
InternalVersion version = session.getInternalVersionManager().getVersion((NodeId) id);
if (version == null) {
throw new InvalidItemStateException(id + ": the item does not exist anymore");
}
return version;
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class UpdateTest method testPendingChangesOnOtherNode.
public void testPendingChangesOnOtherNode() throws RepositoryException, NotExecutableException {
try {
Node root = testRootNode.getSession().getRootNode();
if (root.isSame(testRootNode)) {
throw new NotExecutableException();
}
if (root.canAddMixin(mixLockable)) {
root.addMixin(mixLockable);
} else {
root.setProperty(propertyName1, "anyValue");
}
} catch (RepositoryException e) {
throw new NotExecutableException();
}
String srcWorkspace = getAnotherWorkspace();
try {
testRootNode.update(srcWorkspace);
fail("Update while changes are pending must fail with InvalidItemStateException");
} catch (InvalidItemStateException e) {
// ok
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit-oak by apache.
the class DescendantSearchTest method beforeSuite.
@Override
public void beforeSuite() throws RepositoryException {
session = getRepository().login(getCredentials());
try {
// Jackrabbit 2 doesn't have the oak namespace
String o = session.getNamespaceURI("oak");
} catch (RepositoryException e) {
session.setNamespacePrefix("oak", "http://jackrabbit.apache.org/oak/ns/1.0");
}
try {
ensurePropertyIndex();
} 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);
ensurePropertyIndex();
}
root = session.getRootNode().addNode(testNodeName, "nt:unstructured");
for (int i = 0; i < NODE_COUNT; i++) {
Node node = root.addNode("node" + i, "nt:unstructured");
for (int j = 0; j < NODE_COUNT; j++) {
Node child = node.addNode("node" + j, "nt:unstructured");
child.setProperty("testcount", j);
}
session.save();
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class NodeUUIDTest method testSaveMovedRefNode.
/**
* Moves a referencable node using {@link javax.jcr.Session#move(String,
* String)} with one session and saves afterward changes made with a second
* session to the moved node using {@link Node#save()}.
* <p>
* Procedure: <ul> <li>Creates node 1 and node 2 with session 1</li>
* <li>Gets reference to node 1 using session 2</li> <li>Session 1 moves
* node 1 under node 2, saves changes</li> <li>Session 2 modifes node 1,
* saves</li> </ul> This should work (since the modified node is identified
* by its UUID, not by position in repository) or throw an
* <code>InvalidItemStateException</code> if 'move' is reported to the second
* session as a sequence of remove and add events. <br><br>Prerequisites: <ul>
* <li><code>javax.jcr.tck.NodeUUIDTest.nodetype2</code> must have the mixin
* type <code>mix:referenceable</code> assigned.</li>
* <li><code>javax.jcr.tck.NodeUUIDTest.testSaveMovedRefNode.propertyname1</code>
* name of a property that can be modified in <code>nodetype2</code> for
* testing</li> </ul>
*/
public void testSaveMovedRefNode() throws RepositoryException, NotExecutableException {
checkMixReferenceable();
// get default workspace test root node using superuser session
Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
// create a node
Node newParentNode = defaultRootNode.addNode(nodeName1, testNodeType);
// create a referenceable node
Node refTargetNode = defaultRootNode.addNode(nodeName2, getProperty("nodetype2"));
// save the new nodes
superuser.save();
// get the moving node with session 2
Session testSession = getHelper().getReadWriteSession();
try {
Node refTargetNodeSession2 = (Node) testSession.getItem(refTargetNode.getPath());
//move the node with session 1
superuser.move(refTargetNode.getPath(), newParentNode.getPath() + "/" + nodeName3);
// make the move persistent with session 1
superuser.save();
// modify some prop of the moved node with session 2
try {
refTargetNodeSession2.setProperty(propertyName1, "test");
// save it
refTargetNodeSession2.save();
// ok, works as expected
} catch (InvalidItemStateException e) {
// ok as well.
}
} finally {
testSession.logout();
}
}
Aggregations