Package org.exist.storage

Examples of org.exist.storage.NodePath


                final List<Predicate> preds = locationStep.getPredicates();

                // will become true if optimizable expression is found
                boolean canOptimize = false;
                // get path of path expression before the predicates
                NodePath contextPath = toNodePath(getPrecedingSteps(locationStep));
                // process the remaining predicates
                for (Predicate pred : preds) {
                    if (pred.getLength() != 1) {
                        // can only optimize predicates with one expression
                        break;
                    }

                    Expression innerExpr = pred.getExpression(0);
                    List<LocationStep> steps = getStepsToOptimize(innerExpr);
                    if (steps == null || steps.size() == 0) {
                        // no optimizable steps found
                        continue;
                    }

                    // check if inner steps are on an axis we can optimize
                    final int axis;
                    if (innerExpr instanceof InternalFunctionCall) {
                        InternalFunctionCall fcall = (InternalFunctionCall) innerExpr;
                        axis = ((Optimizable) fcall.getFunction()).getOptimizeAxis();
                    } else {
                        axis = ((Optimizable) innerExpr).getOptimizeAxis();
                    }
                    if (!(axis == Constants.CHILD_AXIS || axis == Constants.DESCENDANT_AXIS ||
                            axis == Constants.DESCENDANT_SELF_AXIS || axis == Constants.ATTRIBUTE_AXIS ||
                            axis == Constants.DESCENDANT_ATTRIBUTE_AXIS || axis == Constants.SELF_AXIS
                    )) {
                        continue;
                    }

                    // compute left hand path
                    NodePath innerPath = toNodePath(steps);
                    if (innerPath == null) {
                        continue;
                    }
                    NodePath path;
                    if (contextPath == null) {
                        path = innerPath;
                    } else {
                        path = new NodePath(contextPath);
                        path.append(innerPath);
                    }

                    if (path.length() > 0) {
                        // replace with call to lookup function
                        // collect arguments
                        Lookup func = rewrite(innerExpr, path);
                        // preserve original comparison: may need it for in-memory lookups
                        func.setFallback(innerExpr, axis);
View Full Code Here


        }
        return operator;
    }

    protected static NodePath toNodePath(List<LocationStep> steps) {
        NodePath path = new NodePath();
        for (LocationStep step: steps) {
            if (step == null) {
                return null;
            }
            NodeTest test = step.getTest();
            if (test.isWildcardTest() && step.getAxis() == Constants.SELF_AXIS) {
                //return path;
                continue;
            }
            if (!test.isWildcardTest() && test.getName() != null) {
                int axis = step.getAxis();
                if (axis == Constants.DESCENDANT_AXIS || axis == Constants.DESCENDANT_SELF_AXIS) {
                    path.addComponent(NodePath.SKIP);
                } else if (axis != Constants.CHILD_AXIS && axis != Constants.ATTRIBUTE_AXIS) {
                    return null// not optimizable
                }
                path.addComponent(test.getName());
            }
        }
        return path;
    }
View Full Code Here

    public StoredNode getReindexRoot(StoredNode node, NodePath path, boolean insert, boolean includeSelf) {
//        if (node.getNodeType() == Node.ATTRIBUTE_NODE)
//            return null;
        if (config == null)
            return null;
        NodePath p = new NodePath(path);
        boolean reindexRequired = false;
        if (node.getNodeType() == Node.ELEMENT_NODE && !includeSelf)
            p.removeLastComponent();
        for (int i = 0; i < p.length(); i++) {
            if (config.matches(p)) {
                reindexRequired = true;
                break;
            }
            p.removeLastComponent();
        }
        if (reindexRequired) {
            p = new NodePath(path);
            StoredNode topMost = null;
            StoredNode currentNode = node;
            if (currentNode.getNodeType() != Node.ELEMENT_NODE)
                currentNode = currentNode.getParentStoredNode();
            while (currentNode != null) {
                if (config.matches(p))
                    topMost = currentNode;
                currentNode = currentNode.getParentStoredNode();
                p.removeLastComponent();
            }
            return topMost;
        }
        return null;
    }
