Search in sources :

Example 21 with InvalidItemStateException

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
    }
}
Also used : Version(javax.jcr.version.Version) InvalidItemStateException(javax.jcr.InvalidItemStateException)

Example 22 with InvalidItemStateException

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
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) VersionManager(javax.jcr.version.VersionManager)

Example 23 with InvalidItemStateException

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);
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 24 with InvalidItemStateException

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());
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node)

Example 25 with InvalidItemStateException

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)));
}
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