org.mapdb.Serializer Java Examples
The following examples show how to use
org.mapdb.Serializer.
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: GitConverter.java From git-lfs-migrate with MIT License | 6 votes |
public GitConverter(@NotNull DB cache, @NotNull Path basePath, @NotNull String[] globs) throws IOException, InvalidPatternException { this.basePath = basePath; this.cache = cache; this.globs = globs.clone(); this.matchers = convertGlobs(globs); Arrays.sort(globs); for (String glob : globs) { new FileNameMatcher(glob, '/'); } tempPath = basePath.resolve("lfs/tmp"); Files.createDirectories(tempPath); //noinspection unchecked cacheMeta = cache.<String, MetaData>hashMap("meta") .keySerializer(Serializer.STRING) .valueSerializer(new SerializerJava()) .createOrOpen(); }
Example #2
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 #3
Source File: GitRepository.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
public GitRepository(@NotNull LocalContext context, @NotNull Repository git, @NotNull GitPusher pusher, @NotNull Set<String> branches, boolean renameDetection, @NotNull LockStorage lockStorage, @NotNull GitFilters filters) throws IOException { this.context = context; final SharedContext shared = context.getShared(); shared.getOrCreate(GitSubmodules.class, GitSubmodules::new).register(git); this.git = git; db = shared.getCacheDB(); this.binaryCache = db.hashMap("cache.binary", Serializer.STRING, Serializer.BOOLEAN).createOrOpen(); this.pusher = pusher; this.renameDetection = renameDetection; this.lockStorage = lockStorage; this.gitFilters = filters; for (String branch : branches) this.branches.put(StringHelper.normalizeDir(branch), new GitBranch(this, branch)); }
Example #4
Source File: CacheRevisionSerializer.java From git-as-svn with GNU General Public License v2.0 | 6 votes |
@Override public CacheRevision deserialize(@NotNull DataInput2 input, int available) throws IOException { final ObjectId objectId = input.readBoolean() ? ObjectIdSerializer.instance.deserialize(input, available) : null; final Map<String, String> renames = new TreeMap<>(); final int renamesCount = input.readInt(); for (int i = 0; i < renamesCount; ++i) { renames.put(Serializer.STRING.deserialize(input, available), Serializer.STRING.deserialize(input, available)); } final Map<String, CacheChange> fileChange = new TreeMap<>(); final int fileChangeCount = input.readInt(); for (int i = 0; i < fileChangeCount; ++i) { final String name = Serializer.STRING.deserialize(input, available); final ObjectId oldFile = input.readBoolean() ? ObjectIdSerializer.instance.deserialize(input, available) : null; final ObjectId newFile = input.readBoolean() ? ObjectIdSerializer.instance.deserialize(input, available) : null; fileChange.put(name, new CacheChange(oldFile, newFile)); } return new CacheRevision(objectId, renames, fileChange); }
Example #5
Source File: RCDB.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
public Table(MultiStateConfSpace.State state, Sequence seq, String id) { this.state = state; this.seq = seq; this.id = id; // assign ids to all the rcs rcIds = new int[state.confSpace.positions.size()][]; int nextId = 0; for (SimpleConfSpace.Position pos : state.confSpace.positions) { rcIds[pos.index] = new int[pos.resConfs.size()]; for (SimpleConfSpace.ResidueConf rc : pos.resConfs) { rcIds[pos.index][rc.index] = nextId++; } } // open the table map = db.hashMap(id) .keySerializer(Serializer.INTEGER) .valueSerializer(new MapDBTools.BigDecimalBoundsSerializer()) .createOrOpen(); }
Example #6
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 #7
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 #8
Source File: AbstractProcessorGroupByExpressions.java From FortifyBugTrackerUtility with MIT License | 6 votes |
/** * If grouping is enabled, initialize the temporary cache that will hold grouped objects. */ @SuppressWarnings("unchecked") @Override protected final boolean preProcess(Context context) { if ( isGroupingEnabled(context) ) { IContextGrouping ctx = context.as(IContextGrouping.class); DB db = DBMaker.tempFileDB() .closeOnJvmShutdown().fileDeleteAfterClose() .fileMmapEnableIfSupported() .make(); Map<String, List<Object>> groups = db.hashMap("groups", Serializer.STRING, Serializer.JAVA).create(); groups.clear(); // Make sure that we start with a clean cache ctx.setGroupByExpressionsMapDB(db); ctx.setGroupByExpressionsGroupsMap(groups); } return preProcessBeforeGrouping(context); }
Example #9
Source File: DigiMorph.java From tint with GNU General Public License v3.0 | 6 votes |
public DigiMorph(String model_path) { if (model_path == null) { try { File file = File.createTempFile("mapdb", "mapdb"); file.deleteOnExit(); byte[] bytes = Resources.toByteArray(Resources.getResource("italian.db")); Files.write(file.toPath(), bytes); model_path = file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); } } this.model_path = model_path; volume = MappedFileVol.FACTORY.makeVolume(model_path, true); this.map = SortedTableMap.open(volume, Serializer.STRING, Serializer.STRING); }
Example #10
Source File: InverseDigiMorph.java From tint with GNU General Public License v3.0 | 6 votes |
public InverseDigiMorph(String model_path) { if (model_path == null) { try { File file = File.createTempFile("mapdb", "mapdb"); file.deleteOnExit(); byte[] bytes = Resources.toByteArray(Resources.getResource("inverse-italian.db")); Files.write(file.toPath(), bytes); model_path = file.getAbsolutePath(); } catch (IOException e) { e.printStackTrace(); } } this.model_path = model_path; volume = MappedFileVol.FACTORY.makeVolume(model_path, true); this.map = SortedTableMap.open(volume, Serializer.STRING, Serializer.STRING); }
Example #11
Source File: RafsStrategy.java From Panako with GNU Affero General Public License v3.0 | 6 votes |
public RafsStrategy(){ String mapsDBFileName = Config.get(Key.RAFS_DATABASE); int searchRadius = Config.getInt(Key.RAFS_HAMMINNG_SEARCH_RADIUS); int chunks = Config.getInt(Key.RAFS_MIH_CHUNKS); int numBits = Config.getInt(Key.RAFS_HAMMING_SPACE_NUM_BITS); mih = new MultiIndexHasher(numBits, searchRadius, chunks, new MapDBStorage(chunks,mapsDBFileName)); File dbFile = new File(Config.get(Key.RAFS_DATABASE) + "desc.db"); db = DBMaker.fileDB(dbFile) .closeOnJvmShutdown() // close the database automatically .make(); final String audioStore = "audio_store"; // The meta-data store. audioNameStore = db.treeMap(audioStore).keySerializer(Serializer.INTEGER).valueSerializer(Serializer.STRING) .counterEnable() // enable size counter .createOrOpen(); }
Example #12
Source File: ChromaPrintStrategy.java From Panako with GNU Affero General Public License v3.0 | 6 votes |
public ChromaPrintStrategy() { String chomaprintDBFileName = "chormaprint.db"; File dbFile = new File(chomaprintDBFileName); db = DBMaker.fileDB(dbFile) .closeOnJvmShutdown() // close the database automatically .make(); final String chromaPrintStoreName = "chroma_print_store"; // The meta-data store. chromaPrintStore = db.treeMap(chromaPrintStoreName) .keySerializer(Serializer.LONG) .valueSerializer(Serializer.STRING) .counterEnable() // enable size counter .createOrOpen(); // The meta-data store. final String audioStoreName = "audio_store"; audioNameStore = db.treeMap(audioStoreName) .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.STRING) .counterEnable() // enable size counter .createOrOpen(); }
Example #13
Source File: MapDBStorage.java From TarsosLSH with GNU Lesser General Public License v3.0 | 5 votes |
public MapDBStorage(int numberOfTables,String fileName){ hashtables = new ArrayList<>(); db = DBMaker.fileDB(fileName).fileMmapEnable().closeOnJvmShutdown().make(); for(int i = 0 ; i < numberOfTables ; i++){ HTreeMap<Integer, long[]> map = db.hashMap("map_"+i) .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.LONG_ARRAY) .counterEnable() .createOrOpen(); hashtables.add(map); } }
Example #14
Source File: InMemoryModesUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenDBCreatedBaseOnDirectByteBuffer_whenUsed_checkUsageCorrect() { DB heapDB = DBMaker.memoryDirectDB().make(); HTreeMap<Integer, String> map = heapDB .hashMap("myMap") .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.STRING) .createOrOpen(); map.put(1, "ONE"); assertEquals("ONE", map.get(1)); }
Example #15
Source File: InMemoryModesUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenDBCreatedBaseOnByteArray_whenUsed_checkUsageCorrect() { DB heapDB = DBMaker.memoryDB().make(); HTreeMap<Integer, String> map = heapDB .hashMap("myMap") .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.STRING) .createOrOpen(); map.put(1, "ONE"); assertEquals("ONE", map.get(1)); }
Example #16
Source File: MapDBSortedMap.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 5 votes |
public MapDBSortedMap(File f) { this.db = DBMaker.fileDB(f).closeOnJvmShutdown().transactionEnable().make(); this.treeMap = db.treeMap(f.getName()) .keySerializer(Serializer.LONG) .valueSerializer(Serializer.BYTE_ARRAY) .createOrOpen(); }
Example #17
Source File: MapDBHashMap.java From yacy_grid_mcp with GNU Lesser General Public License v2.1 | 5 votes |
public MapDBHashMap(File f) { this.db = DBMaker.fileDB(f).closeOnJvmShutdown().transactionEnable().make(); this.hashMap = db.hashMap(f.getName()) .keySerializer(Serializer.STRING) .valueSerializer(Serializer.STRING) .createOrOpen(); }
Example #18
Source File: LocalLockManager.java From git-as-svn with GNU General Public License v2.0 | 5 votes |
@NotNull public static SortedMap<String, LockDesc> getPersistentStorage(@NotNull LocalContext context) { final String lockCacheName = String.format("locks.%s.%s", context.getName(), lockDescCacheVersion); return context.getShared().getCacheDB().treeMap( lockCacheName, Serializer.STRING, LockDescSerializer.instance ).createOrOpen(); }
Example #19
Source File: SortedTableMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void givenValidSortedTableMapSetup_whenQueried_checkValuesCorrect() { //create memory mapped volume, readonly false Volume vol = MappedFileVol.FACTORY.makeVolume(VOLUME_LOCATION, false); //create sink to feed the map with data SortedTableMap.Sink<Integer, String> sink = SortedTableMap.create( vol, Serializer.INTEGER, Serializer.STRING ).createFromSink(); //add content for(int i = 0; i < 100; i++){ sink.put(i, "Value " + Integer.toString(i)); } sink.create(); //now open in read-only mode Volume openVol = MappedFileVol.FACTORY.makeVolume(VOLUME_LOCATION, true); SortedTableMap<Integer, String> sortedTableMap = SortedTableMap.open( openVol, Serializer.INTEGER, Serializer.STRING ); assertEquals(100, sortedTableMap.size()); }
Example #20
Source File: MapDBImpl.java From RxCache with Apache License 2.0 | 5 votes |
public MapDBImpl(File dbFile, Converter converter) { this.converter = converter; db = DBMaker .fileDB(dbFile) .fileMmapEnableIfSupported() .make(); map = db.hashMap("rxcache", Serializer.STRING,Serializer.JAVA) .createOrOpen(); }
Example #21
Source File: MapDBImpl.java From RxCache with Apache License 2.0 | 5 votes |
public MapDBImpl(long maxSize, MapDBCacheConfig cacheConfig) { super(maxSize); db = DBMaker.heapDB() .make(); map = db.hashMap("rxcache",Serializer.STRING,Serializer.JAVA) .expireMaxSize(maxSize) .expireAfterCreate(cacheConfig.expireDuration,cacheConfig.expireTimeUnit) .expireAfterUpdate(cacheConfig.expireDuration,cacheConfig.expireTimeUnit) .expireAfterGet(cacheConfig.expireAfterGetDuration,cacheConfig.expireAfterGetTimeUnit) .counterEnable() .create(); this.cacheStatistics = new CacheStatistics((int)maxSize); }
Example #22
Source File: MapDBImpl.java From RxCache with Apache License 2.0 | 5 votes |
public MapDBImpl(long maxSize) { super(maxSize); db = DBMaker.heapDB() .make(); map = db.hashMap("rxcache",Serializer.STRING,Serializer.JAVA) .expireMaxSize(maxSize) .expireAfterCreate() .expireAfterUpdate() .expireAfterGet() .counterEnable() .create(); this.cacheStatistics = new CacheStatistics((int)maxSize); }
Example #23
Source File: PersistentSet.java From onos with Apache License 2.0 | 5 votes |
public PersistentSet(org.onosproject.store.service.Serializer serializer, DB database, String name) { this.serializer = checkNotNull(serializer); this.database = checkNotNull(database); this.name = checkNotNull(name); items = database .createHashSet(name) .serializer(Serializer.BYTE_ARRAY) .hasher(Hasher.BYTE_ARRAY) .makeOrGet(); }
Example #24
Source File: RafsRepStrategy.java From Panako with GNU Affero General Public License v3.0 | 5 votes |
public RafsRepStrategy(){ fftDuration = Config.getFloat(Key.RAFS_FFT_STEP_SIZE)/Config.getFloat(Key.RAFS_SAMPLE_RATE); String mapsDBFileName = Config.get(Key.RAFS_DATABASE); //int searchRadius = Config.getInt(Key.RAFS_HAMMINNG_SEARCH_RADIUS); File dbFile = new File(mapsDBFileName + ".repl.db"); db = DBMaker.fileDB(dbFile) .closeOnJvmShutdown() // close the database automatically .make(); final String audioStore = "audio_store"; // The meta-data store. audioNameStore = db.treeMap(audioStore) .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.STRING) .counterEnable() // enable size counter .createOrOpen(); lut = db.hashMap("lut") .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.LONG_ARRAY) .createOrOpen(); printsPerSong = db.hashMap("songprints") .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.INT_ARRAY) .counterEnable() .createOrOpen(); }
Example #25
Source File: GitFilterHelper.java From git-as-svn with GNU General Public License v2.0 | 4 votes |
@NotNull public static HTreeMap<String, Long> getCacheSize(@NotNull GitFilter filter, @NotNull DB cacheDb) { return cacheDb.hashMap("cache.filter." + filter.getName() + ".size", Serializer.STRING, Serializer.LONG).createOrOpen(); }
Example #26
Source File: JMHMapDbTokyoCabinetBenchmarkBase.java From xodus with Apache License 2.0 | 4 votes |
Map<String, String> createTestStore() { if (map == null) { map = db.treeMap("testTokyoCabinet").keySerializer(Serializer.STRING).valueSerializer(Serializer.STRING).createOrOpen(); } return map; }
Example #27
Source File: CollectionsUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenSetCreatedInDB_whenMultipleElementsAdded_checkOnlyOneExists() { DB db = DBMaker.memoryDB().make(); NavigableSet<String> set = db. treeSet("mySet") .serializer(Serializer.STRING) .createOrOpen(); String myString = "Baeldung!"; set.add(myString); set.add(myString); assertEquals(1, set.size()); db.close(); }
Example #28
Source File: InMemoryModesUnitTest.java From tutorials with MIT License | 4 votes |
@Test public void givenDBCreatedOnHeap_whenUsed_checkUsageCorrect() { DB heapDB = DBMaker.heapDB().make(); HTreeMap<Integer, String> map = heapDB .hashMap("myMap") .keySerializer(Serializer.INTEGER) .valueSerializer(Serializer.STRING) .createOrOpen(); map.put(1, "ONE"); assertEquals("ONE", map.get(1)); }
Example #29
Source File: CacheManager.java From NNAnalytics with Apache License 2.0 | 4 votes |
public Map<String, Long> getCachedMap(String mapName) { return cache.hashMap(mapName, Serializer.STRING, Serializer.LONG).createOrOpen(); }
Example #30
Source File: GitFilterHelper.java From git-as-svn with GNU General Public License v2.0 | 4 votes |
@NotNull public static HTreeMap<String, String> getCacheMd5(@NotNull GitFilter filter, @NotNull DB cacheDb) { return cacheDb.hashMap("cache.filter." + filter.getName() + ".md5", Serializer.STRING, Serializer.STRING).createOrOpen(); }