Search in sources :

Example 16 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration in project sirix by sirixdb.

the class FMSEImport method shredder.

/**
 * Shredder new revision as temporal resource.
 *
 * @param resNewRev {@link File} reference for new revision (XML resource)
 * @param newRev {@link File} reference for shreddered new revision (sirix resource)
 * @throws SirixException if sirix fails to shredder the file
 * @throws IOException if file couldn't be read
 * @throws XMLStreamException if XML document isn't well formed
 * @throws NullPointerException if {@code resNewRev} or {@code newRev} is {@code null}
 */
private void shredder(final Path resNewRev, @Nonnull Path newRev) throws SirixException, IOException, XMLStreamException {
    assert resNewRev != null;
    assert newRev != null;
    final DatabaseConfiguration conf = new DatabaseConfiguration(newRev);
    Databases.truncateDatabase(conf);
    Databases.createDatabase(conf);
    try (final Database db = Databases.openDatabase(newRev)) {
        db.createResource(new ResourceConfiguration.Builder("shredded", conf).build());
        try (final ResourceManager resMgr = db.getResourceManager(new ResourceManagerConfiguration.Builder("shredded").build());
            final XdmNodeWriteTrx wtx = resMgr.beginNodeWriteTrx()) {
            final XMLEventReader fileReader = XMLShredder.createFileReader(resNewRev);
            final XMLShredder shredder = new XMLShredder.Builder(wtx, fileReader, Insert.ASFIRSTCHILD).commitAfterwards().build();
            shredder.call();
        }
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) Database(org.sirix.api.Database) XMLEventReader(javax.xml.stream.XMLEventReader) XMLShredder(org.sirix.service.xml.shredder.XMLShredder) ResourceManager(org.sirix.api.ResourceManager)

Example 17 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration 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 18 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration 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 19 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration 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)

Example 20 with DatabaseConfiguration

use of org.sirix.access.conf.DatabaseConfiguration in project sirix by sirixdb.

the class DBStore method create.

@Override
public TemporalCollection<?> create(final String collName, @Nullable final Stream<SubtreeParser> parsers) throws DocumentException {
    if (parsers != null) {
        final DatabaseConfiguration dbConf = new DatabaseConfiguration(mLocation.resolve(collName));
        try {
            Databases.truncateDatabase(dbConf);
            Databases.createDatabase(dbConf);
            final Database database = Databases.openDatabase(dbConf.getFile());
            mDatabases.add(database);
            final ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
            int i = database.listResources().size() + 1;
            try {
                SubtreeParser parser = null;
                while ((parser = parsers.next()) != null) {
                    final SubtreeParser nextParser = parser;
                    final String resourceName = new StringBuilder("resource").append(String.valueOf(i)).toString();
                    pool.submit(() -> {
                        database.createResource(ResourceConfiguration.newBuilder(resourceName, dbConf).storageType(mStorageType).useDeweyIDs(true).useTextCompression(true).buildPathSummary(true).build());
                        try (final ResourceManager resource = database.getResourceManager(new ResourceManagerConfiguration.Builder(resourceName).build());
                            final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx()) {
                            final DBCollection collection = new DBCollection(collName, database);
                            mCollections.put(database, collection);
                            nextParser.parse(new SubtreeBuilder(collection, wtx, Insert.ASFIRSTCHILD, Collections.<SubtreeListener<? super AbstractTemporalNode<DBNode>>>emptyList()));
                            wtx.commit();
                        }
                        return null;
                    });
                    i++;
                }
            } finally {
                parsers.close();
            }
            pool.shutdown();
            pool.awaitTermination(5, TimeUnit.MINUTES);
            return new DBCollection(collName, database);
        } catch (final SirixRuntimeException | InterruptedException e) {
            throw new DocumentException(e.getCause());
        }
    }
    return null;
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) SubtreeListener(org.brackit.xquery.node.parser.SubtreeListener) DatabaseConfiguration(org.sirix.access.conf.DatabaseConfiguration) SubtreeParser(org.brackit.xquery.node.parser.SubtreeParser) AbstractTemporalNode(org.brackit.xquery.xdm.AbstractTemporalNode) ResourceManager(org.sirix.api.ResourceManager) SirixRuntimeException(org.sirix.exception.SirixRuntimeException) DocumentException(org.brackit.xquery.xdm.DocumentException) Database(org.sirix.api.Database) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)24 Database (org.sirix.api.Database)19 ResourceManager (org.sirix.api.ResourceManager)11 Path (java.nio.file.Path)10 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)7 DocumentException (org.brackit.xquery.xdm.DocumentException)5 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)5 XMLEventReader (javax.xml.stream.XMLEventReader)4 SirixException (org.sirix.exception.SirixException)4 IOException (java.io.IOException)3 QName (javax.xml.namespace.QName)3 ResourceConfiguration (org.sirix.access.conf.ResourceConfiguration)3 XMLShredder (org.sirix.service.xml.shredder.XMLShredder)3 LinkedList (java.util.LinkedList)2 XMLEventFactory (javax.xml.stream.XMLEventFactory)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 StartElement (javax.xml.stream.events.StartElement)2 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)2 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)2 Ignore (org.junit.Ignore)2