Search in sources :

Example 1 with SubtreeParser

use of org.brackit.xquery.node.parser.SubtreeParser in project sirix by sirixdb.

the class Load method add.

private TemporalCollection<?> add(final org.brackit.xquery.xdm.Store store, final DBCollection coll, final String resName, final Sequence resources) throws DocumentException, IOException {
    if (resources instanceof Atomic) {
        final Atomic res = (Atomic) resources;
        coll.add(resName, new DocumentParser(URIHandler.getInputStream(res.stringValue())));
        return coll;
    } else {
        final ParserStream parsers = new ParserStream(resources);
        try {
            for (SubtreeParser parser = parsers.next(); parser != null; parser = parsers.next()) {
                coll.add(resName, parser);
            }
        } finally {
            parsers.close();
        }
        return coll;
    }
}
Also used : DocumentParser(org.brackit.xquery.node.parser.DocumentParser) SubtreeParser(org.brackit.xquery.node.parser.SubtreeParser) StreamSubtreeParser(org.brackit.xquery.node.parser.StreamSubtreeParser) Atomic(org.brackit.xquery.atomic.Atomic)

Example 2 with SubtreeParser

use of org.brackit.xquery.node.parser.SubtreeParser in project sirix by sirixdb.

the class Store method add.

private void add(final org.brackit.xquery.xdm.Store store, final DBCollection coll, final String resName, final Sequence nodes) throws DocumentException, IOException {
    if (nodes instanceof Node) {
        final Node<?> n = (Node<?>) nodes;
        coll.add(resName, new StoreParser(n));
    } else {
        final ParserStream parsers = new ParserStream(nodes);
        try {
            for (SubtreeParser parser = parsers.next(); parser != null; parser = parsers.next()) {
                coll.add(resName, parser);
            }
        } finally {
            parsers.close();
        }
    }
}
Also used : Node(org.brackit.xquery.xdm.Node) SubtreeParser(org.brackit.xquery.node.parser.SubtreeParser) StreamSubtreeParser(org.brackit.xquery.node.parser.StreamSubtreeParser)

Example 3 with SubtreeParser

use of org.brackit.xquery.node.parser.SubtreeParser in project sirix by sirixdb.

the class DBNode method parse.

@Override
public void parse(final SubtreeHandler handler) throws DocumentException {
    moveRtx();
    final SubtreeParser parser = new NavigationalSubtreeParser(this);
    parser.parse(handler);
}
Also used : NavigationalSubtreeParser(org.brackit.xquery.node.parser.NavigationalSubtreeParser) NavigationalSubtreeParser(org.brackit.xquery.node.parser.NavigationalSubtreeParser) SubtreeParser(org.brackit.xquery.node.parser.SubtreeParser)

Example 4 with SubtreeParser

use of org.brackit.xquery.node.parser.SubtreeParser 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

SubtreeParser (org.brackit.xquery.node.parser.SubtreeParser)4 StreamSubtreeParser (org.brackit.xquery.node.parser.StreamSubtreeParser)2 ExecutorService (java.util.concurrent.ExecutorService)1 Atomic (org.brackit.xquery.atomic.Atomic)1 DocumentParser (org.brackit.xquery.node.parser.DocumentParser)1 NavigationalSubtreeParser (org.brackit.xquery.node.parser.NavigationalSubtreeParser)1 SubtreeListener (org.brackit.xquery.node.parser.SubtreeListener)1 AbstractTemporalNode (org.brackit.xquery.xdm.AbstractTemporalNode)1 DocumentException (org.brackit.xquery.xdm.DocumentException)1 Node (org.brackit.xquery.xdm.Node)1 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)1 Database (org.sirix.api.Database)1 ResourceManager (org.sirix.api.ResourceManager)1 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1 SirixRuntimeException (org.sirix.exception.SirixRuntimeException)1