use of com.sleepycat.je.Database in project GeoGig by boundlessgeo.
the class BDBJEDeduplicationService method createDeduplicator.
@Override
public Deduplicator createDeduplicator() {
Database database = createDatabase();
BDBJEDeduplicator deduplicator = new BDBJEDeduplicator(database, this);
this.openDeduplicators.add(deduplicator);
return deduplicator;
}
use of com.sleepycat.je.Database 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;
}
use of com.sleepycat.je.Database in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method openTable.
public boolean openTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException {
if (tables.containsKey(tableName)) {
throw new BimserverDatabaseException("Table " + tableName + " already opened");
}
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setKeyPrefixing(keyPrefixing);
databaseConfig.setAllowCreate(false);
boolean finalTransactional = transactional && useTransactions;
// if (!transactional) {
// databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
// }
databaseConfig.setDeferredWrite(!finalTransactional);
databaseConfig.setTransactional(finalTransactional);
databaseConfig.setSortedDuplicates(false);
Database database = environment.openDatabase(null, tableName, databaseConfig);
if (database == null) {
throw new BimserverDatabaseException("Table " + tableName + " not found in database");
}
tables.put(tableName, new TableWrapper(database, finalTransactional));
return true;
}
use of com.sleepycat.je.Database in project BIMserver by opensourceBIM.
the class BerkeleyKeyValueStore method createTable.
public boolean createTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
if (tables.containsKey(tableName)) {
throw new BimserverDatabaseException("Table " + tableName + " already created");
}
DatabaseConfig databaseConfig = new DatabaseConfig();
databaseConfig.setKeyPrefixing(keyPrefixing);
databaseConfig.setAllowCreate(true);
boolean finalTransactional = transactional && useTransactions;
databaseConfig.setDeferredWrite(!finalTransactional);
// if (!transactional) {
// databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
// }
databaseConfig.setTransactional(finalTransactional);
databaseConfig.setSortedDuplicates(false);
Database database = environment.openDatabase(null, tableName, databaseConfig);
if (database == null) {
return false;
}
tables.put(tableName, new TableWrapper(database, finalTransactional));
return true;
}
use of com.sleepycat.je.Database in project timbuctoo by HuygensING.
the class BdbNonPersistentEnvironmentCreator method close.
public void close() throws DatabaseException, IOException {
for (Database database : databases.values()) {
database.close();
}
boolean wasDeleted = false;
int tries = 0;
while (!wasDeleted) {
try {
FileUtils.cleanDirectory(dbHome);
wasDeleted = true;
} catch (IOException e) {
tries++;
if (tries >= 10) {
wasDeleted = true;
} else {
try {
Thread.sleep(1);
} catch (InterruptedException e1) {
LOG.error("Trying to clean up and delete directory, but it failed the first time around and then the " + "thread was interrupted");
wasDeleted = true;
}
}
}
}
}
Aggregations