Search in sources :

Example 1 with DBFactory

use of org.iq80.leveldb.DBFactory in project qi4j-sdk by Qi4j.

the class LevelDBEntityStoreMixin method activateService.

@Override
public void activateService() throws Exception {
    charset = Charset.forName("UTF-8");
    configuration.refresh();
    LevelDBEntityStoreConfiguration config = configuration.get();
    // Choose flavour
    String flavour = config.flavour().get();
    DBFactory factory;
    if ("jni".equalsIgnoreCase(flavour)) {
        factory = newJniDBFactory();
    } else if ("java".equalsIgnoreCase(flavour)) {
        factory = newJavaDBFactory();
    } else {
        factory = newDBFactory();
    }
    // Apply configuration
    Options options = new Options();
    options.createIfMissing(true);
    if (config.blockRestartInterval().get() != null) {
        options.blockRestartInterval(config.blockRestartInterval().get());
    }
    if (config.blockSize().get() != null) {
        options.blockSize(config.blockSize().get());
    }
    if (config.cacheSize().get() != null) {
        options.cacheSize(config.cacheSize().get());
    }
    if (config.compression().get() != null) {
        options.compressionType(config.compression().get() ? CompressionType.SNAPPY : CompressionType.NONE);
    }
    if (config.maxOpenFiles().get() != null) {
        options.maxOpenFiles(config.maxOpenFiles().get());
    }
    if (config.paranoidChecks().get() != null) {
        options.paranoidChecks(config.paranoidChecks().get());
    }
    if (config.verifyChecksums().get() != null) {
        options.verifyChecksums(config.verifyChecksums().get());
    }
    if (config.writeBufferSize().get() != null) {
        options.writeBufferSize(config.writeBufferSize().get());
    }
    // Open/Create the database
    File dbFile = new File(fileConfig.dataDirectory(), descriptor.identity());
    db = factory.open(dbFile, options);
}
Also used : Options(org.iq80.leveldb.Options) DBFactory(org.iq80.leveldb.DBFactory) File(java.io.File)

Aggregations

File (java.io.File)1 DBFactory (org.iq80.leveldb.DBFactory)1 Options (org.iq80.leveldb.Options)1