Package org.exist.numbering

Examples of org.exist.numbering.NodeId


        final FindDescendantsCallback callback = new FindDescendantsCallback(type, axis, contextId, result, parent);
        try {
            lock.acquire(Lock.READ_LOCK);
            for (final NodeProxy ancestor : contextSet) {
                final DocumentImpl doc = ancestor.getDocument();
                final NodeId ancestorId = ancestor.getNodeId();
                callback.setAncestor(doc, ancestor);
                byte[] fromKey, toKey;
                if (ancestorId == NodeId.DOCUMENT_NODE) {
                    fromKey = computeKey(type, qname, doc.getDocId());
                    toKey = computeKey(type, qname, doc.getDocId() + 1);
                } else {
                    fromKey = computeKey(type, qname, doc.getDocId(), ancestorId);
                    toKey = computeKey(type, qname, doc.getDocId(), ancestorId.nextSibling());
                }
                final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
                try {
                    index.btree.query(query, callback);
                } catch (final Exception e) {
View Full Code Here


        final Lock lock = index.btree.getLock();
        final NewArrayNodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 256);
        try {
            lock.acquire(Lock.READ_LOCK);
            for (final NodeProxy descendant : contextSet) {
                NodeId parentId;
                if (axis == Constants.ANCESTOR_SELF_AXIS || axis == Constants.SELF_AXIS)
                    {parentId = descendant.getNodeId();}
                else
                    {parentId = descendant.getNodeId().getParentId();}
                final DocumentImpl doc = descendant.getDocument();
                while (parentId != NodeId.DOCUMENT_NODE) {
                    final byte[] key = computeKey(type, qname, doc.getDocId(), parentId);
                    final long address = index.btree.findValue(new Value(key));
                    if (address != -1) {
                        final NodeProxy storedNode = new NodeProxy(doc, parentId,
                            type == ElementValue.ATTRIBUTE ? Node.ATTRIBUTE_NODE : Node.ELEMENT_NODE, address);
                        result.add(storedNode);
                        if (Expression.NO_CONTEXT_ID != contextId) {
                            storedNode.deepCopyContext(descendant, contextId);
                        } else
                            {storedNode.copyContext(descendant);}
                        if (contextSet.getTrackMatches())
                          {storedNode.addMatches(descendant);}
                    }
                    // stop after first iteration if we are on the self axis
                    if (axis == Constants.SELF_AXIS || axis == Constants.PARENT_AXIS)
                        {break;}
                    // continue with the parent of the parent
                    parentId = parentId.getParentId();
                }
            }
        } catch (final LockException e) {
            NativeStructuralIndex.LOG.warn("Lock problem while searching structural index: " + e.getMessage(), e);
        } catch (final Exception e) {
View Full Code Here

        final Lock lock = index.btree.getLock();
        final NewArrayNodeSet result = new NewArrayNodeSet(docs.getDocumentCount(), 256);
        final FindDescendantsCallback callback = new FindDescendantsCallback(type, axis, contextId, useSelfAsContext, result, null);
        for (final NodeProxy ancestor : contextSet) {
            final DocumentImpl doc = ancestor.getDocument();
            final NodeId ancestorId = ancestor.getNodeId();
            final List<QName> qnames = getQNamesForDoc(doc);
            try {
              lock.acquire(Lock.READ_LOCK);
              for (final QName qname : qnames) {
                if (test.getName() == null || test.matches(qname)) {
                  callback.setAncestor(doc, ancestor);
                  byte[] fromKey, toKey;
                      if (ancestorId == NodeId.DOCUMENT_NODE) {
                          fromKey = computeKey(type, qname, doc.getDocId());
                          toKey = computeKey(type, qname, doc.getDocId() + 1);
                      } else {
                          fromKey = computeKey(type, qname, doc.getDocId(), ancestorId);
                          toKey = computeKey(type, qname, doc.getDocId(), ancestorId.nextSibling());
                      }
                      final IndexQuery query = new IndexQuery(IndexQuery.RANGE, new Value(fromKey), new Value(toKey));
                      try {
                          index.btree.query(query, callback);
                      } catch (final Exception e) {
View Full Code Here

                final QName qname = entry.getKey();
                try {
                    lock.acquire(Lock.WRITE_LOCK);
                    final List<NodeProxy> nodes = entry.getValue();
                    for (final NodeProxy proxy : nodes) {
                        final NodeId nodeId = proxy.getNodeId();
                        final byte[] key = computeKey(qname.getNameType(), qname, document.getDocId(), nodeId);
                        index.btree.removeValue(new Value(key));
                    }
                } catch (final LockException e) {
                    NativeStructuralIndex.LOG.warn("Failed to lock structural index: " + e.getMessage(), e);
View Full Code Here

                final QName qname = entry.getKey();
                try {
                    lock.acquire(Lock.WRITE_LOCK);
                    final List<NodeProxy> nodes = entry.getValue();
                    for (final NodeProxy proxy : nodes) {
                        final NodeId nodeId = proxy.getNodeId();
                        final byte[] key = computeKey(qname.getNameType(), qname, document.getDocId(), nodeId);
                        index.btree.addValue(new Value(key), computeValue(proxy));
                    }
                    final Value docKey = new Value(computeDocKey(qname.getNameType(), document.getDocId(), qname));
                    if (index.btree.findValue(docKey) == -1) {
View Full Code Here

                        //That might happen during recovery runs : TODO, investigate
                        if (owner == null) {
                            buf.append("(Can't read data, owner is null)");
                        } else {
                            try {
                                final NodeId nodeId = ((NativeBroker)owner).getBrokerPool()
                                    .getNodeFactory().createFromData(dlnLen, page.data, readOffset);
                                readOffset += nodeId.size();
                                buf.append("(" + nodeId.toString() + ")");
                                final short attributes = ByteConversion.byteToShort(page.data, readOffset);
                                buf.append(" children: " + children);
                                buf.append(" attributes: " + attributes);
                            } catch (final Exception e) {
                                //TODO : more friendly message. Provide the array of bytes ?
                                buf.append("(Unable to read the node ID at: " + readOffset);
                                buf.append(" children : " + children);
                                //Probably a wrong offset so... don't read it
                                buf.append(" attributes : unknown");
                            }
                        }
                        break;
                    }
                    case Node.TEXT_NODE:
                    case Node.CDATA_SECTION_NODE:
                    {
                        if (Signatures.getType(page.data[pos]) == Node.TEXT_NODE)
                            {buf.append("text ");}
                        else
                            {buf.append("CDATA ");}
                        int readOffset = pos;
                        readOffset += 1;
                        final int dlnLen = ByteConversion.byteToShort(page.data, readOffset);
                        readOffset += NodeId.LENGTH_NODE_ID_UNITS;
                        //That might happen during recovery runs : TODO, investigate
                        if (owner == null) {
                            buf.append("(Can't read data, owner is null)");
                        } else {
                            try {
                                final NodeId nodeId = ((NativeBroker)owner).getBrokerPool()
                                    .getNodeFactory().createFromData(dlnLen, page.data, readOffset);
                                readOffset += nodeId.size();
                                buf.append("(" + nodeId.toString() + ")");
                                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                                os.write(page.data, readOffset, valueLength - (readOffset - pos));

                                String value = new String(os.toByteArray(),UTF_8);
                                if (value.length() > 15) {
                                    value = value.substring(0,8) + "..." + value.substring(value.length() - 8);
                                }

                                buf.append(":'" + value + "'");
                            } catch (final Exception e) {
                                //TODO : more friendly message. Provide the array of bytes ?
                                buf.append("(unable to read the node ID at : " + readOffset);
                            }
                        }
                        break;
                    }
                    case Node.ATTRIBUTE_NODE:
                    {
                        buf.append("[");
                        buf.append("attribute ");
                        int readOffset = pos;
                        final byte idSizeType = (byte) (page.data[readOffset] & 0x3);
                        final boolean hasNamespace = (page.data[readOffset] & 0x10) == 0x10;
                        readOffset += 1;
                        final int dlnLen = ByteConversion.byteToShort(page.data, readOffset);
                        readOffset += NodeId.LENGTH_NODE_ID_UNITS;
                        //That might happen during recovery runs : TODO, investigate
                        if (owner == null) {
                            buf.append("(can't read data, owner is null)");
                        } else {
                            try {
                                final NodeId nodeId = ((NativeBroker)owner).getBrokerPool()
                                    .getNodeFactory().createFromData(dlnLen, page.data, readOffset);
                                readOffset += nodeId.size();
                                buf.append("(" + nodeId.toString() + ")");
                                readOffset += Signatures.getLength(idSizeType);
                                if (hasNamespace) {
                                    //Untested
                                    final short NSId = ByteConversion.byteToShort(page.data, readOffset);
                                    readOffset += AttrImpl.LENGTH_NS_ID;
View Full Code Here

        // first try to find the node in the index
        final long pointer = findValue(nodeRef);
        if (pointer == KEY_NOT_FOUND) {
            // node not found in index: try to find the nearest available
            // ancestor and traverse it
            NodeId nodeID = node.getNodeId();
            long parentPointer = KEY_NOT_FOUND;
            do {
                nodeID = nodeID.getParentId();
                if (nodeID == null) {
                    SanityCheck.TRACE("Node " + node.getDocument().getDocId() + ":" +
                        nodeID + " not found.");
                    throw new BTreeException("Node " + nodeID + " not found.");
                }
                if (nodeID == NodeId.DOCUMENT_NODE) {
                    SanityCheck.TRACE("Node " + node.getDocument().getDocId() + ":" +
                            nodeID + " not found.");
                    throw new BTreeException("Node " + nodeID + " not found.");
                }
                final NativeBroker.NodeRef parentRef = new NativeBroker.NodeRef(doc.getDocId(), nodeID);
                try {
                    parentPointer = findValue(parentRef);
                } catch (final BTreeException bte) {
                    LOG.error("report me", bte);
                }
            } while (parentPointer == KEY_NOT_FOUND);
            try {
                final NodeProxy parent = new NodeProxy(doc, nodeID, parentPointer);
                final EmbeddedXMLStreamReader cursor = broker.getXMLStreamReader(parent, true);
                while(cursor.hasNext()) {
                    final int status = cursor.next();
                    if (status != XMLStreamReader.END_ELEMENT) {
                        final NodeId nextId = (NodeId) cursor.getProperty(EmbeddedXMLStreamReader.PROPERTY_NODE_ID);
                        if (nextId.equals(node.getNodeId())) {
                            return cursor.getCurrentPosition();
                        }
                    }
                }
                if (LOG.isDebugEnabled())
View Full Code Here

                        //Exit if the document is not concerned
                        if (storedDocument == null) {
                            is.skipBytes(length);
                            continue;
                        }
                        NodeId previous = null;
                        for (int m = 0; m < termCount; m++) {
                            NodeId nodeId = broker.getBrokerPool().getNodeFactory().createFromStream(previous, is);
                            previous = nodeId;
                            final int freq = is.readInt();
                            NodeProxy storedNode;
                            switch (storedSection) {
                            case TEXT_SECTION :
View Full Code Here

                    //Exit if the document is not concerned
                    if (storedDocument == null) {
                        is.skipBytes(length);
                        continue;
                    }
                    NodeId previous = null;
                    for (int m = 0; m < termCount; m++) {
                        NodeId nodeId = broker.getBrokerPool().getNodeFactory()
                            .createFromStream(previous, is);
                        previous = nodeId;
                        final int freq = is.readInt();
                        is.skip(freq);
                        if (contextSet != null) {
View Full Code Here

                    if (storedDocument == null) {
                        is.skipBytes(length);
                        continue;
                    }
                    //Process the nodes
                    NodeId previous = null;
                    for (int m = 0; m < gidsCount; m++) {
                        NodeId nodeId = broker.getBrokerPool().getNodeFactory().createFromStream(previous, is);
                        previous = nodeId;
                        final int freq = is.readInt();
                        NodeProxy storedNode;
                        switch (storedSection) {
                        case ATTRIBUTE_SECTION :
View Full Code Here

TOP

Related Classes of org.exist.numbering.NodeId

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.