Search in sources :

Example 6 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class IndexBuilder method build.

/**
 * Build the index.
 *
 * @param rtx the current {@link XdmNodeReadTrx}
 * @param builders the index builders
 */
public static void build(final XdmNodeReadTrx rtx, final Set<Visitor> builders) {
    final long nodeKey = rtx.getNodeKey();
    rtx.moveToDocumentRoot();
    for (@SuppressWarnings("unused") final long key : new NonStructuralWrapperAxis(new DescendantAxis(rtx))) {
        for (final Visitor builder : builders) {
            rtx.acceptVisitor(builder);
        }
    }
    rtx.moveTo(nodeKey);
}
Also used : Visitor(org.sirix.api.visitor.Visitor) NonStructuralWrapperAxis(org.sirix.axis.NonStructuralWrapperAxis) DescendantAxis(org.sirix.axis.DescendantAxis)

Example 7 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class DocumentWrapper method selectID.

@Override
public NodeInfo selectID(final String ID, final boolean getParent) {
    try {
        final NodeReadTrx rtx = mSession.beginNodeReadTrx();
        final Axis axis = new DescendantAxis(rtx, IncludeSelf.YES);
        while (axis.hasNext()) {
            if (rtx.getKind() == Kind.ELEMENT) {
                final int attCount = rtx.getAttributeCount();
                if (attCount > 0) {
                    final long nodeKey = rtx.getNodeKey();
                    for (int index = 0; index < attCount; index++) {
                        rtx.moveToAttribute(index);
                        if ("xml:id".equalsIgnoreCase(rtx.getName().getLocalName()) && ID.equals(rtx.getValue())) {
                            if (getParent) {
                                rtx.moveToParent();
                            }
                            return new NodeWrapper(this, rtx.getNodeKey());
                        }
                        rtx.moveTo(nodeKey);
                    }
                }
            }
            axis.next();
        }
        rtx.close();
    } catch (final SirixException e) {
        LOGWRAPPER.error(e.getMessage(), e);
    }
    return null;
}
Also used : NodeReadTrx(org.sirix.api.NodeReadTrx) SirixException(org.sirix.exception.SirixException) DescendantAxis(org.sirix.axis.DescendantAxis) Axis(org.sirix.api.Axis) DescendantAxis(org.sirix.axis.DescendantAxis)

Example 8 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class DBNode method expandString.

/**
 * Filter text nodes.
 *
 * @return concatenated String of text node values
 */
private String expandString() {
    final StringBuilder buffer = new StringBuilder();
    final Axis axis = new DescendantAxis(mRtx);
    while (axis.hasNext()) {
        axis.next();
        if (mRtx.isText()) {
            buffer.append(mRtx.getValue());
        }
    }
    return buffer.toString();
}
Also used : DescendantAxis(org.sirix.axis.DescendantAxis) AllTimeAxis(org.sirix.axis.temporal.AllTimeAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) Axis(org.sirix.api.Axis) FirstAxis(org.sirix.axis.temporal.FirstAxis) AbstractTemporalAxis(org.sirix.axis.AbstractTemporalAxis) ChildAxis(org.sirix.axis.ChildAxis) LastAxis(org.sirix.axis.temporal.LastAxis) AttributeAxis(org.sirix.axis.AttributeAxis) PastAxis(org.sirix.axis.temporal.PastAxis) FollowingAxis(org.sirix.axis.FollowingAxis) AncestorAxis(org.sirix.axis.AncestorAxis) FutureAxis(org.sirix.axis.temporal.FutureAxis) NonStructuralWrapperAxis(org.sirix.axis.NonStructuralWrapperAxis) NextAxis(org.sirix.axis.temporal.NextAxis) PreviousAxis(org.sirix.axis.temporal.PreviousAxis) DescendantAxis(org.sirix.axis.DescendantAxis)

Example 9 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class UpdateTest method testSecondMoveToFirstChild.

