Search in sources :

Example 11 with ResourceManager

use of org.sirix.api.ResourceManager 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 12 with ResourceManager

use of org.sirix.api.ResourceManager 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 13 with ResourceManager

use of org.sirix.api.ResourceManager 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 14 with ResourceManager

use of org.sirix.api.ResourceManager 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 15 with ResourceManager

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

ResourceManager (org.sirix.api.ResourceManager)46 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)33 Database (org.sirix.api.Database)30 Path (java.nio.file.Path)16 Test (org.junit.Test)14 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)14 SirixException (org.sirix.exception.SirixException)12 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 XMLSerializerBuilder (org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder)8 IOException (java.io.IOException)5 ResourceConfiguration (org.sirix.access.conf.ResourceConfiguration)5 XMLEventReader (javax.xml.stream.XMLEventReader)4 DocumentException (org.brackit.xquery.xdm.DocumentException)4 OutputStream (java.io.OutputStream)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 QNm (org.brackit.xquery.atomic.QNm)3 DescendantAxis (org.sirix.axis.DescendantAxis)3 File (java.io.File)2 Files (java.nio.file.Files)2