use of org.sirix.exception.SirixRuntimeException 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;
}
}
}
use of org.sirix.exception.SirixRuntimeException 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;
}
use of org.sirix.exception.SirixRuntimeException in project sirix by sirixdb.
the class DBStore method drop.
@Override
public void drop(final String name) throws DocumentException {
final DatabaseConfiguration dbConfig = new DatabaseConfiguration(mLocation.resolve(name));
if (Databases.existsDatabase(dbConfig)) {
try {
Databases.truncateDatabase(dbConfig);
final Database database = Databases.openDatabase(dbConfig.getFile());
mDatabases.remove(database);
mCollections.remove(database);
} catch (final SirixRuntimeException e) {
throw new DocumentException(e);
}
}
throw new DocumentException("No collection with the specified name found!");
}
Aggregations