View Full Code Here

        final ElementImpl elem = new ElementImpl(ROOT_QNAME, broker.getBrokerPool().getSymbols());
        elem.setNodeId(broker.getBrokerPool().getNodeFactory().createInstance());
        elem.setOwnerDocument(targetDoc);
        elem.setChildCount(doc.getChildCount());
        elem.addNamespaceMapping("exist", Namespaces.EXIST_NS);
        final NodePath path = new NodePath();
        path.addComponent(ROOT_QNAME);
        stack.push(elem);
        broker.storeNode(transaction, elem, path, indexSpec);
        targetDoc.appendChild(elem);
        elem.setChildCount(0);
        // store the document nodes
        int top = (doc.size > 1) ? 1 : -1;
        while (top > 0) {
            store(top, path);
            top = doc.getNextSiblingFor(top);
        }
        //Close the wrapper element
        stack.pop();
        broker.endElement(elem, path, null);
        path.removeLastComponent();
    }
View Full Code Here

        }
        return next;
    }

    public NodePath getPath() {
        final NodePath path = new NodePath();
        if (getNodeType() == Node.ELEMENT_NODE)
            {path.addComponent(getQName());}
        NodeImpl parent = (NodeImpl)getParentNode();
        while (parent != null && parent.getNodeType() != Node.DOCUMENT_NODE) {
            path.addComponentAtStart(parent.getQName());
            parent = (NodeImpl)parent.getParentNode();
        }
        return path;
    }
View Full Code Here

    }

    private void updateDocument(DBBroker broker, DocumentImpl doc) {
        final ElementImpl root = (ElementImpl) doc.getDocumentElement();
        try {
            final NodePath path = new NodePath();
            final Stack<NodeStats> stack = new Stack<NodeStats>();
            QName qname;
            final EmbeddedXMLStreamReader reader = broker.getXMLStreamReader(root, false);
            while (reader.hasNext()) {
                final int status = reader.next();
                switch (status) {
                    case XMLStreamReader.START_ELEMENT:
                        for (int i = 0; i < stack.size(); i++) {
                            final NodeStats next = stack.elementAt(i);
                            next.incDepth();
                        }
                        qname = reader.getQName();
                        path.addComponent(qname);
                        final NodeStats nodeStats = perDocGuide.add(path);
                        stack.push(nodeStats);
                        break;
                    case XMLStreamReader.END_ELEMENT:
                        path.removeLastComponent();
                        final NodeStats stats = stack.pop();
                        stats.updateMaxDepth();
                        break;
                }
            }
View Full Code Here

     *
     * @param other
     * @return the other instance containing the merged graphs
     */
    public DataGuide mergeInto(DataGuide other) {
        root.mergeInto(other, new NodePath());
        return other;
    }
View Full Code Here

        children[children.length - 1] = new NodeStats(this, qn);
        return children[children.length - 1];
    }

    protected void mergeInto(DataGuide other, NodePath currentPath) {
        NodePath newPath;
        if (qname == null)
            {newPath = currentPath;}
        else {
            newPath = new NodePath(currentPath);
            newPath.addComponent(qname);
            other.add(newPath, this);
        }

        if (children != null) {
            for (int i = 0; i < children.length; i++) {
View Full Code Here

                       "A node replacing the document root needs to be an element");}
                broker.removeNode(transaction, oldNode, oldNode.getPath(), null);
                broker.endRemove(transaction);
                newNode.setNodeId(oldNode.getNodeId());
                broker.insertNodeAfter(null, previousNode, newNode);
                final NodePath path = newNode.getPath();
                broker.indexNode(transaction, newNode, path);
                broker.endElement(newNode, path, null);
                broker.flush();
            } else {
                broker.removeNode(transaction, oldNode, oldNode.getPath(), null);
View Full Code Here

public class IndexUtils {

    public static void scanNode(DBBroker broker, Txn transaction, StoredNode node, StreamListener listener) {
        final Iterator<StoredNode> iterator = broker.getNodeIterator(node);
        iterator.next();
        final NodePath path = node.getPath();
        scanNode(transaction, iterator, node, listener, path);
    }
View Full Code Here

TOP

Related Classes of org.exist.storage.NodePath

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.