Package org.apache.jackrabbit.core.persistence.util

Examples of org.apache.jackrabbit.core.persistence.util.NodePropBundle


        if (fix) {
            if (lostNFoundId != null) {
                // do we have a "lost+found" node?
                try {
                    NodeId tmpid = new NodeId(lostNFoundId);
                    NodePropBundle lfBundle = pm.loadBundle(tmpid);
                    if (lfBundle == null) {
                        error(lostNFoundId, "Specified 'lost+found' node does not exist");
                    } else if (!NameConstants.NT_UNSTRUCTURED.equals(lfBundle .getNodeTypeName())) {
                        error(lostNFoundId, "Specified 'lost+found' node is not of type nt:unstructured");
                    } else {
                        lostNFound = lfBundle.getId();
                    }
                } catch (Exception ex) {
                    error(lostNFoundId, "finding 'lost+found' folder", ex);
                }
            } else {
                log.info("No 'lost+found' node specified: orphans cannot be fixed");
            }
        }

        if (uuids == null) {
            try {
                Map<NodeId, NodeInfo> batch = pm.getAllNodeInfos(null, NODESATONCE);
                Map<NodeId, NodeInfo> allInfos = batch;

                while (!batch.isEmpty()) {
                    NodeId lastId = null;

                    for (Map.Entry<NodeId, NodeInfo> entry : batch.entrySet()) {
                        NodeId id = entry.getKey();
                        lastId = id;

                        count++;
                        if (count % 1000 == 0) {
                            log.info(pm + ": loaded " + count + " infos...");
                        }

                        if (!CHECKAFTERLOADING) {
                            // check immediately
                            NodeInfo nodeInfo = entry.getValue();
                            checkBundleConsistency(id, nodeInfo, fix, lostNFound, reports, batch);
                        }
                    }

                    batch = pm.getAllNodeInfos(lastId, NODESATONCE);

                    if (CHECKAFTERLOADING) {
                        allInfos.putAll(batch);
                    }
                }

                if (CHECKAFTERLOADING) {
                    // check info
                    for (Map.Entry<NodeId, NodeInfo> entry : allInfos.entrySet()) {
                        checkBundleConsistency(entry.getKey(), entry.getValue(), fix, lostNFound, reports, allInfos);
                    }
                }
            } catch (ItemStateException ex) {
                throw new RepositoryException("getting nodeIds", ex);
            }
        } else {
            // check only given uuids, handle recursive flag

            // 1) convert uuid array to modifiable list
            // 2) for each uuid do
            // a) load node bundle
            // b) check bundle, store any bundle-to-be-modified in collection
            // c) if recursive, add child uuids to list of uuids

            List<NodeId> idList = new ArrayList<NodeId>(uuids.length);
            // convert uuid string array to list of UUID objects
            for (int i = 0; i < uuids.length; i++) {
                try {
                    idList.add(new NodeId(uuids[i]));
                } catch (IllegalArgumentException e) {
                    error(uuids[i],
                            "Invalid id for consistency check, skipping: '"
                                    + uuids[i] + "': " + e);
                }
            }

            // iterate over UUIDs (including ones that are newly added inside
            // the loop!)
            for (int i = 0; i < idList.size(); i++) {
                NodeId id = idList.get(i);
                try {
                    // load the node from the database
                    NodePropBundle bundle = pm.loadBundle(id);

                    if (bundle == null) {
                        if (!isVirtualNode(id)) {
                            error(id.toString(), "No bundle found for id '"
                                    + id + "'");
                        }
                    } else {
                        checkBundleConsistency(id, new NodeInfo(bundle), fix, lostNFound,
                                reports, Collections.<NodeId, NodeInfo>emptyMap());

                        if (recursive) {
                            for (NodePropBundle.ChildNodeEntry entry : bundle
                                    .getChildNodeEntries()) {
                                idList.add(entry.getId());
                            }
                        }
View Full Code Here


        // look at the node's children
        Collection<NodePropBundle.ChildNodeEntry> missingChildren = new ArrayList<NodePropBundle.ChildNodeEntry>();
        Collection<NodePropBundle.ChildNodeEntry> disconnectedChildren = new ArrayList<NodePropBundle.ChildNodeEntry>();

        NodePropBundle bundle = null;

        for (final NodeId childNodeId : nodeInfo.getChildren()) {

            // skip check for system nodes (root, system root, version storage,
            // node types)
            if (childNodeId.toString().endsWith("babecafebabe")) {
                continue;
            }

            try {
                // analyze child node bundles
                NodePropBundle childBundle = null;
                NodeInfo childNodeInfo = infos.get(childNodeId);

                // does the child exist?
                if (childNodeInfo == null) {
                    // try to load the bundle
                    childBundle = pm.loadBundle(childNodeId);
                    if (childBundle == null) {
                        // the child indeed does not exist
                        // double check whether we still exist and the child entry is still there
                        if (bundle == null) {
                            bundle = pm.loadBundle(id);
                        }
                        if (bundle != null) {
                            NodePropBundle.ChildNodeEntry childNodeEntry = null;
                            for (NodePropBundle.ChildNodeEntry entry : bundle.getChildNodeEntries()) {
                                if (entry.getId().equals(childNodeId)) {
                                    childNodeEntry = entry;
                                    break;
                                }
                            }
                            if (childNodeEntry != null) {
                                String message = "NodeState '" + id + "' references inexistent child '" + childNodeId + "'";
                                log.error(message);
                                addMessage(reports, id, message, ReportItem.Type.MISSING);
                                missingChildren.add(childNodeEntry);
                            }
                        } else {
                            return;
                        }
                    } else {
                        // exists after all
                        childNodeInfo = new NodeInfo(childBundle);
                    }
                }
                if (childNodeInfo != null) {
                    // if the child exists does it reference the current node as its parent?
                    NodeId cp = childNodeInfo.getParentId();
                    if (!id.equals(cp)) {
                        // double check whether the child still has a different parent
                        if (childBundle == null) {
                            childBundle = pm.loadBundle(childNodeId);
                        }
                        if (childBundle != null && !childBundle.getParentId().equals(id)) {
                            // double check if we still exist
                            if (bundle == null) {
                                bundle = pm.loadBundle(id);
                            }
                            if (bundle != null) {
                                // double check if the child node entry is still there
                                NodePropBundle.ChildNodeEntry childNodeEntry = null;
                                for (NodePropBundle.ChildNodeEntry entry : bundle.getChildNodeEntries()) {
                                    if (entry.getId().equals(childNodeId)) {
                                        childNodeEntry = entry;
                                        break;
                                    }
                                }
                                if (childNodeEntry != null) {
                                    // indeed we have a disconnected child
                                    String message = "Node has invalid parent id: '" + cp + "' (instead of '" + id + "')";
                                    log.error(message);
                                    addMessage(reports, childNodeId, message, ReportItem.Type.DISCONNECTED);
                                    disconnectedChildren.add(childNodeEntry);
                                }
                            } else {
                                return;
                            }

                        }
                    }
                }
            } catch (ItemStateException e) {
                // problem already logged (loadBundle called with
                // logDetailedErrors=true)
                addMessage(reports, id, e.getMessage(), ReportItem.Type.ERROR);
            }
        }
        // remove child node entry (if fixing is enabled)
        if (fix && (!missingChildren.isEmpty() || !disconnectedChildren.isEmpty())) {
            for (NodePropBundle.ChildNodeEntry entry : missingChildren) {
                bundle.getChildNodeEntries().remove(entry);
            }
            for (NodePropBundle.ChildNodeEntry entry : disconnectedChildren) {
                bundle.getChildNodeEntries().remove(entry);
            }
            fixBundle(bundle);
        }

        // check parent reference
        NodeId parentId = nodeInfo.getParentId();
        try {
            // skip root nodes (that point to itself)
            if (parentId != null && !id.toString().endsWith("babecafebabe")) {
                NodePropBundle parentBundle = null;
                NodeInfo parentInfo = infos.get(parentId);

                // does the parent exist?
                if (parentInfo == null) {
                    // try to load the bundle
                    parentBundle = pm.loadBundle(parentId);
                    if (parentBundle == null) {
                        // indeed the parent doesn't exist
                        // double check whether we still exist and the parent is still the same\
                        if (bundle == null) {
                            bundle = pm.loadBundle(id);
                        }
                        if (bundle != null) {
                            if (parentId.equals(bundle.getParentId())) {
                                // indeed we have an orphaned node
                                String message = "NodeState '" + id + "' references inexistent parent id '" + parentId + "'";
                                log.error(message);
                                addMessage(reports, id, message, ReportItem.Type.ORPHANED);
                                if (fix && lostNFoundId != null) {
                                    // add a child to lost+found
                                    NodePropBundle lfBundle = pm.loadBundle(lostNFoundId);
                                    lfBundle.markOld();
                                    String nodeName = id + "-" + System.currentTimeMillis();
                                    lfBundle.addChildNodeEntry(NF.create("", nodeName), id);
                                    pm.storeBundle(lfBundle);
                                    pm.evictBundle(lostNFoundId);

                                    // set lost+found parent
                                    bundle.setParentId(lostNFoundId);
View Full Code Here

                return null;
            }
            InputStream in = itemFs.getInputStream(path);
            TrackingInputStream cin = new TrackingInputStream(in);
            din = new DataInputStream(cin);
            NodePropBundle bundle = binding.readBundle(din, id);
            bundle.setSize(cin.getPosition());
            return bundle;
        } catch (Exception e) {
            String msg = "failed to read bundle: " + id + ": " + e;
            log.error(msg);
            throw new ItemStateException(msg, e);
View Full Code Here

                return null;
            }
            InputStream in = itemFs.getInputStream(path);
            TrackingInputStream cin = new TrackingInputStream(in);
            din = new DataInputStream(cin);
            NodePropBundle bundle = binding.readBundle(din, id);
            bundle.setSize(cin.getPosition());
            return bundle;
        } catch (Exception e) {
            String msg = "failed to read bundle: " + id + ": " + e;
            log.error(msg);
            throw new ItemStateException(msg, e);
View Full Code Here

                if (rs.next()) {
                    InputStream input = rs.getBinaryStream(1);
                    try {
                        TrackingInputStream cin = new TrackingInputStream(input);
                        DataInputStream din = new DataInputStream(cin);
                        NodePropBundle bundle = binding.readBundle(din, id);
                        bundle.setSize(cin.getPosition());
                        return bundle;
                    } finally {
                        input.close();
                    }
                } else {
View Full Code Here

     *
     * Loads the state via the appropriate NodePropBundle.
     */
    public NodeState load(NodeId id)
            throws NoSuchItemStateException, ItemStateException {
        NodePropBundle bundle = getBundle(id);
        if (bundle == null) {
            throw new NoSuchItemStateException(id.toString());
        }
        return bundle.createNodeState(this);
    }
View Full Code Here

     *
     * Loads the state via the appropriate NodePropBundle.
     */
    public PropertyState load(PropertyId id)
            throws NoSuchItemStateException, ItemStateException {
        NodePropBundle bundle = getBundle(id.getParentId());
        if (bundle == null) {
            throw new NoSuchItemStateException(id.toString());
        }
        PropertyState state = bundle.createPropertyState(this, id.getName());
        if (state == null) {
            // check if autocreated property state
            if (id.getName().equals(NameConstants.JCR_UUID)) {
                state = createNew(id);
                state.setType(PropertyType.STRING);
                state.setMultiValued(false);
                state.setValues(new InternalValue[]{InternalValue.create(id.getParentId().toString())});
            } else if (id.getName().equals(NameConstants.JCR_PRIMARYTYPE)) {
                state = createNew(id);
                state.setType(PropertyType.NAME);
                state.setMultiValued(false);
                state.setValues(new InternalValue[]{InternalValue.create(bundle.getNodeTypeName())});
            } else if (id.getName().equals(NameConstants.JCR_MIXINTYPES)) {
                Set<Name> mixins = bundle.getMixinTypeNames();
                state = createNew(id);
                state.setType(PropertyType.NAME);
                state.setMultiValued(true);
                state.setValues(InternalValue.create(mixins.toArray(new Name[mixins.size()])));
            } else {
                throw new NoSuchItemStateException(id.toString());
            }
            bundle.addProperty(state);
        }
        return state;
    }
View Full Code Here

     * {@inheritDoc}
     *
     * Loads the state via the appropriate NodePropBundle.
     */
    public boolean exists(PropertyId id) throws ItemStateException {
        NodePropBundle bundle = getBundle(id.getParentId());
        return bundle != null && bundle.hasProperty(id.getName());
    }
View Full Code Here

            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(getBinding(), (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 = (NodePropBundle) 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, mixinTypes and uuid properties
                if (id.getName().equals(NameConstants.JCR_PRIMARYTYPE)
                    || id.getName().equals(NameConstants.JCR_MIXINTYPES)
                    || id.getName().equals(NameConstants.JCR_UUID)) {
                    continue;
                }
                NodeId nodeId = id.getParentId();
                NodePropBundle bundle = (NodePropBundle) 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);
            }
        }
        // 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 = (NodePropBundle) 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());
                }
            }
        }
        // add added properties
        for (ItemState state : changeLog.addedStates()) {
            if (!state.isNode()) {
                PropertyId id = (PropertyId) state.getId();
                // skip primaryType pr mixinTypes properties
                if (id.getName().equals(NameConstants.JCR_PRIMARYTYPE)
                    || id.getName().equals(NameConstants.JCR_MIXINTYPES)
                    || id.getName().equals(NameConstants.JCR_UUID)) {
                    continue;
                }
                NodeId nodeId = id.getParentId();
                NodePropBundle bundle = (NodePropBundle) 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);
            }
        }

        // now store all modified bundles
        for (NodePropBundle bundle : modified.values()) {
View Full Code Here

     * @return the bundle or <code>null</code> if the bundle does not exist
     *
     * @throws ItemStateException if an error occurs.
     */
    private NodePropBundle getBundle(NodeId id) throws ItemStateException {
        NodePropBundle bundle = bundles.get(id);
        if (bundle == MISSING) {
            return null;
        } else if (bundle == null) {
            bundle = loadBundle(id);
            if (bundle != null) {
                bundle.markOld();
                bundles.put(id, bundle, bundle.getSize());
            } else {
                bundles.put(id, MISSING, 16);
            }
        }
        return bundle;
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.persistence.util.NodePropBundle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.