org.mapdb.DB Java Examples
The following examples show how to use
org.mapdb.DB.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockMap.java From Qora with MIT License | 6 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) protected void createIndexes(DB database) { //HEIGHT INDEX Tuple2Comparator<Integer, byte[]> comparator = new Fun.Tuple2Comparator<Integer, byte[]>(Fun.COMPARATOR, UnsignedBytes.lexicographicalComparator()); NavigableSet<Tuple2<Integer, byte[]>> heightIndex = database.createTreeSet("blocks_index_height") .comparator(comparator) .makeOrGet(); NavigableSet<Tuple2<Integer, byte[]>> descendingHeightIndex = database.createTreeSet("blocks_index_height_descending") .comparator(new ReverseComparator(comparator)) .makeOrGet(); createIndex(HEIGHT_INDEX, heightIndex, descendingHeightIndex, new Fun.Function2<Integer, byte[], Block>() { @Override public Integer run(byte[] key, Block value) { return value.getHeight(); } }); }
Example #2
Source File: Huge_Read.java From scava with Eclipse Public License 2.0 | 6 votes |
public static void main(String[] args){ DB db = DBMaker.newFileDB(new File("/tmp/db2")) .journalDisable() //.asyncWriteDisable() .make(); Map<Integer, String> map = db.getTreeMap("map"); long time = System.currentTimeMillis(); long max = (int) 1e8; long step = max/100; for(int i=0;i<max;i++){ map.get(i); if(i%step == 0){ System.out.println(100.0 * i/max); } } System.out.println("Closing"); db.close(); System.out.println(System.currentTimeMillis() - time); }
Example #3
Source File: BlockMap.java From Qora with MIT License | 6 votes |
public BlockMap(DBSet databaseSet, DB database) { super(databaseSet, database); this.observableData.put(DBMap.NOTIFY_ADD, ObserverMessage.ADD_BLOCK_TYPE); this.observableData.put(DBMap.NOTIFY_REMOVE, ObserverMessage.REMOVE_BLOCK_TYPE); this.observableData.put(DBMap.NOTIFY_LIST, ObserverMessage.LIST_BLOCK_TYPE); //LAST BLOCK this.lastBlockVar = database.getAtomicVar("lastBlock"); this.lastBlockSignature = lastBlockVar.get(); //PROCESSING this.processingVar = database.getAtomicVar("processingBlock"); this.processing = processingVar.get(); }
Example #4
Source File: PersistentCacheConfig.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
@NotNull @Override public DB createCache(@NotNull Path basePath) throws IOException { final Path cacheBase = ConfigHelper.joinPath(basePath, path); Files.createDirectories(cacheBase.getParent()); try { final DBMaker.Maker maker = DBMaker.fileDB(cacheBase.toFile()) .closeOnJvmShutdown() .fileMmapEnableIfSupported(); if (enableTransactions) maker.transactionEnable(); return maker .make(); } catch (DBException e) { throw new DBException(String.format("Failed to open %s: %s", cacheBase, e.getMessage()), e); } }
Example #5
Source File: StreamSortedWindowInMapDB.java From eagle with Apache License 2.0 | 6 votes |
/** * @param mapId physical map id, used to decide whether to reuse or not. */ @SuppressWarnings("unused") public StreamSortedWindowInMapDB(long start, long end, long margin, DB db, String mapId) { super(start, end, margin); this.mapId = mapId; try { btreeMap = db.<Long, StreamEvent>treeMap(mapId) .keySerializer(Serializer.LONG) .valueSerializer(STREAM_EVENT_GROUP_SERIALIZER) .createOrOpen(); LOG.debug("Created BTree map {}", mapId); } catch (Error error) { LOG.info("Failed create BTree {}", mapId, error); } size = new AtomicInteger(0); }
Example #6
Source File: StoreTest.java From TarsosLSH with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testStore(){ DB db = DBMaker.memoryDB().make(); NavigableSet<long[]> treeSet = db.treeSet("tree", Serializer.LONG_ARRAY ).createOrOpen(); long[] e = {7,78,78}; long[] f = {7,12,78}; long[] g = {9,78,78}; long[] h = {6,78,78}; long[] i = {7,1,78}; treeSet.add(e); treeSet.add(f); treeSet.add(g); treeSet.add(h); treeSet.add(i); long[] k = {7,0,0}; long[] l = {7,Integer.MAX_VALUE,Integer.MAX_VALUE}; assertEquals(3,treeSet.subSet(k, l).size()); for(long[] element : treeSet.subSet(k, l)){ System.out.println(element[1]); } }
Example #7
Source File: MapDBTestSuite.java From eagle with Apache License 2.0 | 6 votes |
@Test public void testOnHeapDB() { DB db = DBMaker.heapDB().make(); BTreeMap<Long, String> map = db.treeMap("btree").keySerializer(Serializer.LONG).valueSerializer(Serializer.STRING).create(); Assert.assertFalse(map.putIfAbsentBoolean(1L, "val_1")); Assert.assertTrue(map.putIfAbsentBoolean(1L, "val_2")); Assert.assertTrue(map.putIfAbsentBoolean(1L, "val_3")); Assert.assertFalse(map.putIfAbsentBoolean(2L, "val_4")); Assert.assertEquals("val_1", map.get(1L)); Assert.assertEquals("val_4", map.get(2L)); Assert.assertTrue(map.replace(2L, "val_4", "val_5")); Assert.assertEquals("val_5", map.get(2L)); map.close(); db.close(); }
Example #8
Source File: TransactionMap.java From Qora with MIT License | 6 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) protected void createIndexes(DB database) { //TIMESTAMP INDEX Tuple2Comparator<Long, byte[]> comparator = new Fun.Tuple2Comparator<Long, byte[]>(Fun.COMPARATOR, UnsignedBytes.lexicographicalComparator()); NavigableSet<Tuple2<Integer, byte[]>> heightIndex = database.createTreeSet("transactions_index_timestamp") .comparator(comparator) .makeOrGet(); NavigableSet<Tuple2<Integer, byte[]>> descendingHeightIndex = database.createTreeSet("transactions_index_timestamp_descending") .comparator(new ReverseComparator(comparator)) .makeOrGet(); createIndex(TIMESTAMP_INDEX, heightIndex, descendingHeightIndex, new Fun.Function2<Long, byte[], Transaction>() { @Override public Long run(byte[] key, Transaction value) { return value.getTimestamp(); } }); }
Example #9
Source File: DBMap.java From Qora with MIT License | 5 votes |
public DBMap(IDB databaseSet, DB database) { this.databaseSet = databaseSet; //OPEN MAP this.map = this.getMap(database); //CREATE INDEXES this.indexes = new HashMap<Integer, NavigableSet<Tuple2<?, T>>>(); this.createIndexes(database); }
Example #10
Source File: NameExchangeMap.java From Qora with MIT License | 5 votes |
@Override protected Map<String, BigDecimal> getMap(DB database) { //OPEN MAP return database.createTreeMap("namesales") .counterEnable() .makeOrGet(); }
Example #11
Source File: AssetMap.java From Qora with MIT License | 5 votes |
@Override protected Map<Long, Asset> getMap(DB database) { //OPEN MAP return database.createTreeMap("assets") .valueSerializer(new AssetSerializer()) .makeOrGet(); }
Example #12
Source File: BlockMap.java From Qora with MIT License | 5 votes |
public BlockMap(WalletDatabase walletDatabase, DB database) { super(walletDatabase, database); this.observableData.put(DBMap.NOTIFY_ADD, ObserverMessage.ADD_BLOCK_TYPE); this.observableData.put(DBMap.NOTIFY_REMOVE, ObserverMessage.REMOVE_BLOCK_TYPE); this.observableData.put(DBMap.NOTIFY_LIST, ObserverMessage.LIST_BLOCK_TYPE); }
Example #13
Source File: AssetMap.java From Qora with MIT License | 5 votes |
public AssetMap(DBSet databaseSet, DB database) { super(databaseSet, database); this.atomicKey = database.getAtomicLong("assets_key"); this.key = this.atomicKey.get(); this.observableData.put(DBMap.NOTIFY_ADD, ObserverMessage.ADD_ASSET_TYPE); this.observableData.put(DBMap.NOTIFY_REMOVE, ObserverMessage.REMOVE_ASSET_TYPE); this.observableData.put(DBMap.NOTIFY_LIST, ObserverMessage.LIST_ASSET_TYPE); }
Example #14
Source File: OrderMap.java From Qora with MIT License | 5 votes |
public OrderMap(DBSet databaseSet, DB database) { super(databaseSet, database); this.observableData.put(DBMap.NOTIFY_ADD, ObserverMessage.ADD_ORDER_TYPE); this.observableData.put(DBMap.NOTIFY_REMOVE, ObserverMessage.REMOVE_ORDER_TYPE); //this.observableData.put(DBMap.NOTIFY_LIST, ObserverMessage.LIST_ORDER_TYPE); }
Example #15
Source File: OrderMap.java From Qora with MIT License | 5 votes |
@Override protected Map<BigInteger, Order> getMemoryMap() { DB database = DBMaker.newMemoryDB().make(); //OPEN MAP return this.openMap(database); }
Example #16
Source File: NameSaleMap.java From Qora with MIT License | 5 votes |
@Override protected Map<Tuple2<String, String>, BigDecimal> getMap(DB database) { //OPEN MAP return database.createTreeMap("namesales") .keySerializer(BTreeKeySerializer.TUPLE2) .counterEnable() .makeOrGet(); }
Example #17
Source File: CancelOrderMap.java From Qora with MIT License | 5 votes |
@Override protected Map<byte[], Order> getMap(DB database) { //OPEN MAP return database.createTreeMap("cancelOrderOrphanData") .keySerializer(BTreeKeySerializer.BASIC) .valueSerializer(new OrderSerializer()) .comparator(UnsignedBytes.lexicographicalComparator()) .makeOrGet(); }
Example #18
Source File: StatisticDataRepositoryMapDB.java From AisAbnormal with GNU Lesser General Public License v3.0 | 5 votes |
private static DB openDiskDatabaseForRead(File dbFile) { LOG.debug("Trying to open " + dbFile.getAbsolutePath() + " for read only."); DB db; db = DBMaker .newFileDB(dbFile) .transactionDisable() .closeOnJvmShutdown() .readOnly() .make(); LOG.info("Opened disk-based database (\"" + dbFile.getName() + "\") for read only."); return db; }
Example #19
Source File: DatabaseIndexTests.java From Qora with MIT License | 5 votes |
@Test public void databaseFork() { //CREATE DATABASE DB database = DBMaker.newTempFileDB().make(); //CREATE NAMEDATABASE NameMap nameDB = new NameMap(null, database); //CREATE NAMES Name nameA = new Name(new Account("b"), "a", "a"); Name nameB = new Name(new Account("a"), "b", "b"); //ADD TO DB nameDB.set("a", nameA); nameDB.set("b", nameB); //CHECK IF ADDED SUCCESSFULLY Assert.assertEquals(nameDB.get("a").getValue(), "a"); Assert.assertEquals(nameDB.get("b").getValue(), "b"); //GET INDEXED LIST SortableList<String, Name> list = new SortableList<String, Name>(nameDB); //GET VALUES BY DEFAULT INDEX Assert.assertEquals(list.get(0).getA(), "a"); Assert.assertEquals(list.get(1).getA(), "b"); Assert.assertEquals(list.get(0).getA(), "a"); //GET VALUES BY OWNER INDEX list.sort(NameMap.DEFAULT_INDEX); Assert.assertEquals(list.get(0).getA(), "b"); Assert.assertEquals(list.get(1).getA(), "a"); Assert.assertEquals(list.get(0).getA(), "b"); }
Example #20
Source File: CompletedOrderMap.java From Qora with MIT License | 5 votes |
public CompletedOrderMap(DBSet databaseSet, DB database) { super(databaseSet, database); this.observableData.put(DBMap.NOTIFY_ADD, ObserverMessage.ADD_ORDER_TYPE); this.observableData.put(DBMap.NOTIFY_REMOVE, ObserverMessage.REMOVE_ORDER_TYPE); //this.observableData.put(DBMap.NOTIFY_LIST, ObserverMessage.LIST_ORDER_TYPE); }
Example #21
Source File: IssueAssetMap.java From Qora with MIT License | 5 votes |
@Override protected Map<byte[], Long> getMap(DB database) { //OPEN MAP return database.createTreeMap("IssueAssetOrphanData") .keySerializer(BTreeKeySerializer.BASIC) .comparator(UnsignedBytes.lexicographicalComparator()) .makeOrGet(); }
Example #22
Source File: DBSet.java From Qora with MIT License | 5 votes |
public static DBSet createEmptyDatabaseSet() { DB database = DBMaker.newMemoryDB() .make(); return new DBSet(database); }
Example #23
Source File: CompletedOrderMap.java From Qora with MIT License | 5 votes |
@Override protected Map<BigInteger, Order> getMemoryMap() { DB database = DBMaker.newMemoryDB().make(); //OPEN MAP return this.openMap(database); }
Example #24
Source File: CompletedOrderMap.java From Qora with MIT License | 5 votes |
private Map<BigInteger, Order> openMap(DB database) { //OPEN MAP BTreeMap<BigInteger, Order> map = database.createTreeMap("completedorders") .valueSerializer(new OrderSerializer()) .makeOrGet(); //RETURN return map; }
Example #25
Source File: PollMap.java From Qora with MIT License | 5 votes |
public PollMap(DBSet databaseSet, DB database) { super(databaseSet, database); this.observableData.put(DBMap.NOTIFY_ADD, ObserverMessage.ADD_POLL_TYPE); this.observableData.put(DBMap.NOTIFY_REMOVE, ObserverMessage.REMOVE_POLL_TYPE); this.observableData.put(DBMap.NOTIFY_LIST, ObserverMessage.LIST_POLL_TYPE); }
Example #26
Source File: TradeMap.java From Qora with MIT License | 5 votes |
@Override protected Map<Tuple2<BigInteger, BigInteger>, Trade> getMemoryMap() { DB database = DBMaker.newMemoryDB().make(); //OPEN MAP return this.openMap(database); }
Example #27
Source File: PollMap.java From Qora with MIT License | 5 votes |
@Override protected Map<String, Poll> getMap(DB database) { //OPEN MAP return database.createTreeMap("polls") .valueSerializer(new PollSerializer()) .counterEnable() .makeOrGet(); }
Example #28
Source File: AssetFavoritesSet.java From Qora with MIT License | 5 votes |
public AssetFavoritesSet(WalletDatabase walletDatabase, DB database) { this.walletDatabase = walletDatabase; //OPEN MAP this.assetsSet = database.getTreeSet("assetFavorites"); //CHECK IF CONTAINS QORA if(!this.assetsSet.contains(0l)) { this.add(0l); } }
Example #29
Source File: TransactionMap.java From Qora with MIT License | 5 votes |
@Override protected Map<Tuple2<String, String>, Transaction> getMap(DB database) { //OPEN MAP return database.createTreeMap("transactions") .keySerializer(BTreeKeySerializer.TUPLE2) .valueSerializer(new TransactionSerializer()) .counterEnable() .makeOrGet(); }
Example #30
Source File: CancelSellNameMap.java From Qora with MIT License | 5 votes |
@Override protected Map<byte[], BigDecimal> getMap(DB database) { //OPEN MAP return database.createTreeMap("cancelNameOrphanData") .keySerializer(BTreeKeySerializer.BASIC) .comparator(UnsignedBytes.lexicographicalComparator()) .makeOrGet(); }