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

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


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

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


            if (isVirtualNode(childNodeId)) {
                continue;
            }

            NodeInfo childNodeInfo = infos.get(childNodeId);

            if (childNodeInfo == null) {
                addError(new MissingChild(nodeId, childNodeId));
            } else {
                if (!nodeId.equals(childNodeInfo.getParentId())) {
                    addError(new DisconnectedChild(nodeId, childNodeId, childNodeInfo.getParentId()));
                }
            }
        }

        // check the parent
        NodeId parentId = nodeInfo.getParentId();
        // skip root nodes
        if (parentId != null && !isRoot(nodeId)) {
            NodeInfo parentInfo = infos.get(parentId);

            if (parentInfo == null) {
                addError(new OrphanedNode(nodeId, parentId));
            } else {
                // if the parent exists, does it have a child node entry for us?
                boolean found = false;

                for (NodeId childNodeId : parentInfo.getChildren()) {
                    if (childNodeId.equals(nodeId)){
                        found = true;
                        break;
                    }
                }
View Full Code Here

                            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()) {
View Full Code Here

            }

            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);
                                    fixBundle(bundle);
                                }
                            }
                        } else {
                            return;
                        }
                    } else {
                        // parent exists after all
                        parentInfo = new NodeInfo(parentBundle);
                    }
                }
                if (parentInfo != null) {
                    // if the parent exists, does it have a child node entry for us?
                    boolean found = false;

                    for (NodeId childNodeId : parentInfo.getChildren()) {
                        if (childNodeId.equals(id)){
                            found = true;
                            break;
                        }
                    }
View Full Code Here

                    if (current.compareTo(lowId) <= 0) {
                        continue;
                    }
                }
                NodePropBundle bundle = readBundle(current, rs, getStorageModel() == SM_LONGLONG_KEYS ? 3 : 2);
                NodeInfo nodeInfo = new NodeInfo(bundle);
                result.put(nodeInfo.getId(), nodeInfo);
            }
            return result;
        } catch (SQLException e) {
            String msg = "getAllNodeIds failed.";
            log.error(msg, e);
View Full Code Here

    @Override
    public Map<NodeId, NodeInfo> getAllNodeInfos(NodeId after, int maxCount)
            throws ItemStateException, RepositoryException {
        Map<NodeId, NodeInfo> infos = new LinkedHashMap<NodeId, NodeInfo>();
        for (NodeId nodeId : getAllNodeIds(after, maxCount)) {
            infos.put(nodeId, new NodeInfo(loadBundle(nodeId)));
        }
        return infos;
    }
View Full Code Here

    @Override
    public Map<NodeId, NodeInfo> getAllNodeInfos(NodeId after, int maxCount)
            throws ItemStateException, RepositoryException {
        Map<NodeId, NodeInfo> infos = new LinkedHashMap<NodeId, NodeInfo>();
        for (NodeId nodeId : getAllNodeIds(after, maxCount)) {
            infos.put(nodeId, new NodeInfo(loadBundle(nodeId)));
        }
        return infos;
    }
View Full Code Here

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

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

            if (isVirtualNode(childNodeId)) {
                continue;
            }

            NodeInfo childNodeInfo = infos.get(childNodeId);

            if (childNodeInfo == null) {
                addError(new MissingChild(nodeId, childNodeId));
            } else {
                if (!nodeId.equals(childNodeInfo.getParentId())) {
                    addError(new DisconnectedChild(nodeId, childNodeId, childNodeInfo.getParentId()));
                }
            }
        }

        // check the parent
        NodeId parentId = nodeInfo.getParentId();
        // skip root nodes
        if (parentId != null && !isRoot(nodeId)) {
            NodeInfo parentInfo = infos.get(parentId);

            if (parentInfo == null) {
                addError(new OrphanedNode(nodeId, parentId));
            } else {
                // if the parent exists, does it have a child node entry for us?
                boolean found = false;

                for (NodeId childNodeId : parentInfo.getChildren()) {
                    if (childNodeId.equals(nodeId)){
                        found = true;
                        break;
                    }
                }
View Full Code Here

                    if (current.compareTo(lowId) <= 0) {
                        continue;
                    }
                }
                NodePropBundle bundle = readBundle(current, rs, getStorageModel() == SM_LONGLONG_KEYS ? 3 : 2);
                NodeInfo nodeInfo = new NodeInfo(bundle);
                result.put(nodeInfo.getId(), nodeInfo);
            }
            return result;
        } catch (SQLException e) {
            String msg = "getAllNodeIds failed.";
            log.error(msg, e);
View Full Code Here

TOP

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

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.