Search in sources :

Example 61 with XdmNodeWriteTrx

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

the class ThreadTest method testThreads.

@Test
public void testThreads() throws Exception {
    final ExecutorService taskExecutor = Executors.newFixedThreadPool(WORKER_COUNT);
    long newKey = 10L;
    for (int i = 0; i < WORKER_COUNT; i++) {
        taskExecutor.submit(new Task(holder.getResourceManager().beginNodeReadTrx(i)));
        try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx()) {
            wtx.moveTo(newKey);
            wtx.setValue("value" + i);
            newKey = wtx.getNodeKey();
            wtx.commit();
        }
    }
    taskExecutor.shutdown();
    taskExecutor.awaitTermination(1000000, TimeUnit.SECONDS);
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 62 with XdmNodeWriteTrx

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

the class UpdateTest method testReplaceTextNode.

@Test
public void testReplaceTextNode() throws SirixException, IOException, XMLStreamException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.commit();
    XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    rtx.moveTo(12);
    wtx.moveTo(5);
    wtx.replaceNode(rtx);
    testReplaceTextNode(wtx);
    wtx.commit();
    testReplaceTextNode(wtx);
    wtx.close();
    rtx = holder.getResourceManager().beginNodeReadTrx();
    testReplaceTextNode(rtx);
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 63 with XdmNodeWriteTrx

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

the class UpdateTest method testInsertPath.

@Test
public void testInsertPath() throws SirixException {
    XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    wtx.commit();
    wtx.close();
    wtx = holder.getResourceManager().beginNodeWriteTrx();
    assertTrue(wtx.moveToDocumentRoot().hasMoved());
    assertEquals(1L, wtx.insertElementAsFirstChild(new QNm("")).getNodeKey());
    assertEquals(2L, wtx.insertElementAsFirstChild(new QNm("")).getNodeKey());
    assertEquals(3L, wtx.insertElementAsFirstChild(new QNm("")).getNodeKey());
    assertTrue(wtx.moveToParent().hasMoved());
    assertEquals(4L, wtx.insertElementAsRightSibling(new QNm("")).getNodeKey());
    wtx.commit();
    wtx.close();
    final XdmNodeWriteTrx wtx2 = holder.getResourceManager().beginNodeWriteTrx();
    assertTrue(wtx2.moveToDocumentRoot().hasMoved());
    assertTrue(wtx2.moveToFirstChild().hasMoved());
    assertEquals(5L, wtx2.insertElementAsFirstChild(new QNm("")).getNodeKey());
    wtx2.commit();
    wtx2.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) Test(org.junit.Test)

Example 64 with XdmNodeWriteTrx

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

the class UpdateTest method testDelete.

@Test
public void testDelete() throws SirixException {
    try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx()) {
        DocumentCreater.create(wtx);
        wtx.moveTo(4);
        wtx.insertElementAsRightSibling(new QNm("blabla"));
        wtx.moveTo(5);
        wtx.remove();
        assertEquals(8, wtx.getNodeKey());
        wtx.moveTo(4);
        testDelete(wtx);
        wtx.commit();
        testDelete(wtx);
        wtx.close();
        try (final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx()) {
            testDelete(rtx);
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 65 with XdmNodeWriteTrx

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

the class UpdateTest method testReplaceElementNode.

@Test
public void testReplaceElementNode() throws SirixException, IOException, XMLStreamException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.commit();
    XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    rtx.moveTo(11);
    wtx.moveTo(5);
    wtx.replaceNode(rtx);
    testReplaceElementNode(wtx);
    wtx.commit();
    testReplaceElementNode(wtx);
    wtx.close();
    rtx = holder.getResourceManager().beginNodeReadTrx();
    testReplaceElementNode(rtx);
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Aggregations

XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)101 Test (org.junit.Test)61 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)48 ResourceManager (org.sirix.api.ResourceManager)33 Database (org.sirix.api.Database)22 QNm (org.brackit.xquery.atomic.QNm)15 SirixException (org.sirix.exception.SirixException)15 Path (java.nio.file.Path)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 DocumentException (org.brackit.xquery.xdm.DocumentException)7 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)7 DescendantAxis (org.sirix.axis.DescendantAxis)7 XMLSerializerBuilder (org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder)7 IOException (java.io.IOException)5 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 SirixIOException (org.sirix.exception.SirixIOException)5 SirixDeweyID (org.sirix.node.SirixDeweyID)5 DBNode (org.sirix.xquery.node.DBNode)5 XMLEventReader (javax.xml.stream.XMLEventReader)4 QueryException (org.brackit.xquery.QueryException)4