Package org.exist.dom

Examples of org.exist.dom.NewArrayNodeSet


        final Sequence rightSeq = getRight().eval( contextSequence );
       
        // if the right hand sequence has more than one item, we need to merge them
        // into preselectResult
        if (rightSeq.getItemCount() > 1)
          {preselectResult = new NewArrayNodeSet();}
       
        // Iterate through each item in the right-hand sequence
        for( final SequenceIterator itRightSeq = rightSeq.iterate(); itRightSeq.hasNext(); ) {

            //Get the index key
View Full Code Here


        if( LOG.isTraceEnabled() ) {
            LOG.trace( "No index: fall back to nodeSetCompare" );
        }
        final long           start    = System.currentTimeMillis();
        final NodeSet        result   = new NewArrayNodeSet();
        final Collator collator = getCollator( contextSequence );

        if( ( contextSequence != null ) && !contextSequence.isEmpty() && !contextSequence.getDocumentSet().contains( nodes.getDocumentSet() ) ) {

            for( final NodeProxy item : nodes ) {
                ContextItem context = item.getContext();

                if( context == null ) {
                    throw( new XPathException( this, "Internal error: context node missing" ) );
                }
                final AtomicValue lv = item.atomize();

                do {
                    final Sequence rs = getRight().eval( context.getNode().toSequence() );

                    for( final SequenceIterator i2 = rs.iterate(); i2.hasNext(); ) {
                        final AtomicValue rv = i2.nextItem().atomize();

                        if( compareAtomic( collator, lv, rv ) ) {
                            result.add( item );
                        }
                    }
                } while( ( context = context.getNextDirect() ) != null );
            }
        } else {

            for( final NodeProxy item : nodes ) {
                final AtomicValue lv = item.atomize();
                final Sequence    rs = getRight().eval( contextSequence );

                for( final SequenceIterator i2 = rs.iterate(); i2.hasNext(); ) {
                    final AtomicValue rv = i2.nextItem().atomize();

                    if( compareAtomic( collator, lv, rv ) ) {
                        result.add( item );
                    }
                }
            }
        }
View Full Code Here

  public NodeSet toNodeSet() throws XPathException {
    if(size == UNSET_SIZE)
      {return NodeSet.EMPTY_SET;}
        // for this method to work, all items have to be nodes
    if(itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) {
      final NodeSet set = new NewArrayNodeSet();
      NodeValue v;
      for (int i = 0; i <= size; i++) {
        v = (NodeValue)values[i];
        if(v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
                    // found an in-memory document
                    final DocumentImpl doc = ((NodeImpl)v).getDocument();
                    if (doc==null) {
                       continue;
                    }
                    // make this document persistent: doc.makePersistent()
                    // returns a map of all root node ids mapped to the corresponding
                    // persistent node. We scan the current sequence and replace all
                    // in-memory nodes with their new persistent node objects.
                    final DocumentImpl expandedDoc = doc.expandRefs(null);
                    final org.exist.dom.DocumentImpl newDoc = expandedDoc.makePersistent();
                    if (newDoc != null) {
                        NodeId rootId = newDoc.getBrokerPool().getNodeFactory().createInstance();
                        for (int j = i; j <= size; j++) {
                            v = (NodeValue) values[j];
                            if(v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
                                NodeImpl node = (NodeImpl) v;
                                if (node.getDocument() == doc) {
                                    if (node.getNodeType() == Node.ATTRIBUTE_NODE)
                                        {node = expandedDoc.getAttribute(node.getNodeNumber());}
                                    else
                                        {node = expandedDoc.getNode(node.getNodeNumber());}
                                    NodeId nodeId = node.getNodeId();
                                    if (nodeId == null)
                                        {throw new XPathException("Internal error: nodeId == null");}
                                    if (node.getNodeType() == Node.DOCUMENT_NODE)
                                        {nodeId = rootId;}
                                    else
                                        {nodeId = rootId.append(nodeId);}
                                    NodeProxy p = new NodeProxy(newDoc, nodeId, node.getNodeType());
                                    if (p != null) {
                                        // replace the node by the NodeProxy
                                        values[j] = p;
                                    }
                                }
                            }
                        }
                        set.add((NodeProxy) values[i]);
                    }
                } else {
          set.add((NodeProxy)v);
        }
      }
            if (holderVar != null)
                {holderVar.setValue(set);}
            return set;
View Full Code Here

        } catch(final PermissionDeniedException pde) {
            throw new XPathException("FODC0002: can not access collection '" + pde.getMessage() + "'");
           
        }
        // iterate through all docs and create the node set
        final NodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 1);
        Lock dlock;
        DocumentImpl doc;
        for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext();) {
            doc = i.next();
            dlock = doc.getUpdateLock();
            boolean lockAcquired = false;
            try {
                if (!context.inProtectedMode() && !dlock.hasLock()) {
                    dlock.acquire(Lock.READ_LOCK);
                    lockAcquired = true;
                }
                result.add(new NodeProxy(doc)); // , -1, Node.DOCUMENT_NODE));
            } catch (final LockException e) {
                throw new XPathException(e.getMessage());
            } finally {
                if (lockAcquired)
                    {dlock.release(Lock.READ_LOCK);}
View Full Code Here

        else
            return AttrImpl.CDATA;
    }

    private void buildChangeSet() {
        changeSet = new NewArrayNodeSet();
        for (NodeId nodeId : insertedNodes.keySet()) {
            changeSet.add(new NodeProxy(diffDoc, nodeId));
        }
        for (NodeId nodeId : appendedNodes.keySet()) {
            changeSet.add(new NodeProxy(diffDoc, nodeId));
View Full Code Here

//        // better use compile-time inspection and maybe a pragma to mark those
//        // sections in the query that can be safely cached
//        if (cachedDocs != null && cachedDocs.equalDocs(ds)) return cached;
       
        // check if the loaded documents should remain locked
        NewArrayNodeSet result = new NewArrayNodeSet(2);
        try {
            // wait for pending updates
            if (!context.inProtectedMode())
                {ds.lock(context.getBroker(), false, true);}
          DocumentImpl doc;
          for (final Iterator<DocumentImpl> i = ds.getDocumentIterator(); i.hasNext();) {
              doc = i.next();
                if (context.inProtectedMode() && !context.getProtectedDocs().containsKey(doc.getDocId()))
                    {continue;}
                if(doc.getResourceType() == DocumentImpl.XML_FILE) {  // skip binary resources
                result.add(new NodeProxy(doc));
              }
            }
          cached = result;
          cachedDocs = ds;
        } catch (final LockException e) {
View Full Code Here

     * @param contextSequence
     * @return The result of the node set evaluation of the predicate.
     * @throws XPathException
     */
    private Sequence selectByNodeSet(Sequence contextSequence) throws XPathException {
        final NewArrayNodeSet result = new NewArrayNodeSet();
        final NodeSet contextSet = contextSequence.toNodeSet();
        final boolean contextIsVirtual = contextSet instanceof VirtualNodeSet;
        contextSet.setTrackMatches(false);
        final NodeSet nodes = super.eval(contextSet, null).toNodeSet();
        /*
         * if the predicate expression returns results from the cache we can
         * also return the cached result.
         */
        if (cached != null && cached.isValid(contextSequence, null) && nodes.isCached()) {
            if (context.getProfiler().isEnabled())
                {context.getProfiler().message(this, Profiler.OPTIMIZATIONS,
                        "Using cached results", result);}
            return cached.getResult();
        }
        DocumentImpl lastDoc = null;
        for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
            final NodeProxy currentNode = i.next();
            int sizeHint = Constants.NO_SIZE_HINT;
            if (lastDoc == null || currentNode.getDocument() != lastDoc) {
                lastDoc = currentNode.getDocument();
                sizeHint = nodes.getSizeHint(lastDoc);
            }
            ContextItem contextItem = currentNode.getContext();
            if (contextItem == null) {
                throw new XPathException(this,
                    "Internal evaluation error: context is missing for node " +
                    currentNode.getNodeId() + " !");
            }
            // TODO : review to consider transverse context
            while (contextItem != null) {
                if (contextItem.getContextId() == getExpressionId()) {
                    final NodeProxy next = contextItem.getNode();
                    if (contextIsVirtual || contextSet.contains(next)) {
                        next.addMatches(currentNode);
                        result.add(next, sizeHint);
                    }
                }
                contextItem = contextItem.getNextDirect();
            }
        }
View Full Code Here

            throws XPathException {
        if (outerSequence != null && !outerSequence.isEmpty()
                && Type.subTypeOf(contextSequence.getItemType(), Type.NODE)
                && contextSequence.isPersistentSet()
                && outerSequence.isPersistentSet()) {
            final Sequence result = new NewArrayNodeSet(100);
            final NodeSet contextSet = contextSequence.toNodeSet();
            switch (mode) {
            case Constants.CHILD_AXIS:
            case Constants.ATTRIBUTE_AXIS:
            case Constants.DESCENDANT_AXIS:
            case Constants.DESCENDANT_SELF_AXIS:
            case Constants.DESCENDANT_ATTRIBUTE_AXIS: {
                final NodeSet outerNodeSet = outerSequence.toNodeSet();
                // TODO: in some cases, especially with in-memory nodes,
                // outerSequence.toNodeSet() will generate a document
                // which will be different from the one(s) in contextSet
                // ancestors will thus be empty :-(
                // A special treatment of VirtualNodeSet does not seem to be
                // required anymore
                final Sequence ancestors = outerNodeSet.selectAncestors(contextSet,
                        true, getExpressionId());
                if (contextSet.getDocumentSet().intersection(
                        outerNodeSet.getDocumentSet()).getDocumentCount() == 0)
                        {LOG.info("contextSet and outerNodeSet don't share any document");}
                final NewArrayNodeSet temp = new NewArrayNodeSet(100);
                for (final SequenceIterator i = ancestors.iterate(); i.hasNext();) {
                    NodeProxy p = (NodeProxy) i.nextItem();
                    ContextItem contextNode = p.getContext();
                    temp.reset();
                    while (contextNode != null) {
                        if (contextNode.getContextId() == getExpressionId())
                            {temp.add(contextNode.getNode());}
                        contextNode = contextNode.getNextDirect();
                    }
                    p.clearContext(getExpressionId());
                    // TODO : understand why we sort here...
                    temp.sortInDocumentOrder();
                    for (final SequenceIterator j = innerSeq.iterate(); j.hasNext();) {
                        final NumericValue v = (NumericValue) j.nextItem();
                        // Non integers return... nothing, not even an error !
                        if (!v.hasFractionalPart() && !v.isZero()) {
                            // ... whereas we don't want a sorted array here
                            // TODO : rename this method as getInDocumentOrder ? -pb
                            p = temp.get(v.getInt() - 1);
                            if (p != null) {
                                result.add(p);
                            }
                            // TODO : does null make sense here ? Well... sometimes ;-)
                        }
                    }
                }
                break;
            }
            default:
                for (final SequenceIterator i = outerSequence.iterate(); i.hasNext();) {
                    NodeProxy p = (NodeProxy) i.nextItem();
                    Sequence temp;
                    boolean reverseAxis = true;
                    switch (mode) {
                    case Constants.ANCESTOR_AXIS:
                        temp = contextSet.selectAncestors(p, false, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.ANCESTOR_SELF_AXIS:
                        temp = contextSet.selectAncestors(p, true, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.PARENT_AXIS:
                        // TODO : understand why the contextSet is not involved
                        // here
                        // NodeProxy.getParent returns a *theoretical* parent
                        // which is *not* guaranteed to be in the context set !
                        temp = p.getParents(Expression.NO_CONTEXT_ID);
                        break;
                    case Constants.PRECEDING_AXIS:
                        temp = contextSet.selectPreceding(p, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.PRECEDING_SIBLING_AXIS:
                        temp = contextSet.selectPrecedingSiblings(p, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.FOLLOWING_SIBLING_AXIS:
                        temp = contextSet.selectFollowingSiblings(p, Expression.IGNORE_CONTEXT);
                        reverseAxis = false;
                        break;
                    case Constants.FOLLOWING_AXIS:
                        temp = contextSet.selectFollowing(p, Expression.IGNORE_CONTEXT);
                        reverseAxis = false;
                        break;
                    case Constants.SELF_AXIS:
                        temp = p;
                        reverseAxis = false;
                        break;
                    default:
                        throw new IllegalArgumentException("Tried to test unknown axis");
                    }
                    if (!temp.isEmpty()) {
                        for (final SequenceIterator j = innerSeq.iterate(); j.hasNext();) {
                            final NumericValue v = (NumericValue) j.nextItem();
                            // Non integers return... nothing, not even an error !
                            if (!v.hasFractionalPart() && !v.isZero()) {
                                final int pos = (reverseAxis ?
                                    temp.getItemCount() - v.getInt() : v.getInt() - 1);
                                // Other positions are ignored
                                if (pos >= 0 && pos < temp.getItemCount()) {
                                    final NodeProxy t = (NodeProxy) temp.itemAt(pos);
                                    // for the current context: filter out those
                                    // context items not selected by the positional predicate
                                    ContextItem ctx = t.getContext();
                                    t.clearContext(Expression.IGNORE_CONTEXT);
                                    while (ctx != null) {
View Full Code Here

      throws XPathException {
    final NodeSet nodes = args[0].toNodeSet();
    if (nodes.isEmpty())
      {return Sequence.EMPTY_SEQUENCE;}
   
    final NodeSet result = new NewArrayNodeSet();
    final DateTimeValue dtv = (DateTimeValue) args[1].itemAt(0);
    final long lastModified = dtv.getDate().getTime();
   
    for (final NodeSetIterator i = nodes.iterator(); i.hasNext(); ) {
      final NodeProxy proxy = i.next();
      final DocumentImpl doc = proxy.getDocument();
      final long modified = doc.getMetadata().getLastModified();
      if (modified > lastModified)
        {result.add(proxy);}
    }
    return result;
  }
View Full Code Here

TOP

Related Classes of org.exist.dom.NewArrayNodeSet

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.