Search in sources :

Example 41 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project sessdb by ppdai.

the class BdbBenchmark method open.

@Override
public void open() {
    try {
        EnvironmentConfig envConfig = new EnvironmentConfig();
        envConfig.setAllowCreate(true);
        envConfig.setCachePercent(90);
        File file = new File(databaseDir_);
        if (!file.exists()) {
            file.mkdirs();
        }
        env_ = new Environment(file, envConfig);
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        bdb_ = env_.openDatabase(null, BdbBenchmark.DATABASE_NAME, dbConfig);
    } catch (DatabaseException e) {
        e.printStackTrace();
    }
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) File(java.io.File) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 42 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project vertigo by KleeGroup.

the class BerkeleyKVStorePlugin method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() {
    final boolean readOnly = READONLY;
    ramEnvironment = buildRamEnvironment(new File(dbFilePathTranslated + File.separator + "ram"), readOnly);
    fsEnvironment = buildFsEnvironment(new File(dbFilePathTranslated), readOnly);
    final DatabaseConfig databaseConfig = new DatabaseConfig().setReadOnly(readOnly).setAllowCreate(!readOnly).setTransactional(!readOnly);
    for (final BerkeleyCollectionConfig collectionConfig : collectionConfigs) {
        final BerkeleyDatabase berkeleyDatabase = new BerkeleyDatabase(// select environment (FS or RAM)
        (collectionConfig.isInMemory() ? ramEnvironment : fsEnvironment).openDatabase(null, collectionConfig.getCollectionName(), // open database
        databaseConfig), collectionConfig.getTimeToLiveSeconds(), transactionManager, codecManager);
        databases.put(collectionConfig.getCollectionName(), berkeleyDatabase);
    }
}
Also used : File(java.io.File) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 43 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project sirix by sirixdb.

the class BerkeleyStorageFactory method createStorage.

/**
 * Create a new storage.
 *
 * @param resourceConfig the resource configuration
 * @return the berkeley DB storage
 * @throws NullPointerException if {@link ResourceConfiguration} is {@code null}
 * @throws SirixIOException if the storage couldn't be created because of an I/O exception
 */
public BerkeleyStorage createStorage(final ResourceConfiguration resourceConfig) {
    try {
        final Path repoFile = resourceConfig.mPath.resolve(ResourceConfiguration.ResourcePaths.DATA.getFile());
        if (!Files.exists(repoFile)) {
            Files.createDirectories(repoFile);
        }
        final ByteHandlePipeline byteHandler = checkNotNull(resourceConfig.mByteHandler);
        final DatabaseConfig conf = generateDBConf();
        final EnvironmentConfig config = generateEnvConf();
        final List<Path> path;
        try (final Stream<Path> stream = Files.list(repoFile)) {
            path = stream.collect(toList());
        }
        if (path.isEmpty() || (path.size() == 1 && "sirix.data".equals(path.get(0).getFileName().toString()))) {
            conf.setAllowCreate(true);
            config.setAllowCreate(true);
        }
        final Environment env = new Environment(repoFile.toFile(), config);
        final Database database = env.openDatabase(null, NAME, conf);
        return new BerkeleyStorage(env, database, byteHandler);
    } catch (final DatabaseException | IOException e) {
        throw new SirixIOException(e);
    }
}
Also used : Path(java.nio.file.Path) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) IOException(java.io.IOException) SirixIOException(org.sirix.exception.SirixIOException) SirixIOException(org.sirix.exception.SirixIOException) Database(com.sleepycat.je.Database) Environment(com.sleepycat.je.Environment) ByteHandlePipeline(org.sirix.io.bytepipe.ByteHandlePipeline) DatabaseException(com.sleepycat.je.DatabaseException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 44 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig 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 45 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig 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)

Aggregations

DatabaseConfig (com.sleepycat.je.DatabaseConfig)56 Database (com.sleepycat.je.Database)30 Environment (com.sleepycat.je.Environment)26 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)23 DatabaseEntry (com.sleepycat.je.DatabaseEntry)13 File (java.io.File)12 Transaction (com.sleepycat.je.Transaction)7 Test (org.junit.Test)7 Cursor (com.sleepycat.je.Cursor)6 DatabaseException (com.sleepycat.je.DatabaseException)6 IOException (java.io.IOException)4 Map (java.util.Map)4 StoreException (org.apache.qpid.server.store.StoreException)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 OperationStatus (com.sleepycat.je.OperationStatus)3 HashMap (java.util.HashMap)3 StoredClassCatalog (com.sleepycat.bind.serial.StoredClassCatalog)2 StringBinding (com.sleepycat.bind.tuple.StringBinding)2 TupleInput (com.sleepycat.bind.tuple.TupleInput)2 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)2