Search in sources :

Example 31 with PropertyState

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

the class NodeIndexer method createDoc.

/**
     * Creates a lucene Document.
     *
     * @return the lucene Document with the index layout.
     * @throws RepositoryException if an error occurs while reading property
     *                             values from the <code>ItemStateProvider</code>.
     */
public Document createDoc() throws RepositoryException {
    doNotUseInExcerpt.clear();
    Document doc = new Document();
    doc.setBoost(getNodeBoost());
    // special fields
    // UUID
    doc.add(new IDField(node.getNodeId()));
    try {
        // parent UUID
        if (node.getParentId() == null) {
            // root node
            Field parent = new Field(FieldNames.PARENT, false, "", Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO);
            parent.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY);
            doc.add(parent);
            addNodeName(doc, "", "");
        } else if (node.getSharedSet().isEmpty()) {
            addParentChildRelation(doc, node.getParentId());
        } else {
            // shareable node
            for (NodeId id : node.getSharedSet()) {
                addParentChildRelation(doc, id);
            }
            // mark shareable nodes
            doc.add(new Field(FieldNames.SHAREABLE_NODE, false, "", Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
        }
    } catch (NoSuchItemStateException e) {
        throwRepositoryException(e);
    } catch (ItemStateException e) {
        throwRepositoryException(e);
    } catch (NamespaceException e) {
    // will never happen, because this.mappings will dynamically add
    // unknown uri<->prefix mappings
    }
    Set<Name> props = node.getPropertyNames();
    for (Name propName : props) {
        if (isIndexed(propName)) {
            PropertyId id = new PropertyId(node.getNodeId(), propName);
            try {
                PropertyState propState = (PropertyState) stateProvider.getItemState(id);
                // beginning with V2
                if (indexFormatVersion.getVersion() >= IndexFormatVersion.V2.getVersion()) {
                    addPropertyName(doc, propState.getName());
                }
                InternalValue[] values = propState.getValues();
                for (InternalValue value : values) {
                    addValue(doc, value, propState.getName());
                }
                if (values.length > 1) {
                    // real multi-valued
                    addMVPName(doc, propState.getName());
                }
            } catch (NoSuchItemStateException e) {
                throwRepositoryException(e);
            } catch (ItemStateException e) {
                throwRepositoryException(e);
            }
        }
    }
    // now add fields that are not used in excerpt (must go at the end)
    for (Fieldable field : doNotUseInExcerpt) {
        doc.add(field);
    }
    return doc;
}
Also used : Document(org.apache.lucene.document.Document) InternalValue(org.apache.jackrabbit.core.value.InternalValue) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Field(org.apache.lucene.document.Field) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) Fieldable(org.apache.lucene.document.Fieldable) NodeId(org.apache.jackrabbit.core.id.NodeId) NamespaceException(javax.jcr.NamespaceException)

Example 32 with PropertyState

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

the class GarbageCollector method scanPersistenceManagersByNodeInfos.

private void scanPersistenceManagersByNodeInfos() throws RepositoryException, ItemStateException {
    int pmCount = 0;
    for (IterablePersistenceManager pm : pmList) {
        pmCount++;
        int count = 0;
        Map<NodeId, NodeInfo> batch = pm.getAllNodeInfos(null, NODESATONCE);
        while (!batch.isEmpty()) {
            NodeId lastId = null;
            for (NodeInfo info : batch.values()) {
                count++;
                if (count % 1000 == 0) {
                    LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes...");
                }
                lastId = info.getId();
                if (callback != null) {
                    callback.beforeScanning(null);
                }
                if (info.hasBlobsInDataStore()) {
                    try {
                        NodeState state = pm.load(info.getId());
                        Set<Name> propertyNames = state.getPropertyNames();
                        for (Name name : propertyNames) {
                            PropertyId pid = new PropertyId(info.getId(), name);
                            PropertyState ps = pm.load(pid);
                            if (ps.getType() == PropertyType.BINARY) {
                                for (InternalValue v : ps.getValues()) {
                                    // getLength will update the last modified date
                                    // if the persistence manager scan is running
                                    v.getLength();
                                }
                            }
                        }
                    } catch (NoSuchItemStateException ignored) {
                    // the node may have been deleted in the meantime
                    }
                }
            }
            batch = pm.getAllNodeInfos(lastId, NODESATONCE);
        }
    }
    NodeInfo.clearPool();
}
Also used : IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeInfo(org.apache.jackrabbit.core.persistence.util.NodeInfo) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 33 with PropertyState

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

