Search in sources :

Example 41 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId 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 42 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class BundleReader method readBundleNew.

private void readBundleNew(NodePropBundle bundle) throws IOException {
    // node type
    bundle.setNodeTypeName(readName());
    // parentUUID
    NodeId parentId = readNodeId();
    if (BundleBinding.NULL_PARENT_ID.equals(parentId)) {
        parentId = null;
    }
    bundle.setParentId(parentId);
    // read modcount
    bundle.setModCount((short) readVarInt());
    int b = in.readUnsignedByte();
    bundle.setReferenceable((b & 1) != 0);
    // mixin types
    int mn = readVarInt((b >> 7) & 1, 1);
    if (mn == 0) {
        bundle.setMixinTypeNames(Collections.<Name>emptySet());
    } else if (mn == 1) {
        bundle.setMixinTypeNames(Collections.singleton(readName()));
    } else {
        Set<Name> mixins = new HashSet<Name>(mn * 2);
        for (int i = 0; i < mn; i++) {
            mixins.add(readName());
        }
        bundle.setMixinTypeNames(mixins);
    }
    // properties
    int pn = readVarInt((b >> 4) & 7, 7);
    for (int i = 0; i < pn; i++) {
        PropertyId id = new PropertyId(bundle.getId(), readName());
        bundle.addProperty(readPropertyEntry(id));
    }
    // child nodes (list of name/uuid pairs)
    int nn = readVarInt((b >> 2) & 3, 3);
    for (int i = 0; i < nn; i++) {
        Name name = readQName();
        NodeId id = readNodeId();
        bundle.addChildNodeEntry(name, id);
    }
    // read shared set
    int sn = readVarInt((b >> 1) & 1, 1);
    if (sn == 0) {
        bundle.setSharedSet(Collections.<NodeId>emptySet());
    } else if (sn == 1) {
        bundle.setSharedSet(Collections.singleton(readNodeId()));
    } else {
        Set<NodeId> shared = new HashSet<NodeId>();
        for (int i = 0; i < sn; i++) {
            shared.add(readNodeId());
        }
        bundle.setSharedSet(shared);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) NodeId(org.apache.jackrabbit.core.id.NodeId) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Example 43 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class XMLPersistenceManager method store.

/**
 * {@inheritDoc}
 */
protected void store(NodeReferences refs) throws ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    String refsFilePath = buildNodeReferencesFilePath(refs.getTargetId());
    FileSystemResource refsFile = new FileSystemResource(itemStateFS, refsFilePath);
    try {
        refsFile.makeParentDirs();
        OutputStream os = refsFile.getOutputStream();
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new OutputStreamWriter(os, DEFAULT_ENCODING));
            writer.write("<?xml version=\"1.0\" encoding=\"" + DEFAULT_ENCODING.name() + "\"?>\n");
            writer.write("<" + NODEREFERENCES_ELEMENT + " " + TARGETID_ATTRIBUTE + "=\"" + refs.getTargetId() + "\">\n");
            // write references (i.e. the id's of the REFERENCE properties)
            for (PropertyId propId : refs.getReferences()) {
                writer.write("\t<" + NODEREFERENCE_ELEMENT + " " + PROPERTYID_ATTRIBUTE + "=\"" + propId + "\"/>\n");
            }
            writer.write("</" + NODEREFERENCES_ELEMENT + ">\n");
        } finally {
            writer.close();
        }
    } catch (Exception e) {
        String msg = "failed to store " + refs;
        log.debug(msg);
        throw new ItemStateException(msg, e);
    }
}
Also used : OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) 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) BufferedWriter(java.io.BufferedWriter) PropertyId(org.apache.jackrabbit.core.id.PropertyId) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 44 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class PersistenceCopier method copy.

/**
 * Copies the given node state and all associated property states
 * to the target persistence manager.
 *
 * @param sourceNode source node state
 * @throws RepositoryException if the copy operation fails
 */
