Search in sources :

Example 31 with Database

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

the class XMLSerializerTest method testXMLSerializer.

@Test
public void testXMLSerializer() 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();
    DocumentCreater.create(wtx);
    wtx.commit();
    wtx.close();
    // Generate from this session.
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final XMLSerializer serializer = new XMLSerializerBuilder(manager, out).emitXMLDeclaration().build();
    serializer.call();
    assertEquals(DocumentCreater.XML, 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 32 with Database

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

the class XMLSerializerTest method testIDSerializer.

@Test
public void testIDSerializer() 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();
    DocumentCreater.create(wtx);
    wtx.commit();
    wtx.close();
    // Generate from this session.
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final XMLSerializer serializer = new XMLSerializerBuilder(manager, out).emitIDs().emitXMLDeclaration().build();
    serializer.call();
    assertEquals(DocumentCreater.ID, 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 33 with Database

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

the class XMLSerializerTest method testRestSerializer.

@Test
public void testRestSerializer() 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();
    DocumentCreater.create(wtx);
    wtx.commit();
    wtx.close();
    // Generate from this session.
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final XMLSerializer serializer = XMLSerializer.newBuilder(manager, out).emitRESTful().emitIDs().emitXMLDeclaration().build();
    serializer.call();
    assertEquals(DocumentCreater.REST, out.toString());
    manager.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) 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 34 with Database

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

the class XdmResourceManagerTest method testNonExisting.

@Test
public void testNonExisting() throws SirixException, InterruptedException {
    final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
    final Database database2 = TestHelper.getDatabase(PATHS.PATH1.getFile());
    assertTrue(database == database2);
}
Also used : Database(org.sirix.api.Database) Test(org.junit.Test)

Example 35 with Database

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

the class XdmResourceManagerTest method testSingleton.

@Test
public void testSingleton() {
    final Database database = Holder.openResourceManager().getDatabase();
    assertEquals(database, holder.getDatabase());
    final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    assertEquals(manager, holder.getResourceManager());
    manager.close();
    final ResourceManager manager2 = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    assertNotSame(manager2, holder.getResourceManager());
    database.close();
}
Also used : Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) Test(org.junit.Test)

Aggregations

Database (org.sirix.api.Database)55 ResourceManager (org.sirix.api.ResourceManager)30 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)22 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)19 Test (org.junit.Test)18 SirixException (org.sirix.exception.SirixException)18 Session (org.sirix.api.Session)16 IOException (java.io.IOException)13 Path (java.nio.file.Path)13 SessionConfiguration (org.sirix.access.conf.SessionConfiguration)13 XMLSerializerBuilder (org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder)12 JaxRxException (org.jaxrx.core.JaxRxException)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 NodeWriteTrx (org.sirix.api.NodeWriteTrx)8 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 NodeReadTrx (org.sirix.api.NodeReadTrx)6 XMLSerializer (org.sirix.service.xml.serialize.XMLSerializer)6 XMLEventReader (javax.xml.stream.XMLEventReader)5 DocumentException (org.brackit.xquery.xdm.DocumentException)5