Search in sources :

Example 66 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class FirstAxisTest method testAxis.

@Test
public void testAxis() throws SirixException {
    final XdmNodeReadTrx firstRtx = holder.getResourceManager().beginNodeReadTrx(1);
    new IteratorTester<XdmNodeReadTrx>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(firstRtx), null) {

        @Override
        protected Iterator<XdmNodeReadTrx> newTargetIterator() {
            return new FirstAxis(holder.getReader());
        }
    }.test();
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 67 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class LastAxisTest method testAxis.

@Test
public void testAxis() throws SirixException {
    final XdmNodeReadTrx firstRtx = holder.getResourceManager().beginNodeReadTrx(1);
    final XdmNodeReadTrx thirdRtx = holder.getReader();
    new IteratorTester<XdmNodeReadTrx>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(thirdRtx), null) {

        @Override
        protected Iterator<XdmNodeReadTrx> newTargetIterator() {
            return new LastAxis(firstRtx);
        }
    }.test();
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 68 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class XMLShredderTest method testShreddingLargeText.

@Test
public void testShreddingLargeText() throws Exception {
    final Database database = TestHelper.getDatabase(PATHS.PATH2.getFile());
    final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
    final XMLShredder shredder = new XMLShredder.Builder(wtx, XMLShredder.createFileReader(XML3), Insert.ASFIRSTCHILD).commitAfterwards().build();
    shredder.call();
    wtx.close();
    final XdmNodeReadTrx rtx = manager.beginNodeReadTrx();
    assertTrue(rtx.moveToFirstChild().hasMoved());
    assertTrue(rtx.moveToFirstChild().hasMoved());
    final StringBuilder tnkBuilder = new StringBuilder();
    do {
        tnkBuilder.append(rtx.getValue());
    } while (rtx.moveToRightSibling().hasMoved());
    final String tnkString = tnkBuilder.toString();
    rtx.close();
    manager.close();
    final XMLEventReader validater = XMLShredder.createFileReader(XML3);
    final StringBuilder xmlBuilder = new StringBuilder();
    while (validater.hasNext()) {
        final XMLEvent event = validater.nextEvent();
        switch(event.getEventType()) {
            case XMLStreamConstants.CHARACTERS:
                final String text = event.asCharacters().getData().trim();
                if (text.length() > 0) {
                    xmlBuilder.append(text);
                }
                break;
        }
    }
    assertEquals(xmlBuilder.toString(), tnkString);
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Database(org.sirix.api.Database) XMLEvent(javax.xml.stream.events.XMLEvent) XMLEventReader(javax.xml.stream.XMLEventReader) ResourceManager(org.sirix.api.ResourceManager) Test(org.junit.Test)

Example 69 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class XdmResourceManager method close.

@Override
public synchronized void close() {
    if (!mClosed) {
        // Close all open node transactions.
        for (XdmNodeReadTrx rtx : mNodeReaderMap.values()) {
            if (rtx instanceof XdmNodeWriteTrx) {
                ((XdmNodeWriteTrx) rtx).rollback();
            }
            rtx.close();
            rtx = null;
        }
        // Close all open node page transactions.
        for (PageReadTrx rtx : mNodePageTrxMap.values()) {
            rtx.close();
            rtx = null;
        }
        // Close all open page transactions.
        for (PageReadTrx rtx : mPageTrxMap.values()) {
            rtx.close();
            rtx = null;
        }
        // Immediately release all ressources.
        mLastCommittedUberPage = null;
        mNodeReaderMap.clear();
        mPageTrxMap.clear();
        mNodePageTrxMap.clear();
        mResourceStore.closeResource(mResourceConfig.getResource());
        mFac.close();
        mClosed = true;
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) PageReadTrx(org.sirix.api.PageReadTrx)

Example 70 with XdmNodeReadTrx

use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.

the class NonStructuralWrapperAxis method nextKey.

@Override
protected long nextKey() {
    final XdmNodeReadTrx trx = mParentAxis.getTrx();
    if (mParentAxis.isSelfIncluded() == IncludeSelf.NO || !mFirst) {
        final long nodeKey = nonStructural(trx);
        if (nodeKey != Fixed.NULL_NODE_KEY.getStandardProperty()) {
            return nodeKey;
        }
    }
    if (mParentAxis.hasNext()) {
        long key = mParentAxis.next();
        mFirst = false;
        mNspIndex = 0;
        mAttIndex = 0;
        return key;
    }
    return done();
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx)

Aggregations

XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)150 Test (org.junit.Test)93 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)48 QNm (org.brackit.xquery.atomic.QNm)20 DescendantAxis (org.sirix.axis.DescendantAxis)17 Iterator (java.util.Iterator)16 ResourceManager (org.sirix.api.ResourceManager)14 Axis (org.sirix.api.Axis)13 DBNode (org.sirix.xquery.node.DBNode)12 QueryException (org.brackit.xquery.QueryException)11 FilterAxis (org.sirix.axis.filter.FilterAxis)11 IndexController (org.sirix.access.IndexController)10 IndexDef (org.sirix.index.IndexDef)10 Item (org.brackit.xquery.xdm.Item)7 Database (org.sirix.api.Database)7 SirixException (org.sirix.exception.SirixException)6 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 SirixDeweyID (org.sirix.node.SirixDeweyID)5 Path (java.nio.file.Path)4 AbsAxisTest (org.sirix.axis.AbsAxisTest)4