Search in sources :

Example 1 with BdbWrapper

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));
}
Also used : StringStringIsCleanHandler(nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler)

Example 2 with BdbWrapper

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);
}
Also used : BdbDbCreationException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException) Environment(com.sleepycat.je.Environment) File(java.io.File) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 3 with BdbWrapper

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);
    }
}
Also used : BdbDbCreationException(nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) BdbWrapper(nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbWrapper) File(java.io.File) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

DatabaseConfig (com.sleepycat.je.DatabaseConfig)2 DatabaseException (com.sleepycat.je.DatabaseException)2 Environment (com.sleepycat.je.Environment)2 File (java.io.File)2 BdbDbCreationException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException)2 Database (com.sleepycat.je.Database)1 BdbWrapper (nl.knaw.huygens.timbuctoo.v5.berkeleydb.BdbWrapper)1 StringStringIsCleanHandler (nl.knaw.huygens.timbuctoo.v5.berkeleydb.isclean.StringStringIsCleanHandler)1