Search in sources :

Example 11 with DescendantAxis

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

the class UpdateTest method testThirdMoveToFirstChild.

@Test
public void testThirdMoveToFirstChild() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveTo(5);
    wtx.moveSubtreeToFirstChild(11);
    testThirdMoveToFirstChild(wtx);
    wtx.commit();
    testThirdMoveToFirstChild(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testThirdMoveToFirstChild(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.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.2.3")).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.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 12 with DescendantAxis

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

the class UpdateTest method testFirstMoveToFirstChild.

@Test
public void testFirstMoveToFirstChild() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveTo(7);
    wtx.moveSubtreeToFirstChild(6);
    testFirstMoveToFirstChild(wtx);
    wtx.commit();
    testFirstMoveToFirstChild(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testFirstMoveToFirstChild(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.3")).add(new SirixDeweyID("1.3.5")).add(new SirixDeweyID("1.3.5.5")).add(new SirixDeweyID("1.3.5.5.3")).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 13 with DescendantAxis

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

the class UpdateTest method testFirstMoveSubtreeToRightSibling.

@Test
public void testFirstMoveSubtreeToRightSibling() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveToDocumentRoot();
    for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
        System.out.println(nodeKey + ": " + wtx.getDeweyID());
    }
    wtx.moveTo(7);
    wtx.moveSubtreeToRightSibling(6);
    testFirstMoveSubtreeToRightSibling(wtx);
    wtx.moveToDocumentRoot();
    for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
        System.out.println(nodeKey + ": " + wtx.getDeweyID());
    }
    wtx.commit();
    wtx.moveToDocumentRoot();
    for (final long nodeKey : new NonStructuralWrapperAxis(new DescendantAxis(wtx, IncludeSelf.YES))) {
        System.out.println(nodeKey + ": " + wtx.getDeweyID());
    }
    testFirstMoveSubtreeToRightSibling(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testFirstMoveSubtreeToRightSibling(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.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.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 14 with DescendantAxis

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

the class XPathParser method parsePathExpr.

/**
 * Parses the the rule PathExpr according to the following production rule:
 * <p>
 * [25] PathExpr ::= ("/" RelativePathExpr?) | ("//" RelativePathExpr) | RelativePathExpr .
 * </p>
 *
 * @throws SirixXPathException
 */
private void parsePathExpr() throws SirixXPathException {
    if (is(TokenType.SLASH, true)) {
        // path expression starts from the root
        mPipeBuilder.addStep(new DocumentNodeAxis(getTransaction()));
        final TokenType type = mToken.getType();
        if (type != TokenType.END && type != TokenType.COMMA) {
            // all immediately following keywords or '*' are nametests, not
            // operators
            // leading-lone-slash constrain
            parseRelativePathExpr();
        }
    } else if (is(TokenType.DESC_STEP, true)) {
        // path expression starts from the root with a descendant-or-self
        // step
        mPipeBuilder.addStep(new DocumentNodeAxis(getTransaction()));
        final Axis mAxis = new DescendantAxis(getTransaction(), IncludeSelf.YES);
        mPipeBuilder.addStep(mAxis);
        parseRelativePathExpr();
    } else {
        parseRelativePathExpr();
    }
}
Also used : DocumentNodeAxis(org.sirix.service.xml.xpath.filter.DocumentNodeAxis) DescendantAxis(org.sirix.axis.DescendantAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) Axis(org.sirix.api.Axis) DocumentNodeAxis(org.sirix.service.xml.xpath.filter.DocumentNodeAxis) FollowingAxis(org.sirix.axis.FollowingAxis) AbstractAxis(org.sirix.axis.AbstractAxis) AncestorAxis(org.sirix.axis.AncestorAxis) ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) SelfAxis(org.sirix.axis.SelfAxis) DescendantAxis(org.sirix.axis.DescendantAxis) ParentAxis(org.sirix.axis.ParentAxis) AttributeAxis(org.sirix.axis.AttributeAxis) PrecedingSiblingAxis(org.sirix.axis.PrecedingSiblingAxis)

Example 15 with DescendantAxis

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

the class XPathParser method parseForwardAxis.

/**
 * Parses the the rule ForwardAxis according to the following production rule:
 * <p>
 * [30] ForwardAxis ::= <"child" "::"> | <"descendant" "::"> | <"attribute" "::"> | <"self" "::">
 * | <"descendant-or-self" "::"> | <"following-sibling" "::"> | <"following" "::"> | <"namespace"
 * "::"> .
 * </p>
 *
 * @return axis
 * @throws SirixXPathException
 */
private Axis parseForwardAxis() throws SirixXPathException {
    final Axis axis;
    if (is("child", true)) {
        axis = new ChildAxis(getTransaction());
    } else if (is("descendant", true)) {
        axis = new DescendantAxis(getTransaction());
    } else if (is("descendant-or-self", true)) {
        axis = new DescendantAxis(getTransaction(), IncludeSelf.YES);
    } else if (is("attribute", true)) {
        axis = new AttributeAxis(getTransaction());
    } else if (is("self", true)) {
        axis = new SelfAxis(getTransaction());
    } else if (is("following", true)) {
        axis = new FollowingAxis(getTransaction());
    } else if (is("following-sibling", true)) {
        axis = new FollowingSiblingAxis(getTransaction());
    } else {
        is("namespace", true);
        throw EXPathError.XPST0010.getEncapsulatedException();
    }
    consume(TokenType.COLON, true);
    consume(TokenType.COLON, true);
    return axis;
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) SelfAxis(org.sirix.axis.SelfAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) FollowingAxis(org.sirix.axis.FollowingAxis) AttributeAxis(org.sirix.axis.AttributeAxis) DescendantAxis(org.sirix.axis.DescendantAxis) PrecedingAxis(org.sirix.axis.PrecedingAxis) Axis(org.sirix.api.Axis) DocumentNodeAxis(org.sirix.service.xml.xpath.filter.DocumentNodeAxis) FollowingAxis(org.sirix.axis.FollowingAxis) AbstractAxis(org.sirix.axis.AbstractAxis) AncestorAxis(org.sirix.axis.AncestorAxis) ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) FilterAxis(org.sirix.axis.filter.FilterAxis) SelfAxis(org.sirix.axis.SelfAxis) DescendantAxis(org.sirix.axis.DescendantAxis) ParentAxis(org.sirix.axis.ParentAxis) AttributeAxis(org.sirix.axis.AttributeAxis) PrecedingSiblingAxis(org.sirix.axis.PrecedingSiblingAxis)

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