use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class WorkspaceRestoreTest method testWorkspaceRestoreWithPendingChanges.
/**
* Test if InvalidItemStateException is thrown if the session affected by
* Workspace.restore(Version[], boolean) has pending changes.
*/
@SuppressWarnings("deprecation")
public void testWorkspaceRestoreWithPendingChanges() throws RepositoryException {
versionableNode.checkout();
try {
// modify node without calling save()
versionableNode.setProperty(propertyName1, propertyValue);
// create version in second workspace
Version v = wVersionableNode.checkin();
// try to restore that version
superuser.getWorkspace().restore(new Version[] { v }, false);
fail("InvalidItemStateException must be thrown on attempt to call Workspace.restore(Version[], boolean) in a session having any unsaved changes pending.");
} catch (InvalidItemStateException e) {
// success
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class CheckinTest method testCheckinWithPendingChangesJcr2.
/**
* Test if VersionManager.checkin(P) throws InvalidItemStateException if
* the path P resolves to a node that has unsaved changes pending.
*
* @throws RepositoryException
*/
public void testCheckinWithPendingChangesJcr2() throws RepositoryException {
try {
// modify node without calling save()
versionableNode.setProperty(propertyName1, propertyValue);
VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
String path = versionableNode.getPath();
versionManager.checkin(path);
fail("InvalidItemStateException must be thrown on attempt to checkin a node having any unsaved changes pending.");
} catch (InvalidItemStateException e) {
// ok
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class PropertyImpl method makePersistent.
@Override
protected void makePersistent() throws InvalidItemStateException {
if (!isTransient()) {
log.debug(this + " (" + id + "): there's no transient state to persist");
return;
}
PropertyState transientState = data.getPropertyState();
PropertyState persistentState = (PropertyState) transientState.getOverlayedState();
if (persistentState == null) {
// this property is 'new'
try {
persistentState = stateMgr.createNew(transientState);
} catch (ItemStateException e) {
throw new InvalidItemStateException(e);
}
}
synchronized (persistentState) {
// check staleness of transient state first
if (transientState.isStale()) {
String msg = this + ": the property cannot be saved because it has" + " been modified externally.";
log.debug(msg);
throw new InvalidItemStateException(msg);
}
// copy state from transient state
persistentState.setType(transientState.getType());
persistentState.setMultiValued(transientState.isMultiValued());
persistentState.setValues(transientState.getValues());
// make state persistent
stateMgr.store(persistentState);
}
// tell state manager to disconnect item state
stateMgr.disconnectTransientItemState(transientState);
// swap transient state with persistent state
data.setState(persistentState);
// reset status
data.setStatus(STATUS_NORMAL);
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class ExternalModificationTest method testMovedReferenceableNode.
public void testMovedReferenceableNode() throws RepositoryException, NotExecutableException {
Node refNode2 = (Node) testSession.getItem(refNode.getPath());
superuser.move(refNode.getPath(), destParentNode.getPath() + "/" + nodeName2);
superuser.save();
try {
// modify some prop of the moved node with session 2
refNode2.setProperty(propertyName1, "test");
testSession.save();
// node has been automatically moved to new place
// -> check if the parent is correct.
assertTrue(testSession.getItem(destParentNode.getPath()).isSame(refNode.getParent()));
} catch (InvalidItemStateException e) {
// no automatic move of the externally moved node. ok.
log.debug(e.getMessage());
}
}
use of javax.jcr.InvalidItemStateException in project jackrabbit by apache.
the class ExternalModificationTest method testExternalRemoval.
public void testExternalRemoval() throws RepositoryException, NotExecutableException {
String uuid = refNode.getUUID();
Node refNode2 = testSession.getNodeByUUID(uuid);
String srcPath = refNode.getPath();
String destPath = destParentNode.getPath() + "/" + nodeName2;
superuser.move(srcPath, destPath);
superuser.save();
try {
refNode2.refresh(true);
Node parent = refNode2.getParent();
} catch (InvalidItemStateException e) {
}
assertItemStatus(refNode2, Status.REMOVED);
// the uuid must be transferred to the 'moved' node
Node n = testSession.getNodeByUUID(uuid);
assertTrue(n.isSame(testSession.getItem(destPath)));
}
Aggregations