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