use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class UpdateTest method testRemoveDocument.
@Test(expected = SirixUsageException.class)
public void testRemoveDocument() throws SirixException {
final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.moveToDocumentRoot();
try {
wtx.remove();
} finally {
wtx.rollback();
wtx.close();
}
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class UpdateTest method testFirstCopySubtreeAsRightSibling.
@Test
public void testFirstCopySubtreeAsRightSibling() throws SirixException {
// Test for more than one node.
XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.commit();
wtx.close();
XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
rtx.moveTo(5);
wtx = holder.getResourceManager().beginNodeWriteTrx();
wtx.moveTo(9);
wtx.copySubtreeAsRightSibling(rtx);
testFirstCopySubtreeAsRightSibling(wtx);
wtx.commit();
wtx.close();
rtx = holder.getResourceManager().beginNodeReadTrx();
testFirstCopySubtreeAsRightSibling(rtx);
rtx.close();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class UpdateTest method testInsertChild.
@Test
public void testInsertChild() throws SirixException {
XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
wtx.insertElementAsFirstChild(new QNm("foo"));
wtx.commit();
wtx.close();
XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
assertEquals(1L, rtx.getRevisionNumber());
rtx.close();
// Insert 100 children.
for (int i = 1; i <= 50; i++) {
wtx = holder.getResourceManager().beginNodeWriteTrx();
wtx.moveToDocumentRoot();
wtx.moveToFirstChild();
wtx.insertElementAsFirstChild(new QNm("bar"));
wtx.insertTextAsRightSibling(Integer.toString(i));
wtx.commit();
wtx.close();
rtx = holder.getResourceManager().beginNodeReadTrx();
rtx.moveToDocumentRoot();
rtx.moveToFirstChild();
rtx.moveToFirstChild();
rtx.moveToRightSibling();
assertEquals(Integer.toString(i), rtx.getValue());
assertEquals(i + 1, rtx.getRevisionNumber());
rtx.close();
}
rtx = holder.getResourceManager().beginNodeReadTrx();
rtx.moveToDocumentRoot();
rtx.moveToFirstChild();
rtx.moveToFirstChild();
rtx.moveToRightSibling();
assertEquals("50", rtx.getValue());
assertEquals(51L, rtx.getRevisionNumber());
rtx.close();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class UpdateTest method testThirdMoveSubtreeToRightSibling.
@Test
public void testThirdMoveSubtreeToRightSibling() throws SirixException {
final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.moveTo(9);
wtx.moveSubtreeToRightSibling(4);
testThirdMoveSubtreeToRightSibling(wtx);
wtx.commit();
testThirdMoveSubtreeToRightSibling(wtx);
wtx.close();
final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
testThirdMoveSubtreeToRightSibling(rtx);
rtx.close();
}
use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.
the class UpdateTest method testInsertAsRightSiblingUpdateTextSecond.
/**
* Test update of text value in case two adjacent text nodes would be the result of an insert.
*/
@Test
public void testInsertAsRightSiblingUpdateTextSecond() throws SirixException {
final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
DocumentCreater.create(wtx);
wtx.commit();
wtx.moveTo(5L);
wtx.insertTextAsRightSibling("foo");
wtx.commit();
wtx.close();
final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
assertTrue(rtx.moveTo(1L).hasMoved());
assertEquals(4L, rtx.getFirstChildKey());
assertEquals(5L, rtx.getChildCount());
assertEquals(9L, rtx.getDescendantCount());
assertTrue(rtx.moveTo(8L).hasMoved());
assertEquals("foooops2", rtx.getValue());
rtx.close();
}
Aggregations