use of org.mapdb.DB in project eol-globi-data by jhpoelen.
the class ExporterAggregateUtil method exportDistinctInteractionsByStudy.
public static void exportDistinctInteractionsByStudy(Writer writer, GraphDatabaseService graphDatabase, RowWriter rowWriter) throws IOException {
DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
final Map<Fun.Tuple3<Long, String, String>, List<String>> studyOccAggregate = db.createTreeMap("studyOccAggregate").make();
NodeUtil.findStudies(graphDatabase, new StudyNodeListener() {
@Override
public void onStudy(StudyNode aStudy) {
collectDistinctInteractions(aStudy, studyOccAggregate);
}
});
for (Map.Entry<Fun.Tuple3<Long, String, String>, List<String>> distinctInteractions : studyOccAggregate.entrySet()) {
rowWriter.writeRow(writer, new StudyNode(graphDatabase.getNodeById(distinctInteractions.getKey().a)), distinctInteractions.getKey().b, distinctInteractions.getKey().c, distinctInteractions.getValue());
}
db.close();
}
use of org.mapdb.DB in project eol-globi-data by jhpoelen.
the class TaxonInteractionIndexer method indexInteractions.
public void indexInteractions() {
DB db = DBMaker.newMemoryDirectDB().compressionEnable().transactionDisable().make();
final Map<Fun.Tuple3<Long, String, Long>, Long> taxonInteractions = db.createTreeMap("ottIdMap").make();
collectTaxonInteractions(taxonInteractions);
createTaxonInteractions(taxonInteractions);
db.close();
}
use of org.mapdb.DB in project rskj by rsksmart.
the class DefaultConfig method blockStore.
@Bean
public BlockStore blockStore(RskSystemProperties config) {
String database = config.databaseDir();
File blockIndexDirectory = new File(database + "/blocks/");
File dbFile = new File(blockIndexDirectory, "index");
if (!blockIndexDirectory.exists()) {
boolean mkdirsSuccess = blockIndexDirectory.mkdirs();
if (!mkdirsSuccess) {
logger.error("Unable to create blocks directory: {}", blockIndexDirectory);
}
}
DB indexDB = DBMaker.fileDB(dbFile).closeOnJvmShutdown().make();
Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = indexDB.hashMapCreate("index").keySerializer(Serializer.LONG).valueSerializer(BLOCK_INFO_SERIALIZER).counterEnable().makeOrGet();
KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
blocksDB.init();
IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
return indexedBlockStore;
}
use of org.mapdb.DB in project rskj by rsksmart.
the class IndexedBlockStoreTest method test7.
// leveldb + mapdb, multi branch, total re-branch test
@Test
public void test7() throws IOException {
BigInteger bi = new BigInteger(32, new Random());
String testDir = "test_db_" + bi;
config.setDataBaseDir(testDir);
DB indexDB = createMapDB(testDir);
Map<Long, List<IndexedBlockStore.BlockInfo>> indexMap = createIndexMap(indexDB);
KeyValueDataSource blocksDB = new LevelDbDataSource(config, "blocks");
blocksDB.init();
try {
IndexedBlockStore indexedBlockStore = new IndexedBlockStore(indexMap, blocksDB, indexDB);
Block genesis = Genesis.getInstance(config);
List<Block> bestLine = getRandomChain(genesis.getHash().getBytes(), 1, 100);
indexedBlockStore.saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
BlockDifficulty td = genesis.getCumulativeDifficulty();
for (int i = 0; i < bestLine.size(); ++i) {
Block newBlock = bestLine.get(i);
td = td.add(newBlock.getCumulativeDifficulty());
indexedBlockStore.saveBlock(newBlock, td, true);
}
byte[] forkParentHash = bestLine.get(60).getHash().getBytes();
long forkParentNumber = bestLine.get(60).getNumber();
List<Block> forkLine = getRandomChain(forkParentHash, forkParentNumber + 1, 50);
for (int i = 0; i < forkLine.size(); ++i) {
Block newBlock = forkLine.get(i);
Block parentBlock = indexedBlockStore.getBlockByHash(newBlock.getParentHash().getBytes());
td = indexedBlockStore.getTotalDifficultyForHash(parentBlock.getHash().getBytes());
td = td.add(newBlock.getCumulativeDifficulty());
indexedBlockStore.saveBlock(newBlock, td, false);
}
Block bestBlock = bestLine.get(bestLine.size() - 1);
Block forkBlock = forkLine.get(forkLine.size() - 1);
indexedBlockStore.reBranch(forkBlock);
} finally {
blocksDB.close();
indexDB.close();
FileUtil.recursiveDelete(testDir);
}
}
Aggregations