Search in sources :

Example 21 with DescendantAxis

use of org.sirix.axis.DescendantAxis 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 22 with DescendantAxis

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

the class XMLShredderTest method testSTAXShredder.

@Test
public void testSTAXShredder() throws Exception {
    // Setup parsed session.
    XMLShredder.main(XML.toAbsolutePath().toString(), PATHS.PATH2.getFile().toAbsolutePath().toString());
    final XdmNodeReadTrx expectedTrx = holder.getWriter();
    // Verify.
    final Database database2 = TestHelper.getDatabase(PATHS.PATH2.getFile());
    database2.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH2.getConfig()).build());
    final ResourceManager manager = database2.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeReadTrx rtx = manager.beginNodeReadTrx();
    rtx.moveToDocumentRoot();
    final Iterator<Long> expectedDescendants = new DescendantAxis(expectedTrx);
    final Iterator<Long> descendants = new DescendantAxis(rtx);
    while (expectedDescendants.hasNext() && descendants.hasNext()) {
        assertEquals(expectedTrx.getNodeKey(), rtx.getNodeKey());
        assertEquals(expectedTrx.getParentKey(), rtx.getParentKey());
        assertEquals(expectedTrx.getFirstChildKey(), rtx.getFirstChildKey());
        assertEquals(expectedTrx.getLeftSiblingKey(), rtx.getLeftSiblingKey());
        assertEquals(expectedTrx.getRightSiblingKey(), rtx.getRightSiblingKey());
        assertEquals(expectedTrx.getChildCount(), rtx.getChildCount());
        if (expectedTrx.getKind() == Kind.ELEMENT || rtx.getKind() == Kind.ELEMENT) {
            assertEquals(expectedTrx.getAttributeCount(), rtx.getAttributeCount());
            assertEquals(expectedTrx.getNamespaceCount(), rtx.getNamespaceCount());
        }
        assertEquals(expectedTrx.getKind(), rtx.getKind());
        assertEquals(expectedTrx.getName(), rtx.getName());
        assertEquals(expectedTrx.getValue(), expectedTrx.getValue());
    }
    rtx.close();
    manager.close();
    database2.close();
    expectedTrx.close();
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 23 with DescendantAxis

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

the class XMLShredderTest method testShredIntoExisting.

