use of com.sleepycat.je.Environment in project qpid-broker-j by apache.
the class StandardEnvironmentFacade method setCacheSize.
@Override
public void setCacheSize(long cacheSize) {
Environment environment = getEnvironment();
EnvironmentMutableConfig mutableConfig = environment.getMutableConfig();
mutableConfig.setCacheSize(cacheSize);
environment.setMutableConfig(mutableConfig);
}
use of com.sleepycat.je.Environment in project bboxdb by jnidzwetzki.
the class FileLineIndex method openDatabase.
/**
* Open the Berkeley DB
* @throws IOException
*/
protected void openDatabase() throws IOException {
final EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setTransactional(false);
envConfig.setAllowCreate(true);
envConfig.setSharedCache(true);
tmpDatabaseDir = Files.createTempDirectory(null);
dbEnv = new Environment(tmpDatabaseDir.toFile(), envConfig);
logger.info("Database dir is {}", tmpDatabaseDir);
// Delete database on exit
FileUtil.deleteDirOnExit(tmpDatabaseDir);
final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(false);
dbConfig.setAllowCreate(true);
dbConfig.setDeferredWrite(true);
database = dbEnv.openDatabase(null, "lines", dbConfig);
}
use of com.sleepycat.je.Environment in project bboxdb by jnidzwetzki.
the class OSMBDBNodeStore method initNewBDBEnvironment.
/**
* Init a new BDB environment in the given folder
* @param folder
*/
@SuppressWarnings("unused")
protected void initNewBDBEnvironment(final File folder, final EnvironmentConfig envConfig) {
final Environment dbEnv = new Environment(folder, envConfig);
Transaction txn = null;
if (USE_TRANSACTIONS) {
txn = dbEnv.beginTransaction(null, null);
}
final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(USE_TRANSACTIONS);
dbConfig.setAllowCreate(true);
dbConfig.setSortedDuplicates(true);
dbConfig.setDeferredWrite(true);
// dbConfig.setKeyPrefixing(true);
// dbConfig.setNodeMaxEntries(128);
final Database database = dbEnv.openDatabase(txn, "osm", dbConfig);
if (txn != null) {
txn.commit();
}
environments.add(dbEnv);
databases.add(database);
}
use of com.sleepycat.je.Environment in project bboxdb by jnidzwetzki.
the class BDBTupleStore method open.
@Override
public void open() throws Exception {
final EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setTransactional(USE_TRANSACTIONS);
envConfig.setAllowCreate(true);
environment = new Environment(dir, envConfig);
Transaction txn = null;
if (USE_TRANSACTIONS) {
txn = environment.beginTransaction(null, null);
}
final DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(USE_TRANSACTIONS);
dbConfig.setAllowCreate(true);
// dbConfig.setSortedDuplicates(true);
dbConfig.setDeferredWrite(true);
// dbConfig.setKeyPrefixing(true);
// dbConfig.setNodeMaxEntries(128);
database = environment.openDatabase(txn, "test", dbConfig);
if (txn != null) {
txn.commit();
}
}
use of com.sleepycat.je.Environment in project jvarkit by lindenb.
the class NgsFilesScanner method doWork.
@Override
public int doWork(List<String> args) {
boolean dump = false;
EnvironmentConfig envCfg = new EnvironmentConfig();
Environment env = null;
if (bdbHome == null) {
LOG.error("BDB home undefined");
return -1;
}
if (!bdbHome.exists() || !bdbHome.isDirectory()) {
LOG.error("BDB doesn't exist or is not a directory");
return -1;
}
File root = new File("/");
Cursor cursor = null;
OutputStream xmlout = null;
try {
if (!dump && args.size() == 1) {
root = new File(args.get(0));
} else if (!(dump && args.isEmpty())) {
LOG.error("illegal.number.of.arguments");
return -1;
}
envCfg.setAllowCreate(!dump);
envCfg.setReadOnly(dump);
envCfg.setTransactional(false);
LOG.info("Opening env " + bdbHome);
env = new Environment(bdbHome, envCfg);
// TransactionConfig txnCfg=new TransactionConfig();
// this.txn=env.beginTransaction(null, txnCfg);
LOG.info("Opening database " + DATABASE_NAME);
DatabaseConfig cfg = new DatabaseConfig();
cfg.setAllowCreate(!dump);
cfg.setReadOnly(dump);
cfg.setTransactional(false);
this.database = env.openDatabase(this.txn, DATABASE_NAME, cfg);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
if (dump) {
XMLEventFactory xef = XMLEventFactory.newFactory();
XMLOutputFactory xof = XMLOutputFactory.newFactory();
XMLInputFactory xif = XMLInputFactory.newFactory();
xmlout = openFileOrStdoutAsStream(outputFile);
XMLEventWriter out = xof.createXMLEventWriter(xmlout, "UTF-8");
out.add(xef.createStartDocument("UTF-8", "1.0"));
out.add(xef.createStartElement("", "", "ngs-files"));
cursor = this.database.openCursor(this.txn, null);
while (cursor.getNext(key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
File file = new File(StringBinding.entryToString(key));
if (isEntryShouldBeDeleted(file)) {
LOG.info("deleting entry for " + file);
// cursor.delete();//no env is read only
continue;
}
StringReader sr = new StringReader(StringBinding.entryToString(data));
XMLEventReader xr = xif.createXMLEventReader(sr);
while (xr.hasNext()) {
XMLEvent evt = xr.nextEvent();
if (evt.isStartDocument())
continue;
if (evt.isEndDocument())
break;
out.add(evt);
}
xr.close();
sr.close();
}
cursor.close();
out.add(xef.createEndElement("", "", "ngs-files"));
out.add(xef.createEndDocument());
out.flush();
out.close();
xmlout.flush();
xmlout.close();
xmlout = null;
} else {
recursive(root);
// final cleanup
cursor = this.database.openCursor(this.txn, null);
while (cursor.getNext(key, data, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
File file = new File(StringBinding.entryToString(key));
if (isEntryShouldBeDeleted(file)) {
LOG.info("deleting entry for " + file);
cursor.delete();
}
}
cursor.close();
}
return 0;
} catch (Exception err) {
LOG.error(err);
return -1;
} finally {
if (cursor != null)
try {
cursor.close();
} catch (Exception err) {
}
if (this.txn != null)
try {
this.txn.commit();
} catch (Exception err) {
}
if (this.database != null)
try {
this.database.close();
} catch (Exception err) {
}
if (env != null)
try {
env.close();
} catch (Exception err) {
}
CloserUtil.close(xmlout);
}
}
Aggregations