private void copy(NodeState sourceNode) throws RepositoryException {
    try {
        ChangeLog changes = new ChangeLog();
        // Copy the node state
        NodeState targetNode = target.createNew(sourceNode.getNodeId());
        targetNode.setParentId(sourceNode.getParentId());
        targetNode.setNodeTypeName(sourceNode.getNodeTypeName());
        targetNode.setMixinTypeNames(sourceNode.getMixinTypeNames());
        targetNode.setPropertyNames(sourceNode.getPropertyNames());
        targetNode.setChildNodeEntries(sourceNode.getChildNodeEntries());
        if (target.exists(targetNode.getNodeId())) {
            changes.modified(targetNode);
        } else {
            changes.added(targetNode);
        }
        // Copy all associated property states
        for (Name name : sourceNode.getPropertyNames()) {
            PropertyId id = new PropertyId(sourceNode.getNodeId(), name);
            PropertyState sourceState = source.load(id);
            PropertyState targetState = target.createNew(id);
            targetState.setType(sourceState.getType());
            targetState.setMultiValued(sourceState.isMultiValued());
            InternalValue[] values = sourceState.getValues();
            // special case copy of binary values
            if (sourceState.getType() == PropertyType.BINARY) {
                InternalValue[] convertedValues = new InternalValue[values.length];
                for (int i = 0; i < values.length; i++) {
                    try (InputStream stream = values[i].getStream()) {
                        convertedValues[i] = InternalValue.create(stream, store);
                    }
                }
                targetState.setValues(convertedValues);
            } else {
                targetState.setValues(values);
            }
            if (target.exists(targetState.getPropertyId())) {
                changes.modified(targetState);
            } else {
                changes.added(targetState);
            }
        }
        // Copy all node references
        if (source.existsReferencesTo(sourceNode.getNodeId())) {
            changes.modified(source.loadReferencesTo(sourceNode.getNodeId()));
        } else if (target.existsReferencesTo(sourceNode.getNodeId())) {
            NodeReferences references = target.loadReferencesTo(sourceNode.getNodeId());
            references.clearAllReferences();
            changes.modified(references);
        }
        // Persist the copied states
        target.store(changes);
    } catch (IOException e) {
        throw new RepositoryException("Unable to copy binary values of " + sourceNode, e);
    } catch (ItemStateException e) {
        throw new RepositoryException("Unable to copy " + sourceNode, e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) InputStream(java.io.InputStream) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) 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) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog)

Example 45 with PropertyId

use of org.apache.jackrabbit.core.id.PropertyId in project jackrabbit by apache.

the class AbstractBundlePersistenceManager method storeInternal.

/**
 * Stores the given changelog and updates the bundle cache.
 *
 * @param changeLog the changelog to store
 * @throws ItemStateException on failure
 */
