use of nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbWrapper in project timbuctoo by HuygensING.
the class BdbDumpTask method execute.
@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
if (!parameters.keySet().containsAll(REQUIRED_PARAMS)) {
output.write("Make sure you provide the following parameters: " + REQUIRED_PARAMS);
return;
}
BdbWrapper<String, String> database = environmentCreator.getDatabase(getParam(parameters, OWNER), getParam(parameters, DATA_SET), getParam(parameters, DATABASE), true, STRING_BINDER, STRING_BINDER, new StringStringIsCleanHandler());
String prefix = parameters.containsKey("prefix") ? getParam(parameters, "prefix") : "";
int start = parameters.containsKey("start") ? Integer.parseInt(getParam(parameters, "start")) : 0;
int count = parameters.containsKey("count") ? Integer.parseInt(getParam(parameters, "count")) : 10;
output.write("uncommitted data: " + database.dump(prefix, start, count, LockMode.READ_UNCOMMITTED));
output.write("committed data: " + database.dump(prefix, start, count, LockMode.READ_COMMITTED));
}
use of nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbWrapper in project timbuctoo by HuygensING.
the class BdbPersistentEnvironmentCreator method getDatabase.
@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName, boolean allowDuplicates, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, IsCleanHandler<KeyT, ValueT> cleanHandler) throws BdbDbCreationException {
DatabaseConfig config = new DatabaseConfig();
config.setAllowCreate(true);
config.setDeferredWrite(true);
config.setSortedDuplicates(allowDuplicates);
String environmentKey = environmentKey(userId, dataSetId);
String databaseKey = environmentKey + "_" + databaseName;
if (!databases.containsKey(databaseKey)) {
if (!environmentMap.containsKey(environmentKey)) {
try {
File dbDir = fileHelper.pathInDataSet(userId, dataSetId, "databases");
Environment dataSetEnvironment = new Environment(dbDir, configuration);
environmentMap.put(environmentKey, dataSetEnvironment);
} catch (DatabaseException e) {
throw new BdbDbCreationException(e);
}
}
try {
databases.put(databaseKey, environmentMap.get(environmentKey).openDatabase(null, databaseName, config));
} catch (DatabaseException e) {
throw new BdbDbCreationException(e);
}
}
return new BdbWrapper<>(environmentMap.get(environmentKey), databases.get(databaseKey), config, keyBinder, valueBinder, cleanHandler);
}
use of nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbWrapper in project timbuctoo by HuygensING.
the class BdbNonPersistentEnvironmentCreator method getDatabase.
@Override
public <KeyT, ValueT> BdbWrapper<KeyT, ValueT> getDatabase(String userId, String dataSetId, String databaseName, boolean allowDuplicates, EntryBinding<KeyT> keyBinder, EntryBinding<ValueT> valueBinder, IsCleanHandler<KeyT, ValueT> isCleanHandler) throws BdbDbCreationException {
try {
DatabaseConfig config = new DatabaseConfig();
config.setAllowCreate(true);
config.setDeferredWrite(true);
config.setSortedDuplicates(allowDuplicates);
String environmentKey = environmentKey(userId, dataSetId);
File envHome = new File(dbHome, environmentKey);
envHome.mkdirs();
Environment dataSetEnvironment = new Environment(envHome, configuration);
Database database = dataSetEnvironment.openDatabase(null, databaseName, config);
databases.put(environmentKey + "_" + databaseName, database);
environmentMap.put(environmentKey, dataSetEnvironment);
return new BdbWrapper<>(dataSetEnvironment, database, config, keyBinder, valueBinder, isCleanHandler);
} catch (DatabaseException e) {
throw new BdbDbCreationException(e);
}
}
Aggregations