use of com.sleepycat.je.DatabaseConfig 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.DatabaseConfig 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);
}
}
use of com.sleepycat.je.DatabaseConfig in project jvarkit by lindenb.
the class PubmedOrcidGraph method doWork.
@Override
public int doWork(final List<String> args) {
if (!this.ncbiApiKey.isApiKeyDefined()) {
LOG.error("NCBI API key is not defined");
return -1;
}
InputStream in = null;
XMLEventReader r = null;
try {
// open BDB
final EnvironmentConfig envCfg = new EnvironmentConfig();
envCfg.setAllowCreate(true);
envCfg.setReadOnly(false);
LOG.info("open BDB env...");
this.environment = new Environment(this.bdbDir, envCfg);
LOG.info("open BDB databases...");
final DatabaseConfig config = new DatabaseConfig();
config.setAllowCreate(true);
config.setReadOnly(false);
config.setTemporary(true);
this.authorDatabase = this.environment.openDatabase(txn, "authors", config);
this.articleDatabase = this.environment.openDatabase(txn, "articles", config);
this.linkDatabase = this.environment.openDatabase(txn, "links", config);
if (this.dumpStrangeOrcidFile != null) {
this.errPrintWriter = super.openPathOrStdoutAsPrintStream(this.dumpStrangeOrcidFile);
}
if (this.input_is_orcid_id) {
/* recursively scan authors */
for (final String orcid : args) {
scanOrcid(orcid, 0);
}
while (complete()) {
// run...
}
} else {
/* input is a efetch stream */
final String inputName = oneFileOrNull(args);
in = (inputName == null ? stdin() : IOUtils.openURIForReading(inputName));
scanArticles(in, 0);
in.close();
in = null;
}
dumpGexf();
this.errPrintWriter.flush();
if (this.dumpStrangeOrcidFile != null) {
this.errPrintWriter.close();
}
return 0;
} catch (Exception e) {
LOG.error(e);
return -1;
} finally {
CloserUtil.close(in);
CloserUtil.close(r);
CloserUtil.close(authorDatabase);
CloserUtil.close(articleDatabase);
CloserUtil.close(linkDatabase);
CloserUtil.close(environment);
}
}
use of com.sleepycat.je.DatabaseConfig in project jvarkit by lindenb.
the class PubmedAuthorGraph method doWork.
@Override
public int doWork(final List<String> args) {
if (!this.ncbiApiKey.isApiKeyDefined()) {
LOG.error("NCBI API key is not defined");
return -1;
}
InputStream in = null;
XMLEventReader r = null;
try {
// open BDB
final EnvironmentConfig envCfg = new EnvironmentConfig();
envCfg.setAllowCreate(true);
envCfg.setReadOnly(false);
LOG.info("open BDB env...");
this.environment = new Environment(this.bdbDir, envCfg);
LOG.info("open BDB databases...");
final DatabaseConfig config = new DatabaseConfig();
config.setAllowCreate(true);
config.setReadOnly(false);
config.setTemporary(true);
this.authorDatabase = this.environment.openDatabase(txn, "authors", config);
this.articleDatabase = this.environment.openDatabase(txn, "articles", config);
/* input is a efetch stream */
final String inputName = oneFileOrNull(args);
in = (inputName == null ? stdin() : IOUtils.openURIForReading(inputName));
scanArticles(in);
in.close();
in = null;
dumpGexf();
return 0;
} catch (final Throwable e) {
e.printStackTrace();
LOG.error(e);
return -1;
} finally {
CloserUtil.close(in);
CloserUtil.close(r);
CloserUtil.close(authorDatabase);
CloserUtil.close(articleDatabase);
CloserUtil.close(environment);
}
}
use of com.sleepycat.je.DatabaseConfig 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;
}
Aggregations