Search in sources :

Example 11 with XdmNodeWriteTrx

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

the class UpdateTest method testRemoveDescendantFirst.

/**
 * Ordinary remove test.
 */
@Test
public void testRemoveDescendantFirst() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.commit();
    wtx.moveTo(4L);
    wtx.remove();
    wtx.commit();
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    assertEquals(0, rtx.getNodeKey());
    assertTrue(rtx.moveToFirstChild().hasMoved());
    assertEquals(1, rtx.getNodeKey());
    assertEquals(5, rtx.getFirstChildKey());
    assertEquals(4, rtx.getChildCount());
    assertEquals(8, rtx.getDescendantCount());
    assertTrue(rtx.moveToFirstChild().hasMoved());
    assertEquals(5, rtx.getNodeKey());
    assertEquals(Fixed.NULL_NODE_KEY.getStandardProperty(), rtx.getLeftSiblingKey());
    assertTrue(rtx.moveToRightSibling().hasMoved());
    assertEquals(8, rtx.getNodeKey());
    assertEquals(5, rtx.getLeftSiblingKey());
    assertTrue(rtx.moveToRightSibling().hasMoved());
    assertEquals(9, rtx.getNodeKey());
    assertTrue(rtx.moveToRightSibling().hasMoved());
    assertEquals(13, rtx.getNodeKey());
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 12 with XdmNodeWriteTrx

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

the class UpdateTest method testSubtreeInsertAsFirstChildSecond.

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

Example 13 with XdmNodeWriteTrx

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

the class UpdateTest method testSecondCopySubtreeAsFirstChild.

@Test
public void testSecondCopySubtreeAsFirstChild() 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.copySubtreeAsFirstChild(rtx);
    testSecondCopySubtreeAsFirstChild(wtx);
    wtx.commit();
    wtx.close();
    rtx = holder.getResourceManager().beginNodeReadTrx();
    testSecondCopySubtreeAsFirstChild(rtx);
    rtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 14 with XdmNodeWriteTrx

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

the class UpdateTest method testNodeTransactionIsolation.

@Test
public void testNodeTransactionIsolation() throws SirixException {
    XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    wtx.insertElementAsFirstChild(new QNm(""));
    testNodeTransactionIsolation(wtx);
    wtx.commit();
    testNodeTransactionIsolation(wtx);
    XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testNodeTransactionIsolation(rtx);
    wtx.moveToFirstChild();
    wtx.insertElementAsFirstChild(new QNm(""));
    testNodeTransactionIsolation(rtx);
    wtx.commit();
    testNodeTransactionIsolation(rtx);
    rtx.close();
    wtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 15 with XdmNodeWriteTrx

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

the class UpdateTest method testRemoveDescendant.

/**
 * Test for text concatenation.
 */
@Test
public void testRemoveDescendant() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.moveTo(0L);
    // assertEquals(10L, wtx.getDescendantCount());
    wtx.commit();
    assertEquals(10L, wtx.getDescendantCount());
    wtx.moveTo(5L);
    wtx.remove();
    testRemoveDescendant(wtx);
    wtx.commit();
    testRemoveDescendant(wtx);
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    testRemoveDescendant(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