Search in sources :

Example 16 with Database

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

the class WorkerHelperTest method testSerializeXML.

/**
 * This method tests
 * {@link WorkerHelper#serializeXML(Session, OutputStream, boolean, boolean,Long)}
 */
@Test
public void testSerializeXML() throws SirixException, IOException {
    final Database database = Databases.openDatabase(DBFILE.getParentFile());
    final Session session = database.getSession(new SessionConfiguration.Builder(DBFILE.getName()).build());
    final OutputStream out = new ByteArrayOutputStream();
    assertNotNull("test serialize xml", WorkerHelper.serializeXML(session, out, true, true, null));
    session.close();
    database.close();
    out.close();
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Database(org.sirix.api.Database) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Session(org.sirix.api.Session) Test(org.junit.Test)

Example 17 with Database

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

the class Holder method openResourceManager.

/**
 * Open a resource manager.
 *
 * @return this holder instance
 * @throws SirixException if an error occurs
 */
public static Holder openResourceManager() throws SirixException {
    final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
    final ResourceManager session = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final Holder holder = new Holder();
    holder.setDatabase(database);
    holder.setResourceManager(session);
    return holder;
}
Also used : Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager)

Example 18 with Database

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

the class TestHelper method createPICommentTestDocument.

/**
 * Creating a test document with comments and processing instructions at {@link PATHS#PATH1}.
 *
 * @throws SirixException
 */
public static void createPICommentTestDocument() throws SirixException {
    try (final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile())) {
        database.createResource(new ResourceConfiguration.Builder(RESOURCE, PATHS.PATH1.config).build());
        try (final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(RESOURCE).build());
            final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx()) {
            DocumentCreater.createCommentPI(wtx);
            wtx.commit();
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Database(org.sirix.api.Database) XdmResourceManager(org.sirix.access.XdmResourceManager) ResourceManager(org.sirix.api.ResourceManager)

Example 19 with Database

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

the class TestHelper method createTestDocument.

/**
 * Creating a test document at {@link PATHS#PATH1}.
 *
 * @throws SirixException
 */
public static void createTestDocument() throws SirixException {
    try (final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile())) {
        database.createResource(new ResourceConfiguration.Builder(RESOURCE, PATHS.PATH1.config).build());
        try (final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(RESOURCE).build());
            final XdmNodeWriteTrx wtx = manager.beginNodeWriteTrx()) {
            DocumentCreater.create(wtx);
            wtx.commit();
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Database(org.sirix.api.Database) XdmResourceManager(org.sirix.access.XdmResourceManager) ResourceManager(org.sirix.api.ResourceManager)

Example 20 with Database

use of org.sirix.api.Database 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)

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