Search in sources :

Example 1 with ValueNode

use of org.sirix.node.interfaces.ValueNode in project sirix by sirixdb.

the class CASIndexListener method listen.

@Override
public void listen(final ChangeType type, final ImmutableNode node, final long pathNodeKey) throws SirixIOException {
    if (node instanceof ValueNode) {
        final ValueNode valueNode = ((ValueNode) node);
        mPathSummaryReader.moveTo(pathNodeKey);
        try {
            switch(type) {
                case INSERT:
                    if (mPathSummaryReader.getPCRsForPaths(mPaths).contains(pathNodeKey)) {
                        insert(valueNode, pathNodeKey);
                    }
                    break;
                case DELETE:
                    if (mPathSummaryReader.getPCRsForPaths(mPaths).contains(pathNodeKey)) {
                        mAVLTreeWriter.remove(new CASValue(new Str(valueNode.getValue()), mType, pathNodeKey), node.getNodeKey());
                    }
                    break;
                default:
            }
        } catch (final PathException e) {
            throw new SirixIOException(e);
        }
    }
}
Also used : Str(org.brackit.xquery.atomic.Str) PathException(org.brackit.xquery.util.path.PathException) CASValue(org.sirix.index.avltree.keyvalue.CASValue) ValueNode(org.sirix.node.interfaces.ValueNode) SirixIOException(org.sirix.exception.SirixIOException)

Example 2 with ValueNode

use of org.sirix.node.interfaces.ValueNode in project sirix by sirixdb.

the class XPathParser method parsePITest.

/**
 * Parses the the rule PITest according to the following production rule:
 * <p>
 * [58] PITest ::= <"processing-instruction" "("> (NCName | StringLiteral)? ")" .
 * </p>
 *
 * @return filter
 */
private Filter parsePITest() {
    consume("processing-instruction", true);
    consume(TokenType.OPEN_BR, true);
    Filter filter = new PIFilter(getTransaction());
    if (!is(TokenType.CLOSE_BR, true)) {
        String stringLiteral;
        if (isQuote()) {
            final byte[] param = ((ValueNode) getTransaction().getItemList().getItem(parseStringLiteral()).get()).getRawValue();
            stringLiteral = Arrays.toString(param);
        } else {
            stringLiteral = parseNCName();
        }
        consume(TokenType.CLOSE_BR, true);
        filter = new NestedFilter(getTransaction(), filter, new NameFilter(getTransaction(), stringLiteral));
    }
    return filter;
}
Also used : NestedFilter(org.sirix.axis.filter.NestedFilter) NameFilter(org.sirix.axis.filter.NameFilter) PIFilter(org.sirix.axis.filter.PIFilter) ItemFilter(org.sirix.axis.filter.ItemFilter) AttributeFilter(org.sirix.axis.filter.AttributeFilter) NameFilter(org.sirix.axis.filter.NameFilter) TypeFilter(org.sirix.axis.filter.TypeFilter) NestedFilter(org.sirix.axis.filter.NestedFilter) DocumentRootNodeFilter(org.sirix.axis.filter.DocumentRootNodeFilter) CommentFilter(org.sirix.axis.filter.CommentFilter) WildcardFilter(org.sirix.axis.filter.WildcardFilter) PIFilter(org.sirix.axis.filter.PIFilter) SchemaElementFilter(org.sirix.service.xml.xpath.filter.SchemaElementFilter) Filter(org.sirix.api.Filter) SchemaAttributeFilter(org.sirix.service.xml.xpath.filter.SchemaAttributeFilter) TextFilter(org.sirix.axis.filter.TextFilter) ElementFilter(org.sirix.axis.filter.ElementFilter) NodeFilter(org.sirix.axis.filter.NodeFilter) ValueNode(org.sirix.node.interfaces.ValueNode)

Example 3 with ValueNode

use of org.sirix.node.interfaces.ValueNode in project sirix by sirixdb.

the class XdmNodeWriterTrxImpl method adaptSubtreeForMove.

/**
 * Adapt subtree regarding the index-structures.
 *
 * @param toMove node which is moved (either before the move, or after the move)
 * @param type the type of change (either deleted from the old position or inserted into the new
 *        position)
 * @throws SirixIOException if an I/O exception occurs
 */