@Test
public void testShredIntoExisting() throws Exception {
    final XdmNodeWriteTrx wtx = holder.getWriter();
    final XMLShredder shredder = new XMLShredder.Builder(wtx, XMLShredder.createFileReader(XML), Insert.ASFIRSTCHILD).includeComments(true).commitAfterwards().build();
    shredder.call();
    assertEquals(2, wtx.getRevisionNumber());
    wtx.moveToDocumentRoot();
    wtx.moveToFirstChild();
    wtx.remove();
    final XMLShredder shredder2 = new XMLShredder.Builder(wtx, XMLShredder.createFileReader(XML), Insert.ASFIRSTCHILD).includeComments(true).commitAfterwards().build();
    shredder2.call();
    assertEquals(3, wtx.getRevisionNumber());
    wtx.close();
    // Setup expected session.
    final Database database2 = TestHelper.getDatabase(PATHS.PATH2.getFile());
    final ResourceManager expectedSession = database2.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx expectedTrx = expectedSession.beginNodeWriteTrx();
    DocumentCreater.create(expectedTrx);
    expectedTrx.commit();
    expectedTrx.moveToDocumentRoot();
    // Verify.
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    final Iterator<Long> descendants = new DescendantAxis(rtx);
    final Iterator<Long> expectedDescendants = new DescendantAxis(expectedTrx);
    while (expectedDescendants.hasNext()) {
        expectedDescendants.next();
        descendants.hasNext();
        descendants.next();
        assertEquals(expectedTrx.getName(), rtx.getName());
        assertEquals(expectedTrx.getValue(), rtx.getValue());
    }
    // expectedTrx.moveToDocumentRoot();
    // final Iterator<Long> expectedDescendants2 = new
    // DescendantAxis(expectedTrx);
    // while (expectedDescendants2.hasNext()) {
    // expectedDescendants2.next();
    // descendants.hasNext();
    // descendants.next();
    // assertEquals(expectedTrx.getQNameOfCurrentNode(),
    // rtx.getQNameOfCurrentNode());
    // }
    expectedTrx.close();
    expectedSession.close();
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 24 with DescendantAxis

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

the class XMLShredderTest method testAttributesNSPrefix.

@Test
public void testAttributesNSPrefix() throws Exception {
    // Setup expected session.
    final XdmNodeWriteTrx expectedTrx2 = holder.getWriter();
    DocumentCreater.createWithoutNamespace(expectedTrx2);
    expectedTrx2.commit();
    // Setup parsed session.
    final Database database2 = TestHelper.getDatabase(PATHS.PATH2.getFile());
    final ResourceManager manager2 = database2.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx wtx = manager2.beginNodeWriteTrx();
    final XMLShredder shredder = new XMLShredder.Builder(wtx, XMLShredder.createFileReader(XML2), Insert.ASFIRSTCHILD).commitAfterwards().build();
    shredder.call();
    wtx.commit();
    wtx.close();
    // Verify.
    final XdmNodeReadTrx rtx = manager2.beginNodeReadTrx();
    rtx.moveToDocumentRoot();
    final Iterator<Long> expectedAttributes = new DescendantAxis(expectedTrx2);
    final Iterator<Long> attributes = new DescendantAxis(rtx);
    while (expectedAttributes.hasNext() && attributes.hasNext()) {
        expectedAttributes.next();
        attributes.next();
        if (expectedTrx2.getKind() == Kind.ELEMENT || rtx.getKind() == Kind.ELEMENT) {
            assertEquals(expectedTrx2.getNamespaceCount(), rtx.getNamespaceCount());
            assertEquals(expectedTrx2.getAttributeCount(), rtx.getAttributeCount());
            for (int i = 0; i < expectedTrx2.getAttributeCount(); i++) {
                assertEquals(expectedTrx2.getName(), rtx.getName());
            }
        }
    }
    attributes.hasNext();
    assertEquals(expectedAttributes.hasNext(), attributes.hasNext());
    expectedTrx2.close();
    rtx.close();
    manager2.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) DescendantAxis(org.sirix.axis.DescendantAxis) Test(org.junit.Test)

Example 25 with DescendantAxis

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

the class ExpressionSingleTest method testDup.

@Test
public void testDup() throws SirixException {
    ExpressionSingle builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    assertTrue(builder.getExpr() instanceof NestedAxis);
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    assertEquals(true, builder.isOrdered());
    assertTrue(builder.getExpr() instanceof NestedAxis);
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new ChildAxis(holder.getReader()));
    assertEquals(false, builder.isOrdered());
    builder = new ExpressionSingle();
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new ParentAxis(holder.getReader()));
    assertEquals(true, builder.isOrdered());
    builder = new ExpressionSingle();
    builder.add(new ChildAxis(holder.getReader()));
    builder.add(new DescendantAxis(holder.getReader()));
    builder.add(new FollowingSiblingAxis(holder.getReader()));
    assertEquals(false, builder.isOrdered());
    builder = new ExpressionSingle();
    builder.add(new UnionAxis(holder.getReader(), new DescendantAxis(holder.getReader()), new ParentAxis(holder.getReader())));
    assertEquals(false, builder.isOrdered());
    assertTrue(builder.getExpr() instanceof DupFilterAxis);
}
Also used : ChildAxis(org.sirix.axis.ChildAxis) FollowingSiblingAxis(org.sirix.axis.FollowingSiblingAxis) ParentAxis(org.sirix.axis.ParentAxis) NestedAxis(org.sirix.axis.NestedAxis) DupFilterAxis(org.sirix.service.xml.xpath.filter.DupFilterAxis) DescendantAxis(org.sirix.axis.DescendantAxis) UnionAxis(org.sirix.service.xml.xpath.expr.UnionAxis) 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