@Test
public void testSecondMoveToFirstChild() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveTo(5);
    wtx.moveSubtreeToFirstChild(4);
    testSecondMoveToFirstChild(wtx);
    wtx.commit();
    testSecondMoveToFirstChild(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testSecondMoveToFirstChild(rtx);
    rtx.moveToDocumentRoot();
    final Builder<SirixDeweyID> builder = ImmutableSet.<SirixDeweyID>builder();
    final ImmutableSet<SirixDeweyID> ids = builder.add(new SirixDeweyID("1")).add(new SirixDeweyID("1.3")).add(new SirixDeweyID("1.3.0.3")).add(new SirixDeweyID("1.3.1.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.3")).add(new SirixDeweyID("1.3.5.5")).add(new SirixDeweyID("1.3.7")).add(new SirixDeweyID("1.3.9")).add(new SirixDeweyID("1.3.9.1.3")).add(new SirixDeweyID("1.3.9.3")).add(new SirixDeweyID("1.3.9.5")).add(new SirixDeweyID("1.3.11")).build();
    test(ids.iterator(), new NonStructuralWrapperAxis(new DescendantAxis(rtx, IncludeSelf.YES)));
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) NonStructuralWrapperAxis(org.sirix.axis.NonStructuralWrapperAxis) SirixDeweyID(org.sirix.node.SirixDeweyID) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 10 with DescendantAxis

use of org.sirix.axis.DescendantAxis in project sirix by sirixdb.

the class UpdateTest method testSecondMoveSubtreeToRightSibling.

@Test
public void testSecondMoveSubtreeToRightSibling() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveTo(9);
    wtx.moveSubtreeToRightSibling(5);
    // wtx.moveTo(5);
    // wtx.moveSubtreeToRightSibling(4);
    testSecondMoveSubtreeToRightSibling(wtx);
    wtx.commit();
    testSecondMoveSubtreeToRightSibling(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testSecondMoveSubtreeToRightSibling(rtx);
    rtx.moveToDocumentRoot();
    final Builder<SirixDeweyID> builder = ImmutableSet.<SirixDeweyID>builder();
    builder.add(new SirixDeweyID("1")).add(new SirixDeweyID("1.3")).add(new SirixDeweyID("1.3.0.3")).add(new SirixDeweyID("1.3.1.3")).add(new SirixDeweyID("1.3.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.5")).add(new SirixDeweyID("1.3.5.7")).add(new SirixDeweyID("1.3.7")).add(new SirixDeweyID("1.3.9")).add(new SirixDeweyID("1.3.9.1.3")).add(new SirixDeweyID("1.3.9.3")).add(new SirixDeweyID("1.3.9.5")).add(new SirixDeweyID("1.3.11")).build();
    // test(ids.iterator(), new NonStructuralWrapperAxis(new DescendantAxis(rtx,
    // IncludeSelf.YES)));
    rtx.moveToDocumentRoot();
    for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(rtx, IncludeSelf.YES))) {
        System.out.println(nodeKey + ": " + rtx.getDeweyID());
    }
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) NonStructuralWrapperAxis(org.sirix.axis.NonStructuralWrapperAxis) SirixDeweyID(org.sirix.node.SirixDeweyID) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Aggregations

DescendantAxis (org.sirix.axis.DescendantAxis)44 Axis (org.sirix.api.Axis)27 Test (org.junit.Test)18 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)17 FilterAxis (org.sirix.axis.filter.FilterAxis)16 ChildAxis (org.sirix.axis.ChildAxis)14 QNm (org.brackit.xquery.atomic.QNm)7 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)7 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)7 NameFilter (org.sirix.axis.filter.NameFilter)7 NestedAxis (org.sirix.axis.NestedAxis)6 PostOrderAxis (org.sirix.axis.PostOrderAxis)6 PathSummaryReader (org.sirix.index.path.summary.PathSummaryReader)6 AbstractAxis (org.sirix.axis.AbstractAxis)5 AncestorAxis (org.sirix.axis.AncestorAxis)5 FollowingAxis (org.sirix.axis.FollowingAxis)5 FollowingSiblingAxis (org.sirix.axis.FollowingSiblingAxis)5 LevelOrderAxis (org.sirix.axis.LevelOrderAxis)5 ParentAxis (org.sirix.axis.ParentAxis)5 PrecedingAxis (org.sirix.axis.PrecedingAxis)5