Search in sources :

Example 31 with NoSuchItemStateException

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

the class AbstractBundlePersistenceManager method load.

/**
     * {@inheritDoc}
     *
     * Loads the state via the appropriate NodePropBundle.
     */
public PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    NodePropBundle bundle = getBundle(id.getParentId());
    if (bundle != null) {
        PropertyState state = createNew(id);
        PropertyEntry p = bundle.getPropertyEntry(id.getName());
        if (p != null) {
            state.setMultiValued(p.isMultiValued());
            state.setType(p.getType());
            state.setValues(p.getValues());
            state.setModCount(p.getModCount());
        } else if (id.getName().equals(JCR_UUID)) {
            state.setType(PropertyType.STRING);
            state.setMultiValued(false);
            state.setValues(new InternalValue[] { InternalValue.create(id.getParentId().toString()) });
        } else if (id.getName().equals(JCR_PRIMARYTYPE)) {
            state.setType(PropertyType.NAME);
            state.setMultiValued(false);
            state.setValues(new InternalValue[] { InternalValue.create(bundle.getNodeTypeName()) });
        } else if (id.getName().equals(JCR_MIXINTYPES)) {
            state.setType(PropertyType.NAME);
            state.setMultiValued(true);
            Set<Name> mixins = bundle.getMixinTypeNames();
            state.setValues(InternalValue.create(mixins.toArray(new Name[mixins.size()])));
        } else {
            throw new NoSuchItemStateException(id.toString());
        }
        return state;
    } else {
        throw new NoSuchItemStateException(id.toString());
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) PropertyEntry(org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name)

Example 32 with NoSuchItemStateException

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

the class InMemBundlePersistenceManager method loadReferencesTo.

/**
     * {@inheritDoc}
     */
public NodeReferences loadReferencesTo(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    if (!refsStore.containsKey(id)) {
        throw new NoSuchItemStateException(id.toString());
    }
    try {
        NodeReferences refs = new NodeReferences(id);
        Serializer.deserialize(refs, new ByteArrayInputStream(refsStore.get(id)));
        return refs;
    } catch (Exception e) {
        String msg = "failed to read references: " + id;
        log.error(msg, e);
        throw new ItemStateException(msg, e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 33 with NoSuchItemStateException

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

the class DatabasePersistenceManager method load.

/**
     * {@inheritDoc}
     */
public NodeState load(NodeId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    synchronized (nodeStateSelectSQL) {
        ResultSet rs = null;
        InputStream in = null;
        try {
            Statement stmt = executeStmt(nodeStateSelectSQL, new Object[] { id.toString() });
            rs = stmt.getResultSet();
            if (!rs.next()) {
                throw new NoSuchItemStateException(id.toString());
            }
            in = rs.getBinaryStream(1);
            NodeState state = createNew(id);
            Serializer.deserialize(state, in);
            return state;
        } catch (Exception e) {
            if (e instanceof NoSuchItemStateException) {
                throw (NoSuchItemStateException) e;
            }
            String msg = "failed to read node state: " + id;
            log.error(msg, e);
            throw new ItemStateException(msg, e);
        } finally {
            IOUtils.closeQuietly(in);
            closeResultSet(rs);
        }
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeState(org.apache.jackrabbit.core.state.NodeState) FilterInputStream(java.io.FilterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) SQLException(java.sql.SQLException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 34 with NoSuchItemStateException

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

the class BundleFsPersistenceManager method loadReferencesTo.

/**
     * {@inheritDoc}
     */
public synchronized NodeReferences loadReferencesTo(NodeId targetId) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    InputStream in = null;
    try {
        String path = buildNodeReferencesFilePath(null, targetId).toString();
        if (!itemFs.exists(path)) {
            // special case
            throw new NoSuchItemStateException(targetId.toString());
        }
        in = itemFs.getInputStream(path);
        NodeReferences refs = new NodeReferences(targetId);
        Serializer.deserialize(refs, in);
        return refs;
    } catch (NoSuchItemStateException e) {
        throw e;
    } catch (Exception e) {
        String msg = "failed to read references: " + targetId;
        BundleFsPersistenceManager.log.error(msg, e);
        throw new ItemStateException(msg, e);
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InputStream(java.io.InputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) SQLException(java.sql.SQLException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 35 with NoSuchItemStateException

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

the class NodeIndexer method getValue.

/**
     * Utility method that extracts the first value of the named property
     * of the current node. Returns <code>null</code> if the property does
     * not exist or contains no values.
     *
     * @param name property name
     * @return value of the named property, or <code>null</code>
     * @throws ItemStateException if the property can not be accessed
     */
protected InternalValue getValue(Name name) throws ItemStateException {
    try {
        PropertyId id = new PropertyId(node.getNodeId(), name);
        PropertyState property = (PropertyState) stateProvider.getItemState(id);
        InternalValue[] values = property.getValues();
        if (values.length > 0) {
            return values[0];
        } else {
            return null;
        }
    } catch (NoSuchItemStateException e) {
        return null;
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Aggregations

NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)37 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)31 RepositoryException (javax.jcr.RepositoryException)17 NodeId (org.apache.jackrabbit.core.id.NodeId)14 NodeState (org.apache.jackrabbit.core.state.NodeState)13 FileSystemException (org.apache.jackrabbit.core.fs.FileSystemException)11 PropertyState (org.apache.jackrabbit.core.state.PropertyState)11 IOException (java.io.IOException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InputStream (java.io.InputStream)8 InvalidItemStateException (javax.jcr.InvalidItemStateException)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 ItemState (org.apache.jackrabbit.core.state.ItemState)8 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)8 SQLException (java.sql.SQLException)7 PropertyId (org.apache.jackrabbit.core.id.PropertyId)7 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 Name (org.apache.jackrabbit.spi.Name)6 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 FilterInputStream (java.io.FilterInputStream)4