Search in sources :

Example 41 with XdmNodeWriteTrx

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

the class XdmResourceManagerTest method testInsertChild.

@Test
public void testInsertChild() {
    try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx()) {
        DocumentCreater.create(wtx);
        assertNotNull(wtx.moveToDocumentRoot());
        assertEquals(Kind.DOCUMENT, wtx.getKind());
        assertNotNull(wtx.moveToFirstChild());
        assertEquals(Kind.ELEMENT, wtx.getKind());
        assertEquals("p:a", new StringBuilder(wtx.getName().getPrefix()).append(":").append(wtx.getName().getLocalName()).toString());
        wtx.rollback();
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Test(org.junit.Test)

Example 42 with XdmNodeWriteTrx

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

the class XdmResourceManagerTest method testIdempotentClose.

@Test
public void testIdempotentClose() {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    DocumentCreater.create(wtx);
    wtx.commit();
    wtx.close();
    wtx.close();
    final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx();
    assertEquals(false, rtx.moveTo(14L).hasMoved());
    rtx.close();
    rtx.close();
    holder.getResourceManager().close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 43 with XdmNodeWriteTrx

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

the class AttributeAxisTest method testMultipleAttributes.

@Test
public void testMultipleAttributes() throws SirixException {
    final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx();
    final long nodeKey = wtx.insertElementAsFirstChild(new QNm("foo")).getNodeKey();
    wtx.insertAttribute(new QNm("foo0"), "0");
    wtx.moveTo(nodeKey);
    wtx.insertAttribute(new QNm("foo1"), "1");
    wtx.moveTo(nodeKey);
    wtx.insertAttribute(new QNm("foo2"), "2");
    Assert.assertEquals(true, wtx.moveTo(nodeKey).hasMoved());
    Assert.assertEquals(true, wtx.moveToAttribute(0).hasMoved());
    Assert.assertEquals("0", wtx.getValue());
    Assert.assertEquals(new QNm("foo0"), wtx.getName());
    Assert.assertEquals(true, wtx.moveToParent().hasMoved());
    Assert.assertEquals(true, wtx.moveToAttribute(1).hasMoved());
    Assert.assertEquals("1", wtx.getValue());
    Assert.assertEquals(new QNm("foo1"), wtx.getName());
    Assert.assertEquals(true, wtx.moveToParent().hasMoved());
    Assert.assertEquals(true, wtx.moveToAttribute(2).hasMoved());
    Assert.assertEquals("2", wtx.getValue());
    Assert.assertEquals(new QNm("foo2"), wtx.getName());
    Assert.assertEquals(true, wtx.moveTo(nodeKey).hasMoved());
    final AbstractAxis axis = new AttributeAxis(wtx);
    Assert.assertEquals(true, axis.hasNext());
    axis.next();
    Assert.assertEquals(nodeKey + 1, wtx.getNodeKey());
    Assert.assertEquals(new QNm("foo0"), wtx.getName());
    Assert.assertEquals("0", wtx.getValue());
    Assert.assertEquals(true, axis.hasNext());
    axis.next();
    Assert.assertEquals(nodeKey + 2, wtx.getNodeKey());
    Assert.assertEquals(new QNm("foo1"), wtx.getName());
    Assert.assertEquals("1", wtx.getValue());
    Assert.assertEquals(true, axis.hasNext());
    axis.next();
    Assert.assertEquals(nodeKey + 3, wtx.getNodeKey());
    Assert.assertEquals(new QNm("foo2"), wtx.getName());
    Assert.assertEquals("2", wtx.getValue());
    wtx.rollback();
    wtx.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) QNm(org.brackit.xquery.atomic.QNm) Test(org.junit.Test)

Example 44 with XdmNodeWriteTrx

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

the class XMLSerializerTest method testSampleCompleteSerializer.

@Test
public void testSampleCompleteSerializer() throws Exception {
    final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
    final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    // generate serialize all from this session
    DocumentCreater.createVersioned(wtx);
    wtx.close();
    XMLSerializer serializerall = new XMLSerializerBuilder(manager, out, -1).emitXMLDeclaration().build();
    serializerall.call();
    assertEquals(DocumentCreater.VERSIONEDXML, out.toString());
    out.reset();
    serializerall = new XMLSerializerBuilder(manager, out, 1, 2, 3).emitXMLDeclaration().build();
    serializerall.call();
    assertEquals(DocumentCreater.VERSIONEDXML, out.toString());
    manager.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XMLSerializerBuilder(org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder) XMLSerializerBuilder(org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 45 with XdmNodeWriteTrx

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

the class XMLSerializerTest method testKeyStart.

/**
 * This test check the XPath //books expression and expects 6 books as result. But the failure is,
 * that only the children of the books will be serialized and NOT the book node itself.
 */
@Test
public void testKeyStart() throws Exception {
    final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
    final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx();
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    // generate serialize all from this session
    DocumentCreater.createVersioned(wtx);
    wtx.commit();
    wtx.close();
    XMLSerializer serializerall = new XMLSerializerBuilder(manager, 5l, out, new XMLSerializerProperties()).emitXMLDeclaration().build();
    serializerall.call();
    final String result = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><b>foo<c/></b>";
    assertEquals(result, out.toString());
    out.reset();
    serializerall = new XMLSerializerBuilder(manager, out, 1, 2, 3).emitXMLDeclaration().build();
    serializerall.call();
    assertEquals(DocumentCreater.VERSIONEDXML, out.toString());
    manager.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XMLSerializerBuilder(org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder) XMLSerializerBuilder(org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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