Search in sources :

Example 1 with NodeReferences

use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.

the class XMLPersistenceManager method loadReferencesTo.

/**
     * {@inheritDoc}
     */
public synchronized NodeReferences loadReferencesTo(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    Exception e = null;
    String refsFilePath = buildNodeReferencesFilePath(id);
    try {
        if (!itemStateFS.isFile(refsFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
        InputStream in = itemStateFS.getInputStream(refsFilePath);
        try {
            DOMWalker walker = new DOMWalker(in);
            NodeReferences refs = new NodeReferences(id);
            readState(walker, refs);
            return refs;
        } finally {
            in.close();
        }
    } catch (IOException ioe) {
        e = ioe;
    // fall through
    } catch (FileSystemException fse) {
        e = fse;
    // fall through
    }
    String msg = "failed to load references: " + id;
    log.debug(msg);
    throw new ItemStateException(msg, e);
}
Also used : DOMWalker(org.apache.jackrabbit.core.util.DOMWalker) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InputStream(java.io.InputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) IOException(java.io.IOException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 2 with NodeReferences

use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.

the class InternalVersionManagerImpl method canCheckout.

/**
     * {@inheritDoc}
     *
     * this method currently does no modifications to the persistence and just
     * checks if the checkout is valid in respect to a possible activity set on
     * the session
     */
public NodeId canCheckout(NodeStateEx state, NodeId activityId) throws RepositoryException {
    NodeId baseId = state.getPropertyValue(NameConstants.JCR_BASEVERSION).getNodeId();
    if (activityId != null) {
        // exist in 'this' workspace
        if (stateMgr.hasNodeReferences(activityId)) {
            try {
                NodeReferences refs = stateMgr.getNodeReferences(activityId);
                for (PropertyId id : refs.getReferences()) {
                    if (!state.hasNode(id.getParentId())) {
                        throw new ActivityViolationException("Unable to checkout. " + "Activity is already used for the same node in " + "another workspace.");
                    }
                }
            } catch (ItemStateException e) {
                throw new RepositoryException("Error during checkout.", e);
            }
        }
        // If there is a version in H that is not an eventual predecessor of N but
        // whose jcr:activity references A, then the checkout fails with an
        // ActivityViolationException
        InternalActivityImpl a = (InternalActivityImpl) getItem(activityId);
        NodeId historyId = state.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
        InternalVersionHistory history = (InternalVersionHistory) getItem(historyId);
        InternalVersion version = a.getLatestVersion(history);
        if (version != null) {
            InternalVersion baseVersion = (InternalVersion) getItem(baseId);
            while (baseVersion != null && !baseVersion.getId().equals(version.getId())) {
                baseVersion = baseVersion.getLinearPredecessor();
            }
            if (baseVersion == null) {
                throw new ActivityViolationException("Unable to checkout. " + "Activity is used by another version on a different branch: " + version.getName());
            }
        }
    }
    return baseId;
}
Also used : NodeId(org.apache.jackrabbit.core.id.NodeId) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ActivityViolationException(javax.jcr.version.ActivityViolationException) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 3 with NodeReferences

use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.

the class VersionItemStateManager method setNodeReferences.

/**
     * Sets the
     * @param references
     * @return
     */
public boolean setNodeReferences(ChangeLog references) {
    try {
        ChangeLog log = new ChangeLog();
        for (NodeReferences source : references.modifiedRefs()) {
            // filter out version storage intern ones
            NodeReferences target = new NodeReferences(source.getTargetId());
            for (PropertyId id : source.getReferences()) {
                if (!hasNonVirtualItemState(id.getParentId())) {
                    target.addReference(id);
                }
            }
            log.modified(target);
        }
        if (log.hasUpdates()) {
            pMgr.store(log);
        }
        return true;
    } catch (ItemStateException e) {
        log.error("Error while setting references: " + e.toString());
        return false;
    }
}
Also used : NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 4 with NodeReferences

use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.

the class NodeImpl method getReferences.

/**
     * {@inheritDoc}
     */
public PropertyIterator getReferences(String name) throws RepositoryException {
    // check state of this instance
    sanityCheck();
    try {
        if (stateMgr.hasNodeReferences(getNodeId())) {
            NodeReferences refs = stateMgr.getNodeReferences(getNodeId());
            // refs.getReferences() returns a list of PropertyId's
            List<PropertyId> idList = refs.getReferences();
            if (name != null) {
                Name qName;
                try {
                    qName = sessionContext.getQName(name);
                } catch (NameException e) {
                    throw new RepositoryException("invalid property name: " + name, e);
                }
                ArrayList<PropertyId> filteredList = new ArrayList<PropertyId>(idList.size());
                for (PropertyId propId : idList) {
                    if (propId.getName().equals(qName)) {
                        filteredList.add(propId);
                    }
                }
                idList = filteredList;
            }
            return new LazyItemIterator(sessionContext, idList);
        } else {
            // there are no references, return empty iterator
            return PropertyIteratorAdapter.EMPTY;
        }
    } catch (ItemStateException e) {
        String msg = "Unable to retrieve REFERENCE properties that refer to " + id;
        log.debug(msg);
        throw new RepositoryException(msg, e);
    }
}
Also used : NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) ArrayList(java.util.ArrayList) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) RepositoryException(javax.jcr.RepositoryException) PropertyId(org.apache.jackrabbit.core.id.PropertyId) Name(org.apache.jackrabbit.spi.Name) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 5 with NodeReferences

use of org.apache.jackrabbit.core.state.NodeReferences in project jackrabbit by apache.

the class InternalVersionManagerBase method internalRemoveActivity.

/**
     * Removes the specified activity
     *
     * @param activity the activity to remove
     * @throws javax.jcr.RepositoryException if any other error occurs.
     */
protected void internalRemoveActivity(InternalActivityImpl activity) throws RepositoryException {
    WriteOperation operation = startWriteOperation();
    try {
        // check if the activity has any references in the workspaces
        NodeId nodeId = activity.getId();
        if (stateMgr.hasNodeReferences(nodeId)) {
            NodeReferences refs = stateMgr.getNodeReferences(nodeId);
            if (refs.hasReferences()) {
                throw new ReferentialIntegrityException("Unable to delete activity. still referenced.");
            }
        }
        // TODO:
        // check if the activity is used in anywhere in the version storage
        // and reject removal
        // remove activity and possible empty parent directories
        NodeStateEx act = getNodeStateEx(nodeId);
        NodeId parentId = act.getParentId();
        Name name = act.getName();
        while (parentId != null) {
            NodeStateEx parent = getNodeStateEx(parentId);
            parent.removeNode(name);
            parent.store();
            if (parent.getChildNodes().length == 0 && !parentId.equals(activitiesId)) {
                name = parent.getName();
                parentId = parent.getParentId();
            } else {
                parentId = null;
            }
        }
        operation.save();
    } catch (ItemStateException e) {
        log.error("Error while storing: " + e.toString());
    } finally {
        operation.close();
    }
}
Also used : ReferentialIntegrityException(javax.jcr.ReferentialIntegrityException) NodeId(org.apache.jackrabbit.core.id.NodeId) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) Name(org.apache.jackrabbit.spi.Name) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Aggregations

NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)15 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)13 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)10 RepositoryException (javax.jcr.RepositoryException)7 IOException (java.io.IOException)5 InputStream (java.io.InputStream)5 PropertyId (org.apache.jackrabbit.core.id.PropertyId)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 NodeId (org.apache.jackrabbit.core.id.NodeId)4 SQLException (java.sql.SQLException)3 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)3 ChangeLog (org.apache.jackrabbit.core.state.ChangeLog)3 NodeState (org.apache.jackrabbit.core.state.NodeState)3 Name (org.apache.jackrabbit.spi.Name)3 FilterInputStream (java.io.FilterInputStream)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 ResultSet (java.sql.ResultSet)2 InvalidItemStateException (javax.jcr.InvalidItemStateException)2 ReferentialIntegrityException (javax.jcr.ReferentialIntegrityException)2 PropertyState (org.apache.jackrabbit.core.state.PropertyState)2