Search in sources :

Example 86 with InvalidItemStateException

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

the class HierarchyEntryImpl method transientRemove.

/**
     * {@inheritDoc}
     * @see HierarchyEntry#transientRemove()
     */
public void transientRemove() throws InvalidItemStateException, RepositoryException {
    ItemState state = internalGetItemState();
    if (state == null) {
        // nothing to do -> correct status must be set upon resolution.
        return;
    }
    // it in order to determine the current status.
    if (state.getStatus() == Status.INVALIDATED) {
        reload(false);
    }
    switch(state.getStatus()) {
        case Status.NEW:
            state.setStatus(Status.REMOVED);
            parent.internalRemoveChildEntry(this);
            break;
        case Status.EXISTING:
        case Status.EXISTING_MODIFIED:
            state.setStatus(Status.EXISTING_REMOVED);
            // if a conflict with a new entry occurs.
            break;
        case Status.REMOVED:
        case Status.STALE_DESTROYED:
            throw new InvalidItemStateException("Item has already been removed by someone else. Status = " + Status.getName(state.getStatus()));
        default:
            throw new RepositoryException("Cannot transiently remove an ItemState with status " + Status.getName(state.getStatus()));
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemState(org.apache.jackrabbit.jcr2spi.state.ItemState) RepositoryException(javax.jcr.RepositoryException)

Example 87 with InvalidItemStateException

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

the class ConcurrentWriteACLTest method runTest.

@Override
public void runTest() throws Exception {
    Session session = null;
    try {
        session = loginWriter();
        for (int i = 0; i < numItems; i++) {
            session.refresh(false);
            int a = random.nextInt(NODE_COUNT);
            int b = random.nextInt(NODE_COUNT);
            String path = "/" + ROOT_NODE_NAME + "/node" + a + "/node" + b;
            AccessControlManager acMgr = session.getAccessControlManager();
            JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, path);
            if (acl.isEmpty()) {
                Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
                if (acl.addAccessControlEntry(EveryonePrincipal.getInstance(), privileges)) {
                    acMgr.setPolicy(path, acl);
                }
            } else {
                for (AccessControlEntry ace : acl.getAccessControlEntries()) {
                    acl.removeAccessControlEntry(ace);
                }
                acMgr.setPolicy(path, acl);
            }
            session.save();
        }
    } catch (InvalidItemStateException e) {
        System.out.printf("error: %s%n", e);
    // ignore
    } finally {
        if (session != null) {
            session.logout();
        }
    }
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) InvalidItemStateException(javax.jcr.InvalidItemStateException) AccessControlEntry(javax.jcr.security.AccessControlEntry) Privilege(javax.jcr.security.Privilege) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList) Session(javax.jcr.Session)

Example 88 with InvalidItemStateException

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

the class PrivilegeManagerImpl method registerPrivilege.

@Override
public Privilege registerPrivilege(String privilegeName, boolean isAbstract, String[] declaredAggregateNames) throws RepositoryException {
    if (root.hasPendingChanges()) {
        throw new InvalidItemStateException("Attempt to register a new privilege while there are pending changes.");
    }
    if (privilegeName == null || privilegeName.isEmpty()) {
        throw new RepositoryException("Invalid privilege name " + privilegeName);
    }
    PrivilegeDefinition definition = new ImmutablePrivilegeDefinition(getOakName(privilegeName), isAbstract, getOakNames(declaredAggregateNames));
    PrivilegeDefinitionWriter writer = new PrivilegeDefinitionWriter(getWriteRoot());
    writer.writeDefinition(definition);
    // refresh the current root to make sure the definition is visible
    root.refresh();
    return getPrivilege(definition);
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) PrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeDefinition) ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) ImmutablePrivilegeDefinition(org.apache.jackrabbit.oak.spi.security.privilege.ImmutablePrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException)

Example 89 with InvalidItemStateException

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

the class ConcurrentPropertyUpdateTest method concurrentUpdates.

@Test
public void concurrentUpdates() throws Exception {
    final DocumentNodeStore store = mk.getNodeStore();
    NodeBuilder builder = store.getRoot().builder();
    builder.child("test").setProperty("prop", System.currentTimeMillis());
    store.merge(builder, HOOK, CommitInfo.EMPTY);
    List<Callable<Object>> tasks = Lists.newArrayList();
    for (int i = 0; i < NUM_THREADS; i++) {
        tasks.add(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                for (int i = 0; i < 100; i++) {
                    try {
                        NodeBuilder builder = store.getRoot().builder();
                        builder.getChildNode("test").setProperty("prop", Math.random());
                        store.merge(builder, HOOK, CommitInfo.EMPTY);
                    } catch (CommitFailedException e) {
                        // merge must either succeed or fail
                        // with an InvalidItemStateException
                        RepositoryException ex = e.asRepositoryException();
                        if (!(ex instanceof InvalidItemStateException)) {
                            throw e;
                        }
                    }
                }
                return null;
            }
        });
    }
    List<Future<Object>> results = service.invokeAll(tasks);
    for (Future<Object> r : results) {
        r.get();
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) RepositoryException(javax.jcr.RepositoryException) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Callable(java.util.concurrent.Callable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) RepositoryException(javax.jcr.RepositoryException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Future(java.util.concurrent.Future) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test)

Example 90 with InvalidItemStateException

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

the class ReadWriteVersionManager method checkin.

/**
     * Performs a checkin on a versionable tree and returns the tree that
     * represents the created version.
     *
     * @param versionable the versionable node to check in.
     * @return the created version.
     * @throws InvalidItemStateException if the current root has pending
     *                                   changes.
     * @throws UnsupportedRepositoryOperationException
     *                                   if the versionable tree isn't actually
     *                                   versionable.
     * @throws RepositoryException       if an error occurs while checking the
     *                                   node type of the tree.
     */
@Nonnull
public Tree checkin(@Nonnull Tree versionable) throws RepositoryException, InvalidItemStateException, UnsupportedRepositoryOperationException {
    if (sessionDelegate.hasPendingChanges()) {
        throw new InvalidItemStateException("Unable to perform checkin. " + "Session has pending changes.");
    }
    if (!isVersionable(versionable)) {
        throw new UnsupportedRepositoryOperationException(versionable.getPath() + " is not versionable");
    }
    if (isCheckedOut(versionable)) {
        Tree baseVersion = getExistingBaseVersion(versionable);
        versionable.setProperty(JCR_ISCHECKEDOUT, Boolean.FALSE, Type.BOOLEAN);
        PropertyState created = baseVersion.getProperty(JCR_CREATED);
        if (created != null) {
            long c = ISO8601.parse(created.getValue(Type.DATE)).getTimeInMillis();
            while (System.currentTimeMillis() == c) {
            // busy-wait for System.currentTimeMillis to change
            // so that the new version has a distinct timestamp
            }
        }
        try {
            sessionDelegate.commit();
            refresh();
        } catch (CommitFailedException e) {
            sessionDelegate.refresh(true);
            throw e.asRepositoryException();
        }
    }
    return getExistingBaseVersion(getWorkspaceRoot().getTree(versionable.getPath()));
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) InvalidItemStateException(javax.jcr.InvalidItemStateException) Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) PropertyState(org.apache.jackrabbit.oak.api.PropertyState) Nonnull(javax.annotation.Nonnull)

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