private void storeInternal(ChangeLog changeLog) throws ItemStateException {
    // delete bundles
    HashSet<ItemId> deleted = new HashSet<ItemId>();
    for (ItemState state : changeLog.deletedStates()) {
        if (state.isNode()) {
            NodePropBundle bundle = getBundle((NodeId) state.getId());
            if (bundle == null) {
                throw new NoSuchItemStateException(state.getId().toString());
            }
            deleteBundle(bundle);
            deleted.add(state.getId());
        }
    }
    // gather added node states
    HashMap<ItemId, NodePropBundle> modified = new HashMap<ItemId, NodePropBundle>();
    for (ItemState state : changeLog.addedStates()) {
        if (state.isNode()) {
            NodePropBundle bundle = new NodePropBundle((NodeState) state);
            modified.put(state.getId(), bundle);
        }
    }
    // gather modified node states
    for (ItemState state : changeLog.modifiedStates()) {
        if (state.isNode()) {
            NodeId nodeId = (NodeId) state.getId();
            NodePropBundle bundle = modified.get(nodeId);
            if (bundle == null) {
                bundle = getBundle(nodeId);
                if (bundle == null) {
                    throw new NoSuchItemStateException(nodeId.toString());
                }
                modified.put(nodeId, bundle);
            }
            bundle.update((NodeState) state);
        } else {
            PropertyId id = (PropertyId) state.getId();
            // skip redundant primaryType and uuid properties
            if (id.getName().equals(JCR_PRIMARYTYPE) || id.getName().equals(JCR_UUID)) {
                continue;
            }
            NodeId nodeId = id.getParentId();
            NodePropBundle bundle = modified.get(nodeId);
            if (bundle == null) {
                bundle = getBundle(nodeId);
                if (bundle == null) {
                    throw new NoSuchItemStateException(nodeId.toString());
                }
                modified.put(nodeId, bundle);
            }
            bundle.addProperty((PropertyState) state, getBlobStore());
        }
    }
    // add removed properties
    for (ItemState state : changeLog.deletedStates()) {
        if (state.isNode()) {
            // check consistency
            NodeId parentId = state.getParentId();
            if (!modified.containsKey(parentId) && !deleted.contains(parentId)) {
                log.warn("Deleted node state's parent is not modified or deleted: " + parentId + "/" + state.getId());
            }
        } else {
            PropertyId id = (PropertyId) state.getId();
            NodeId nodeId = id.getParentId();
            if (!deleted.contains(nodeId)) {
                NodePropBundle bundle = modified.get(nodeId);
                if (bundle == null) {
                    // should actually not happen
                    log.warn("deleted property state's parent not modified!");
                    bundle = getBundle(nodeId);
                    if (bundle == null) {
                        throw new NoSuchItemStateException(nodeId.toString());
                    }
                    modified.put(nodeId, bundle);
                }
                bundle.removeProperty(id.getName(), getBlobStore());
            }
        }
    }
    // add added properties
    for (ItemState state : changeLog.addedStates()) {
        if (!state.isNode()) {
            PropertyId id = (PropertyId) state.getId();
            // skip primaryType and uuid properties
            if (id.getName().equals(JCR_PRIMARYTYPE) || id.getName().equals(JCR_UUID)) {
                continue;
            }
            NodeId nodeId = id.getParentId();
            NodePropBundle bundle = modified.get(nodeId);
            if (bundle == null) {
                // should actually not happen
                log.warn("added property state's parent not modified!");
                bundle = getBundle(nodeId);
                if (bundle == null) {
                    throw new NoSuchItemStateException(nodeId.toString());
                }
                modified.put(nodeId, bundle);
            }
            bundle.addProperty((PropertyState) state, getBlobStore());
        }
    }
    // now store all modified bundles
    long updateSize = 0;
    for (NodePropBundle bundle : modified.values()) {
        putBundle(bundle);
        updateSize += bundle.getSize();
    }
    changeLog.setUpdateSize(updateSize);
    // store the refs
    for (NodeReferences refs : changeLog.modifiedRefs()) {
        if (refs.hasReferences()) {
            store(refs);
        } else {
            destroy(refs);
        }
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ItemState(org.apache.jackrabbit.core.state.ItemState) NodePropBundle(org.apache.jackrabbit.core.persistence.util.NodePropBundle) NodeId(org.apache.jackrabbit.core.id.NodeId) NodeReferences(org.apache.jackrabbit.core.state.NodeReferences) ItemId(org.apache.jackrabbit.core.id.ItemId) HashSet(java.util.HashSet) PropertyId(org.apache.jackrabbit.core.id.PropertyId)

Aggregations

PropertyId (org.apache.jackrabbit.core.id.PropertyId)59 Name (org.apache.jackrabbit.spi.Name)29 PropertyState (org.apache.jackrabbit.core.state.PropertyState)25 NodeState (org.apache.jackrabbit.core.state.NodeState)23 RepositoryException (javax.jcr.RepositoryException)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)22 NodeId (org.apache.jackrabbit.core.id.NodeId)16 InternalValue (org.apache.jackrabbit.core.value.InternalValue)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 HashSet (java.util.HashSet)10 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)7 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeReferences (org.apache.jackrabbit.core.state.NodeReferences)5 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)5 ItemId (org.apache.jackrabbit.core.id.ItemId)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyEntry (org.apache.jackrabbit.core.persistence.util.NodePropBundle.PropertyEntry)4