use of com.sleepycat.je.Environment in project OpenRefine by OpenRefine.
the class RefineBrokerImpl method init.
@Override
public void init(ServletConfig config) throws Exception {
logger.trace("> init");
super.init(config);
timer = new Timer();
expirer = new Expirer();
timer.schedule(expirer, 0, LOCK_EXPIRATION_CHECK_DELAY);
String dataDir = config.getInitParameter("refine.data");
if (dataDir == null)
dataDir = "data";
File dataPath = new File(dataDir);
if (!dataPath.exists())
dataPath.mkdirs();
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
env = new Environment(dataPath, envConfig);
StoreConfig storeConfig = new StoreConfig();
storeConfig.setAllowCreate(true);
storeConfig.setTransactional(true);
projectStore = new EntityStore(env, "ProjectsStore", storeConfig);
lockStore = new EntityStore(env, "LockStore", storeConfig);
projectById = projectStore.getPrimaryIndex(String.class, Project.class);
lockById = lockStore.getPrimaryIndex(String.class, Lock.class);
locksByProject = lockStore.getSecondaryIndex(lockById, String.class, "pid");
logger.trace("< init");
}
use of com.sleepycat.je.Environment 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.Environment in project vertigo by KleeGroup.
the class BerkeleyKVStorePlugin method buildFsEnvironment.
private static Environment buildFsEnvironment(final File dbFile, final boolean readOnly) {
dbFile.mkdirs();
final EnvironmentConfig fsEnvironmentConfig = new EnvironmentConfig().setConfigParam(EnvironmentConfig.LOG_MEM_ONLY, "false").setConfigParam(EnvironmentConfig.CLEANER_MIN_UTILIZATION, "90").setConfigParam(EnvironmentConfig.CLEANER_MIN_FILE_UTILIZATION, "50").setReadOnly(readOnly).setAllowCreate(!readOnly).setTransactional(!readOnly);
return new Environment(dbFile, fsEnvironmentConfig);
}
use of com.sleepycat.je.Environment in project jvarkit by lindenb.
the class Biostar92368 method doWork.
@Override
public int doWork(List<String> args) {
if (this.dbHome == null) {
LOG.error("Undefined DB-Home");
return -1;
}
environment = null;
EnvironmentConfig envCfg = new EnvironmentConfig();
this.database = null;
Transaction txn = null;
PrintStream out = null;
try {
envCfg.setAllowCreate(true);
this.environment = new Environment(dbHome, envCfg);
DatabaseConfig cfg = new DatabaseConfig();
cfg.setAllowCreate(true);
cfg.setTemporary(true);
this.database = environment.openDatabase(txn, "interactions", cfg);
if (args.isEmpty()) {
LOG.info("reading stdin");
LineIterator r = IOUtils.openStdinForLineIterator();
load(txn, r);
CloserUtil.close(r);
} else {
for (String filename : args) {
LOG.info("reading " + filename);
LineIterator r = IOUtils.openURIForLineIterator(filename);
load(txn, r);
CloserUtil.close(r);
}
}
out = super.openFileOrStdoutAsPrintStream(outputFile);
DatabaseEntry key1 = new DatabaseEntry();
DatabaseEntry data1 = new DatabaseEntry();
DatabaseEntry key2 = new DatabaseEntry();
DatabaseEntry data2 = new DatabaseEntry();
Cursor c1 = this.database.openCursor(txn, null);
Cursor c2 = this.database.openCursor(txn, null);
while (c1.getNext(key1, data1, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
String prot1 = StringBinding.entryToString(key1);
boolean first = true;
while ((first ? c2.getFirst(key2, data2, LockMode.DEFAULT) : c2.getNext(key2, data2, LockMode.DEFAULT)) == OperationStatus.SUCCESS) {
first = false;
String prot2 = StringBinding.entryToString(key2);
if (prot2.compareTo(prot1) <= 0)
continue;
Stack<String> path = new Stack<String>();
path.push(prot1);
int depth = recursive(txn, prot2, path, -1, maxDepth);
if (depth != -1) {
out.println(prot1 + "\t" + prot2 + "\t" + depth);
} else {
// System.out.println(prot1+"\t"+prot2+"\t"+depth);
}
if (out.checkError())
break;
}
}
CloserUtil.close(c2);
CloserUtil.close(c1);
out.flush();
out.close();
return 0;
} catch (Exception err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(this.database);
CloserUtil.close(this.environment);
}
}
use of com.sleepycat.je.Environment in project jvarkit by lindenb.
the class VcfAnnotWithBeacon method doWork.
@Override
public int doWork(final List<String> args) {
try {
if (this.bdbDir != null) {
LOG.info("open BDB " + this.bdbDir);
IOUtil.assertDirectoryIsWritable(this.bdbDir);
final EnvironmentConfig envCfg = new EnvironmentConfig();
envCfg.setAllowCreate(true);
envCfg.setReadOnly(false);
this.bdbEnv = new Environment(this.bdbDir, envCfg);
final DatabaseConfig cfg = new DatabaseConfig();
cfg.setAllowCreate(true);
cfg.setReadOnly(false);
this.beaconDatabase = this.bdbEnv.openDatabase(this.txn, "ga4ghBeaconBuffer", cfg);
}
return doVcfToVcf(args, outputFile);
} catch (final Exception err) {
LOG.error(err);
return -1;
} finally {
CloserUtil.close(beaconDatabase);
CloserUtil.close(bdbEnv);
}
}
Aggregations