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