Search in sources :

Example 41 with Database

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

the class TestHelper method getDatabase.

/**
 * Getting a database and create one of not existing. This includes the creation of a resource
 * with the settings in the builder as standard.
 *
 * @param file to be created
 * @return a database-obj
 */
@Ignore
public static final Database getDatabase(final Path file) {
    if (INSTANCES.containsKey(file)) {
        return INSTANCES.get(file);
    } else {
        try {
            final DatabaseConfiguration config = new DatabaseConfiguration(file);
            if (!Files.exists(file)) {
                Databases.createDatabase(config);
            }
            final Database database = Databases.openDatabase(file);
            database.createResource(new ResourceConfiguration.Builder(RESOURCE, config).build());
            INSTANCES.put(file, database);
            return database;
        } catch (final SirixRuntimeException e) {
            fail(e.toString());
            return null;
        }
    }
}
Also used : SirixRuntimeException(org.sirix.exception.SirixRuntimeException) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) Ignore(org.junit.Ignore)

Example 42 with Database

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

the class TestHelper method closeEverything.

/**
 * Closing all resources as defined in the enum {@link PATHS}.
 *
 * @throws SirixException
 */
@Ignore
public static final void closeEverything() throws SirixException {
    if (INSTANCES.containsKey(PATHS.PATH1.getFile())) {
        final Database database = INSTANCES.remove(PATHS.PATH1.getFile());
        database.close();
    }
    if (INSTANCES.containsKey(PATHS.PATH2.getFile())) {
        final Database database = INSTANCES.remove(PATHS.PATH2.getFile());
        database.close();
    }
}
Also used : Database(org.sirix.api.Database) Ignore(org.junit.Ignore)

Example 43 with Database

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

the class HashTest method createWtx.

private XdmNodeWriteTrx createWtx(final HashKind kind) throws SirixException {
    final Database database = TestHelper.getDatabase(TestHelper.PATHS.PATH1.getFile());
    database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).build());
    final ResourceManager manager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx wTrx = manager.beginNodeWriteTrx();
    return wTrx;
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager)

Example 44 with Database

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

the class Holder method generateDeweyIDResourceMgr.

/**
 * Generate a resource with deweyIDs for resources and open a resource.
 *
 * @return this holder instance
 * @throws SirixException if an error occurs
 */
public static Holder generateDeweyIDResourceMgr() throws SirixException {
    final Path file = PATHS.PATH1.getFile();
    final DatabaseConfiguration config = new DatabaseConfiguration(file);
    if (!Files.exists(file)) {
        Databases.createDatabase(config);
    }
    final Database database = Databases.openDatabase(PATHS.PATH1.getFile());
    database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).useDeweyIDs(true).build());
    final ResourceManager resourceManager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final Holder holder = new Holder();
    holder.setDatabase(database);
    holder.setResourceManager(resourceManager);
    return holder;
}
Also used : Path(java.nio.file.Path) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) ResourceConfiguration(org.sirix.access.conf.ResourceConfiguration)

Example 45 with Database

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

the class Holder method generatePathSummary.

/**
 * Generate a resource with a path summary.
 *
 * @return this holder instance
 * @throws SirixException if an error occurs
 */
public static Holder generatePathSummary() throws SirixException {
    final Path file = PATHS.PATH1.getFile();
    final DatabaseConfiguration config = new DatabaseConfiguration(file);
    if (!Files.exists(file)) {
        Databases.createDatabase(config);
    }
    final Database database = Databases.openDatabase(PATHS.PATH1.getFile());
    database.createResource(new ResourceConfiguration.Builder(TestHelper.RESOURCE, PATHS.PATH1.getConfig()).buildPathSummary(true).build());
    final ResourceManager resourceManager = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final Holder holder = new Holder();
    holder.setDatabase(database);
    holder.setResourceManager(resourceManager);
    return holder;
}
Also used : Path(java.nio.file.Path) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) ResourceConfiguration(org.sirix.access.conf.ResourceConfiguration)

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