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);
}
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();
}
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();
}
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);
}
}
}
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();
}
Aggregations