Search in sources :

Example 16 with DatabaseConfig

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);
    }
}
Also used : PrintStream(java.io.PrintStream) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) LineIterator(htsjdk.tribble.readers.LineIterator) Stack(java.util.Stack) Transaction(com.sleepycat.je.Transaction) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 17 with DatabaseConfig

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);
    }
}
Also used : EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Environment(com.sleepycat.je.Environment) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) CertificateException(java.security.cert.CertificateException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 18 with DatabaseConfig

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) XMLEventReader(javax.xml.stream.XMLEventReader) Environment(com.sleepycat.je.Environment) XMLStreamException(javax.xml.stream.XMLStreamException) JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) IOException(java.io.IOException) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 19 with DatabaseConfig

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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) XMLEventReader(javax.xml.stream.XMLEventReader) Environment(com.sleepycat.je.Environment) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 20 with DatabaseConfig

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;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) 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