the class GarbageCollector method scanNodeIdList.

private void scanNodeIdList(int split, List<NodeId> nodeList, PersistenceManager pm, int pmCount) throws RepositoryException, ItemStateException {
    int count = 0;
    for (NodeId id : nodeList) {
        count++;
        if (count % 1000 == 0) {
            if (split > 0) {
                LOG.debug("[Split " + split + "] " + pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
            } else {
                LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
            }
        }
        if (callback != null) {
            callback.beforeScanning(null);
        }
        try {
            NodeState state = pm.load(id);
            Set<Name> propertyNames = state.getPropertyNames();
            for (Name name : propertyNames) {
                PropertyId pid = new PropertyId(id, name);
                PropertyState ps = pm.load(pid);
                if (ps.getType() == PropertyType.BINARY) {
                    for (InternalValue v : ps.getValues()) {
                        // getLength will update the last modified date
                        // if the persistence manager scan is running
                        v.getLength();
                    }
                }
            }
        } catch (NoSuchItemStateException e) {
        // the node may have been deleted or moved in the meantime
        // ignore it
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 34 with PropertyState

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

the class InMemPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    byte[] data = stateStore.get(id);
    if (data == null) {
        throw new NoSuchItemStateException(id.toString());
    }
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    try {
        PropertyState state = createNew(id);
        Serializer.deserialize(state, in, blobStore);
        return state;
    } catch (Exception e) {
        String msg = "failed to read property state: " + id;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ByteArrayInputStream(java.io.ByteArrayInputStream) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 35 with PropertyState

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

the class WorkspaceImporter method processProperty.

protected void processProperty(NodeState node, PropInfo pInfo) throws RepositoryException {
    PropertyState prop;
    QPropertyDefinition def;
    Name name = pInfo.getName();
    int type = pInfo.getType();
    if (node.hasPropertyName(name)) {
        // a property with that name already exists...
        PropertyId idExisting = new PropertyId(node.getNodeId(), name);
        prop = (PropertyState) itemOps.getItemState(idExisting);
        def = itemOps.findApplicablePropertyDefinition(prop.getName(), prop.getType(), prop.isMultiValued(), node);
        if (def.isProtected()) {
            // skip protected property
            log.debug("skipping protected property " + itemOps.safeGetJCRPath(idExisting));
            return;
        }
        if (!def.isAutoCreated() || (prop.getType() != type && type != PropertyType.UNDEFINED) || def.isMultiple() != prop.isMultiValued()) {
            throw new ItemExistsException(itemOps.safeGetJCRPath(prop.getPropertyId()));
        }
    } else {
        // there's no property with that name,
        // find applicable definition
        def = pInfo.getApplicablePropertyDef(itemOps.getEffectiveNodeType(node));
        if (def.isProtected()) {
            // skip protected property
            log.debug("skipping protected property " + name);
            return;
        }
        // create new property
        prop = itemOps.createPropertyState(node, name, type, def);
    }
    // check multi-valued characteristic
    TextValue[] values = pInfo.getTextValues();
    if (values.length != 1 && !def.isMultiple()) {
        throw new ConstraintViolationException(itemOps.safeGetJCRPath(prop.getPropertyId()) + " is not multi-valued");
    }
    // convert serialized values to InternalValue objects
    int targetType = pInfo.getTargetType(def);
    InternalValue[] iva = new InternalValue[values.length];
    for (int i = 0; i < values.length; i++) {
        iva[i] = values[i].getInternalValue(targetType);
    }
    // set values
    prop.setValues(iva);
    // make sure property is valid according to its definition
    itemOps.validate(prop);
    if (prop.getType() == PropertyType.REFERENCE || prop.getType() == PropertyType.WEAKREFERENCE) {
        // store reference for later resolution
        refTracker.processedReference(prop);
    }
    // store property
    itemOps.store(prop);
}
Also used : ItemExistsException(javax.jcr.ItemExistsException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Aggregations

PropertyState (org.apache.jackrabbit.core.state.PropertyState)53 PropertyId (org.apache.jackrabbit.core.id.PropertyId)25 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)25 NodeState (org.apache.jackrabbit.core.state.NodeState)25 RepositoryException (javax.jcr.RepositoryException)22 Name (org.apache.jackrabbit.spi.Name)22 InternalValue (org.apache.jackrabbit.core.value.InternalValue)19 NodeId (org.apache.jackrabbit.core.id.NodeId)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)14 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)13 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 ItemExistsException (javax.jcr.ItemExistsException)4 Value (javax.jcr.Value)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)4