Search in sources :

Example 1 with EnvironmentLockedException

use of com.sleepycat.je.EnvironmentLockedException in project GeoGig by boundlessgeo.

the class JEObjectDatabase method createDatabase.

protected Database createDatabase() {
    final String databaseName = "ObjectDatabase";
    Environment environment;
    try {
        environment = createEnvironment(readOnly);
    } catch (EnvironmentLockedException e) {
        throw new IllegalStateException("The repository is already open by another process for writing", e);
    }
    if (!environment.getDatabaseNames().contains(databaseName)) {
        if (readOnly) {
            environment.close();
            try {
                environment = createEnvironment(false);
            } catch (EnvironmentLockedException e) {
                throw new IllegalStateException(String.format("Environment open readonly but database %s does not exist.", databaseName));
            }
        }
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        Database openDatabase = environment.openDatabase(null, databaseName, dbConfig);
        openDatabase.close();
        environment.flushLog(true);
        environment.close();
        environment = createEnvironment(readOnly);
    }
    // System.err.println("Opened ObjectDatabase at " + env.getHome()
    // + ". Environment read-only: " + environment.getConfig().getReadOnly()
    // + " database read only: " + this.readOnly);
    Database database;
    try {
        LOGGER.debug("Opening ObjectDatabase at {}", environment.getHome());
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setCacheMode(CacheMode.MAKE_COLD);
        // can result in a slightly smaller db size
        dbConfig.setKeyPrefixing(false);
        dbConfig.setReadOnly(readOnly);
        boolean transactional = environment.getConfig().getTransactional();
        dbConfig.setTransactional(transactional);
        dbConfig.setDeferredWrite(!transactional);
        database = environment.openDatabase(null, databaseName, dbConfig);
    } catch (RuntimeException e) {
        if (environment != null) {
            environment.close();
        }
        throw e;
    }
    this.env = environment;
    return database;
}
Also used : EnvironmentLockedException(com.sleepycat.je.EnvironmentLockedException) AbstractObjectDatabase(org.locationtech.geogig.storage.AbstractObjectDatabase) ConfigDatabase(org.locationtech.geogig.storage.ConfigDatabase) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

Database (com.sleepycat.je.Database)1 DatabaseConfig (com.sleepycat.je.DatabaseConfig)1 Environment (com.sleepycat.je.Environment)1 EnvironmentLockedException (com.sleepycat.je.EnvironmentLockedException)1 AbstractObjectDatabase (org.locationtech.geogig.storage.AbstractObjectDatabase)1 ConfigDatabase (org.locationtech.geogig.storage.ConfigDatabase)1 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)1