Package org.exist.dom

Examples of org.exist.dom.NodeSet


        if (contextItem != null)
                {contextSequence = contextItem.toSequence();}

        boolean useCached = false;
        boolean optimize = false;
        NodeSet originalContext = null;

        if (contextSequence == null || contextSequence.isPersistentSet()) {    // don't try to optimize in-memory node sets!
            // contextSequence will be overwritten
            originalContext = contextSequence == null ? null : contextSequence.toNodeSet();
            if (cachedContext != null && cachedContext == originalContext)
                {useCached = !originalContext.hasChanged(cachedTimestamp);}
            if (contextVar != null) {
                contextSequence = contextVar.eval(contextSequence);
            }
            // check if all Optimizable expressions signal that they can indeed optimize
            // in the current context
            if (useCached)
                {optimize = cachedOptimize;}
            else {
                if (optimizables != null && optimizables.length > 0) {
                    for (int i = 0; i < optimizables.length; i++) {
                        if (optimizables[i].canOptimize(contextSequence))
                            {optimize = true;}
                        else {
                            optimize = false;
                            break;
                        }
                    }
                }
            }
        }
        if (optimize) {
            cachedContext = originalContext;
            cachedTimestamp = originalContext == null ? 0 : originalContext.getState();
            cachedOptimize = true;
            NodeSet ancestors;
            NodeSet result = null;
            for (int current = 0; current < optimizables.length; current++) {
                NodeSet selection = optimizables[current].preSelect(contextSequence, current > 0);
                if (LOG.isTraceEnabled())
                    {LOG.trace("exist:optimize: pre-selection: " + selection.getLength());}
                // determine the set of potential ancestors for which the predicate has to
                // be re-evaluated to filter out wrong matches
                if (selection.isEmpty())
                  {ancestors = selection;}
                else if (contextStep == null || current > 0) {
                    ancestors = selection.selectAncestorDescendant(contextSequence.toNodeSet(), NodeSet.ANCESTOR,
                        true, contextId, true);
                } else {
//                    NodeSelector selector;
                    final long start = System.currentTimeMillis();
//                    selector = new AncestorSelector(selection, contextId, true, false);
                    final StructuralIndex index = context.getBroker().getStructuralIndex();
                    final QName ancestorQN = contextStep.getTest().getName();
                    if (optimizables[current].optimizeOnSelf()) {
                        ancestors = index.findAncestorsByTagName(ancestorQN.getNameType(), ancestorQN, Constants.SELF_AXIS,
                            selection.getDocumentSet(), selection, contextId);
                    } else {
                        ancestors = index.findAncestorsByTagName(ancestorQN.getNameType(), ancestorQN,
                            optimizables[current].optimizeOnChild() ? Constants.PARENT_AXIS : Constants.ANCESTOR_SELF_AXIS,
                            selection.getDocumentSet(), selection, contextId);
                    }
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Ancestor selection took " + (System.currentTimeMillis() - start));
                        LOG.trace("Found: " + ancestors.getLength());
                    }
View Full Code Here


            final Sequence ls = left.eval(contextSequence, null);
            doOptimize = doOptimize && (ls.isPersistentSet() || ls.isEmpty());
            if (doOptimize) {
             
              if (inPredicate) {
                    NodeSet lr = ls.toNodeSet();
                    lr = lr.getContextNodes(getContextId());

                    if (lr.isEmpty())
                        {return NodeSet.EMPTY_SET;}

                    final Sequence rs = right.eval(lr, null);
                   
                    final NodeSet rr = rs.toNodeSet();
                    result = rr.getContextNodes(getContextId());

              } else {
                final Sequence rs = right.eval(contextSequence, null);

                if (rs.isPersistentSet()) {
                      NodeSet rl = ls.toNodeSet();
                      rl = rl.getContextNodes(left.getContextId());

                        if (rl.isEmpty())
                            {return NodeSet.EMPTY_SET;}

                      // TODO: optimize and return false if rl.isEmpty() ?
                      NodeSet rr = rs.toNodeSet();
                      rr = rr.getContextNodes(right.getContextId());
                      result = rr.intersection(rl);
                      //<test>{() and ()}</test> has to return <test>false</test>         
                      if (getParent() instanceof EnclosedExpr ||
                          //First, the intermediate PathExpr
                          (getParent() != null && getParent().getParent() == null)) {
                          result = result.isEmpty() ? BooleanValue.FALSE : BooleanValue.TRUE;
View Full Code Here

    }

        //execute the XQuery
        try {
          //TODO : should we provide another contextSet ?
          final NodeSet contextSet = NodeSet.EMPTY_SET;
      service.execute(compiledQuery, contextSet);
      //TODO : should we have a special processing ?
      LOG.debug("Trigger fired for prepare");
        } catch(final XPathException e) {
        TriggerStatePerThread.setTriggerRunningState(TriggerStatePerThread.NO_TRIGGER_RUNNING, this, null);
View Full Code Here

    }

      //execute the XQuery
        try {
          //TODO : should we provide another contextSet ?
          final NodeSet contextSet = NodeSet.EMPTY_SET;         
      service.execute(compiledQuery, contextSet);
      //TODO : should we have a special processing ?
        } catch (final XPathException e) {
          //Should never be reached
      LOG.error("Error during trigger finish", e);
View Full Code Here

        doOptimize = doOptimize && (ls.isPersistentSet() || ls.isEmpty());
        if (doOptimize) {
            // yes: try to optimize by looking at right operand
            final Sequence rs = right.eval(contextSequence, null);
            if (rs.isPersistentSet() || rs.isEmpty()) {
                NodeSet rl = ls.toNodeSet();
                rl = rl.getContextNodes(contextId);
                NodeSet rr = rs.toNodeSet();
                rr = rr.getContextNodes(contextId);
                result = rl.union(rr);
                //<test>{() or ()}</test> should return <test>false</test>     
                if (getParent() instanceof EnclosedExpr ||
                    //First, the intermediate PathExpr
                    (getParent() != null && getParent().getParent() == null)) {
View Full Code Here

                //We might not be sure of the return type at this level
        Type.subTypeOf(whereExpr.returnsType(), Type.ITEM)) {
      final Sequence seq = whereExpr.eval(contextSequence);
      //But *now*, we are ;-)
      if (Type.subTypeOf(whereExpr.returnsType(), Type.NODE)) {
        final NodeSet nodes = seq.toNodeSet();
        // if the where expression returns a node set, check the context
        // node of each node in the set          
        final NodeSet contextSet = contextSequence.toNodeSet();
        final boolean contextIsVirtual = contextSet instanceof VirtualNodeSet;           
        final NodeSet result = new ExtArrayNodeSet();
        DocumentImpl lastDoc = null;

        for (final NodeProxy current : nodes) {
          int sizeHint = Constants.NO_SIZE_HINT;
          if(lastDoc == null || current.getDocument() != lastDoc) {
            lastDoc = current.getDocument();
            sizeHint = nodes.getSizeHint(lastDoc);
          }
          ContextItem  context = current.getContext();               
          if (context == null) {              
            throw new XPathException(this, "Internal evaluation error: context node is missing for node " +
                current.getNodeId() + "!");
          }
  //        LOG.debug(current.debugContext());
          while (context != null) {
                      //TODO : Is this the context we want ? Not sure... would have prefered the LetExpr.
            if (context.getContextId() == whereExpr.getContextId()) {
              final NodeProxy contextNode = context.getNode();                   
              if(contextIsVirtual || contextSet.contains(contextNode)) {
                              contextNode.addMatches(current);
                result.add(contextNode, sizeHint);
              }
            }
                      context = context.getNextDirect();
          }
        }
        return result;
      }
    }
   
    if (contextSequence == null) {
      final Sequence innerSeq = whereExpr.eval(null);
      return innerSeq.effectiveBooleanValue() ? BooleanValue.TRUE : BooleanValue.FALSE;
    } else {
      // general where clause: just check the effective boolean value
      final ValueSequence result = new ValueSequence();
      int p = 0;     
      for (final SequenceIterator i = contextSequence.iterate(); i.hasNext(); p++) {
        final Item item = i.nextItem();
        context.setContextSequencePosition(p, contextSequence);
                final Sequence innerSeq = whereExpr.eval(contextSequence, item);               
        if (innerSeq.effectiveBooleanValue())
          {result.add(item);}                   
      }
      return result;
    }
  }
View Full Code Here

    if(attributeValue == null)
      {return null;}
    final AtomicValue comparison = new AnyURIValue(attributeValue);

    final DocumentSet documentSet = getPolicyDocuments(broker, true);
    final NodeSet nodeSet = documentSet.docsToNodeSet();

        final NativeValueIndex valueIndex = broker.getValueIndex();
        final Sequence results = valueIndex.find(null, Constants.EQ, documentSet, null, NodeSet.ANCESTOR, attributeQName, comparison);
//        Sequence results = index.findByQName(attributeQName, comparison, nodeSet);
    //TODO : should we honour (# exist:force-index-use #) ?
View Full Code Here

            // If the predicate is known to return a node set, no special treatment is required.
            if (abbreviated && (pred.getExecutionMode() != Predicate.NODE ||
                    !seq.isPersistentSet())) {
                result = new ValueSequence();
                if (seq.isPersistentSet()) {
                    final NodeSet contextSet = seq.toNodeSet();
                    final Sequence outerSequence = contextSet.getParents(getExpressionId());
                    for (final SequenceIterator i = outerSequence.iterate(); i.hasNext(); ) {
                        final NodeValue node = (NodeValue) i.nextItem();
                        final Sequence newContextSeq =
                            contextSet.selectParentChild((NodeSet) node, NodeSet.DESCENDANT,
                            getExpressionId());
                        final Sequence temp = processPredicate(outerSequence, newContextSeq);
                        result.addAll(temp);
                    }
                } else {
View Full Code Here

      // resource is a document
            //TODO : use dedicated function in XmldbURI
      final XmldbURI[] docs = new XmldbURI[] { XmldbURI.create(res.getParentCollection().getName()).append(res.getDocumentId()) };
      return doQuery(query, docs, null, sortBy);
    } else {
      final NodeSet set = new ExtArrayNodeSet(1);
      set.add(node);
      final XmldbURI[] docs = new XmldbURI[] { node.getDocument().getURI() };
      return doQuery(query, docs, set, sortBy);
    }
  }
View Full Code Here

    if (node == null) {
      // resource is a document
      final XmldbURI[] docs = new XmldbURI[] { XmldbURI.create(res.getParentCollection().getName()).append(res.getDocumentId()) };
      return execute(docs, null, expression, null);
    } else {
      final NodeSet set = new ExtArrayNodeSet(1);
      set.add(node);
      final XmldbURI[] docs = new XmldbURI[] { node.getDocument().getURI() };
      return execute(docs, set, expression, null);
    }
  }
View Full Code Here

TOP

Related Classes of org.exist.dom.NodeSet

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.