Search in sources :

Example 31 with Environment

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);
}
Also used : EnvironmentMutableConfig(com.sleepycat.je.EnvironmentMutableConfig) Environment(com.sleepycat.je.Environment)

Example 32 with Environment

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);
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 33 with Environment

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);
}
Also used : Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 34 with Environment

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();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 35 with Environment

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);
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLEventFactory(javax.xml.stream.XMLEventFactory) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) OutputStream(java.io.OutputStream) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) XMLEventWriter(javax.xml.stream.XMLEventWriter) StringReader(java.io.StringReader) XMLEvent(javax.xml.stream.events.XMLEvent) Environment(com.sleepycat.je.Environment) XMLEventReader(javax.xml.stream.XMLEventReader) File(java.io.File) XMLInputFactory(javax.xml.stream.XMLInputFactory) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

Environment (com.sleepycat.je.Environment)38 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)20 DatabaseConfig (com.sleepycat.je.DatabaseConfig)18 File (java.io.File)15 Database (com.sleepycat.je.Database)10 DatabaseException (com.sleepycat.je.DatabaseException)9 DatabaseEntry (com.sleepycat.je.DatabaseEntry)5 Transaction (com.sleepycat.je.Transaction)5 IOException (java.io.IOException)5 Cursor (com.sleepycat.je.Cursor)3 EnvironmentMutableConfig (com.sleepycat.je.EnvironmentMutableConfig)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 VoldemortException (voldemort.VoldemortException)3 CheckpointConfig (com.sleepycat.je.CheckpointConfig)2 StatsConfig (com.sleepycat.je.StatsConfig)2 ReplicatedEnvironment (com.sleepycat.je.rep.ReplicatedEnvironment)2 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)2 LineIterator (htsjdk.tribble.readers.LineIterator)2 BdbDbCreationException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException)2