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;
}
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();
}
}
}
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();
}
}
}
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();
}
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();
}
Aggregations