private void adaptSubtreeForMove(final Node node, final ChangeType type) throws SirixIOException {
    assert type != null;
    final long beforeNodeKey = getNode().getNodeKey();
    moveTo(node.getNodeKey());
    final Axis axis = new DescendantAxis(this, IncludeSelf.YES);
    while (axis.hasNext()) {
        axis.next();
        for (int i = 0, attCount = getAttributeCount(); i < attCount; i++) {
            moveToAttribute(i);
            final ImmutableAttribute att = (ImmutableAttribute) getNode();
            mIndexController.notifyChange(type, att, att.getPathNodeKey());
            moveToParent();
        }
        for (int i = 0, nspCount = getNamespaceCount(); i < nspCount; i++) {
            moveToAttribute(i);
            final ImmutableNamespace nsp = (ImmutableNamespace) getNode();
            mIndexController.notifyChange(type, nsp, nsp.getPathNodeKey());
            moveToParent();
        }
        long pathNodeKey = -1;
        if (getNode() instanceof ValueNode && getNode().getParentKey() != Fixed.DOCUMENT_NODE_KEY.getStandardProperty()) {
            final long nodeKey = getNode().getNodeKey();
            pathNodeKey = moveToParent().get().getNameNode().getPathNodeKey();
            moveTo(nodeKey);
        } else if (getNode() instanceof NameNode) {
            pathNodeKey = getNameNode().getPathNodeKey();
        }
        mIndexController.notifyChange(type, getNode(), pathNodeKey);
    }
    moveTo(beforeNodeKey);
}
Also used : NameNode(org.sirix.node.interfaces.NameNode) ValueNode(org.sirix.node.interfaces.ValueNode) ImmutableNamespace(org.sirix.node.immutable.ImmutableNamespace) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) LevelOrderAxis(org.sirix.axis.LevelOrderAxis) PostOrderAxis(org.sirix.axis.PostOrderAxis) DescendantAxis(org.sirix.axis.DescendantAxis) ImmutableAttribute(org.sirix.node.immutable.ImmutableAttribute)

Example 4 with ValueNode

use of org.sirix.node.interfaces.ValueNode in project sirix by sirixdb.

the class XdmNodeWriterTrxImpl method setValue.

@Override
public XdmNodeWriteTrx setValue(final String value) throws SirixException {
    checkNotNull(value);
    acquireLock();
    try {
        if (getCurrentNode() instanceof ValueNode) {
            checkAccessAndCommit();
            // XDM).
            if (value.isEmpty()) {
                remove();
                return this;
            }
            // Remove old value from indexes.
            mIndexController.notifyChange(ChangeType.DELETE, getNode(), getPathNodeKey());
            final long oldHash = mNodeReader.getCurrentNode().hashCode();
            final byte[] byteVal = getBytes(value);
            final ValueNode node = (ValueNode) getPageTransaction().prepareEntryForModification(mNodeReader.getCurrentNode().getNodeKey(), PageKind.RECORDPAGE, -1, Optional.<UnorderedKeyValuePage>empty());
            node.setValue(byteVal);
            mNodeReader.setCurrentNode(node);
            adaptHashedWithUpdate(oldHash);
            // Index new value.
            mIndexController.notifyChange(ChangeType.INSERT, getNode(), getPathNodeKey());
            return this;
        } else {
            throw new SirixUsageException("setValue(String) is not allowed if current node is not an IValNode implementation!");
        }
    } finally {
        unLock();
    }
}
Also used : ValueNode(org.sirix.node.interfaces.ValueNode) UnorderedKeyValuePage(org.sirix.page.UnorderedKeyValuePage) SirixUsageException(org.sirix.exception.SirixUsageException)

Aggregations

ValueNode (org.sirix.node.interfaces.ValueNode)4 Str (org.brackit.xquery.atomic.Str)1 PathException (org.brackit.xquery.util.path.PathException)1 Axis (org.sirix.api.Axis)1 Filter (org.sirix.api.Filter)1 DescendantAxis (org.sirix.axis.DescendantAxis)1 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)1 PostOrderAxis (org.sirix.axis.PostOrderAxis)1 AttributeFilter (org.sirix.axis.filter.AttributeFilter)1 CommentFilter (org.sirix.axis.filter.CommentFilter)1 DocumentRootNodeFilter (org.sirix.axis.filter.DocumentRootNodeFilter)1 ElementFilter (org.sirix.axis.filter.ElementFilter)1 ItemFilter (org.sirix.axis.filter.ItemFilter)1 NameFilter (org.sirix.axis.filter.NameFilter)1 NestedFilter (org.sirix.axis.filter.NestedFilter)1 NodeFilter (org.sirix.axis.filter.NodeFilter)1 PIFilter (org.sirix.axis.filter.PIFilter)1 TextFilter (org.sirix.axis.filter.TextFilter)1 TypeFilter (org.sirix.axis.filter.TypeFilter)1 WildcardFilter (org.sirix.axis.filter.WildcardFilter)1