1717package org .dswarm .graph .index ;
1818
1919import java .io .File ;
20- import java .io .IOException ;
2120import java .util .Map ;
2221import java .util .Set ;
2322
2423import org .mapdb .BTreeKeySerializer ;
2524import org .mapdb .DB ;
2625import org .mapdb .DBMaker ;
2726import org .mapdb .Serializer ;
28- import org .mapdb .TxMaker ;
2927
3028import org .dswarm .common .types .Tuple ;
3129
3533public final class MapDBUtils {
3634
3735 public static final String INDEX_DIR = "index/mapdb" ;
38- public static final String DEFAULT_INDEX_NAME = "default_mapdb_index" ;
39-
40- public static Tuple <Map <Long , Long >, DB > createOrGetPersistentLongLongIndexTreeMapNonTransactional (final String indexFileName , final String indexName ) {
41-
42- final DB db = createNonTransactionalPermanentMapDB (indexFileName );
43-
44- return Tuple .tuple (createTreeMap (db , indexName ), db );
45- }
46-
47- public static Tuple <Map <Long , Long >, DB > getOrCreateLongLongIndexTreeMapNonTransactional (final String name ) {
48-
49- return MapDBUtils .createOrGetPersistentLongLongIndexTreeMapNonTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name , name );
50- }
51-
52- public static Tuple <Set <Long >, DB > createOrGetPersistentLongIndexTreeSetNonTransactional (final String indexFileName , final String indexName ) {
53-
54- final DB db = createNonTransactionalPermanentMapDB (indexFileName );
55-
56- return Tuple .tuple (createTreeSet (db , indexName ), db );
57- }
58-
59- public static Tuple <Set <Long >, DB > getOrCreateLongIndexTreeSetNonTransactional (final String name ) {
60-
61- return MapDBUtils .createOrGetPersistentLongIndexTreeSetNonTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name , name );
62- }
6336
6437 public static Tuple <Set <Long >, DB > createOrGetInMemoryLongIndexTreeSetNonTransactional (final String indexName ) {
6538
@@ -75,133 +48,20 @@ public static Tuple<Map<String, String>, DB> createOrGetInMemoryStringStringInde
7548 return Tuple .tuple (createStringStringTreeMap (db , indexName ), db );
7649 }
7750
78- public static Tuple <Map <String , String >, DB > createOrGetInMemoryStringStringIndexTreeMapGlobalTransactional (final String indexName ) {
79-
80- final DB db = createGlobalTransactionalInMemoryMapDB ();
81-
82- return Tuple .tuple (createStringStringTreeMap (db , indexName ), db );
83- }
84-
85- public static Tuple <Set <Long >, DB > getOrCreateInMemoryLongIndexTreeSetNonTransactional (final String name ) {
86-
87- return MapDBUtils .createOrGetInMemoryLongIndexTreeSetNonTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name );
88- }
89-
90- public static Tuple <Map <Long , Long >, DB > createOrGetPersistentLongLongIndexTreeMapGlobalTransactional (final String indexFileName , final String indexName ) {
91-
92- final DB db = createGlobalTransactionalPermanentMapDB (indexFileName );
93-
94- return Tuple .tuple (createTreeMap (db , indexName ), db );
95- }
96-
97- public static Tuple <Map <Long , Long >, DB > getOrCreateLongLongIndexTreeMapGlobalTransactional (final String name ) {
98-
99- return MapDBUtils .createOrGetPersistentLongLongIndexTreeMapGlobalTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name , name );
100- }
101-
10251 public static Tuple <Set <Long >, DB > createOrGetPersistentLongIndexTreeSetGlobalTransactional (final String indexFileName , final String indexName ) {
10352
10453 final DB db = createGlobalTransactionalPermanentMapDB (indexFileName );
10554
10655 return Tuple .tuple (createTreeSet (db , indexName ), db );
10756 }
10857
109- public static Tuple <Set <Long >, DB > getOrCreateLongIndexTreeSetGlobalTransactional (final String name ) {
110-
111- return MapDBUtils .createOrGetPersistentLongIndexTreeSetGlobalTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name , name );
112- }
113-
114- public static Tuple <Set <Long >, DB > createOrGetInMemoryLongIndexTreeSetGlobalTransactional (final String indexFileName ) {
115-
116- final DB db = createGlobalTransactionalInMemoryMapDB ();
117-
118- return Tuple .tuple (createTreeSet (db , indexFileName ), db );
119- }
120-
121- public static Tuple <Set <Long >, DB > getOrCreateInMemoryLongIndexTreeSetGlobalTransactional (final String name ) {
122-
123- return MapDBUtils .createOrGetInMemoryLongIndexTreeSetGlobalTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name );
124- }
125-
126- public static TxMaker createOrGetPersistentIndexTransactional (final String indexFileName ) throws IOException {
127-
128- final File file = new File (indexFileName + Statics .INDEX_FILE_ENDING );
129-
130- return DBMaker .newFileDB (file ).asyncWriteEnable ().closeOnJvmShutdown ().makeTxMaker ();
131- }
132-
133- public static TxMaker getOrCreateIndexTransactional (final String name ) throws IOException {
134-
135- return MapDBUtils .createOrGetPersistentIndexTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name );
136- }
137-
138- public static Tuple <Map <Long , Long >, DB > createOrGetPersistentLongLongIndexHashMapNonTransactional (final String indexFileName ) {
139-
140- final DB db = createNonTransactionalPermanentMapDB (indexFileName );
141-
142- return Tuple .tuple (createHashMap (db , indexFileName ), db );
143- }
144-
145- public static Tuple <Map <Long , Long >, DB > getOrCreateLongLongIndexHashMapNonTransactional (final String name ) {
146-
147- return MapDBUtils .createOrGetPersistentLongLongIndexHashMapNonTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name );
148- }
149-
150- public static Tuple <Set <Long >, DB > createOrGetPersistentLongIndexHashSetNonTransactional (final String indexFileName ) {
151-
152- final DB db = createNonTransactionalPermanentMapDB (indexFileName );
153-
154- return Tuple .tuple (createHashSet (db , indexFileName ), db );
155- }
156-
157- public static Tuple <Set <Long >, DB > getOrCreateLongIndexHashSetNonTransactional (final String name ) {
158-
159- return MapDBUtils .createOrGetPersistentLongIndexHashSetNonTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name );
160- }
161-
162- public static Tuple <Map <Long , Long >, DB > createOrGetPersistentLongLongIndexHashMapGlobalTransactional (final String indexFileName ) {
163-
164- final DB db = createGlobalTransactionalPermanentMapDB (indexFileName );
165-
166- return Tuple .tuple (createHashMap (db , indexFileName ), db );
167- }
168-
169- public static Tuple <Map <Long , Long >, DB > getOrCreateLongLongIndexHashMapGlobalTransactional (final String name ) {
170-
171- return MapDBUtils .createOrGetPersistentLongLongIndexHashMapGlobalTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name );
172- }
173-
17458 public static Tuple <Map <String , String >, DB > createOrGetPersistentStringStringIndexTreeMapGlobalTransactional (final String indexFileName , final String indexName ) {
17559
17660 final DB db = createGlobalTransactionalPermanentMapDB (indexFileName );
17761
17862 return Tuple .tuple (createStringStringTreeMap (db , indexName ), db );
17963 }
18064
181- public static Tuple <Map <String , String >, DB > getOrCreateStringStringndexTreeMapGlobalTransactional (final String name ) {
182-
183- return MapDBUtils .createOrGetPersistentStringStringIndexTreeMapGlobalTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name , name );
184- }
185-
186- public static Tuple <Set <Long >, DB > createOrGetPersistentLongIndexHashSetGlobalTransactional (final String indexFileName ) {
187-
188- final DB db = createGlobalTransactionalPermanentMapDB (indexFileName );
189-
190- return Tuple .tuple (createHashSet (db , indexFileName ), db );
191- }
192-
193- public static Tuple <Set <Long >, DB > getOrCreateLongIndexHashSetGlobalTransactional (final String name ) {
194-
195- return MapDBUtils .createOrGetPersistentLongIndexHashSetGlobalTransactional (Statics .DEFAULT_STORE_DIR + File .separator + name );
196- }
197-
198- public static Map <Long , Long > createTreeMap (final DB db , final String indexFileName ) {
199-
200- return db .createTreeMap (indexFileName )
201- //.keySerializer(BTreeKeySerializer.LONG) // supported by 2.0-alpha1
202- .valueSerializer (Serializer .LONG ).makeOrGet ();
203- }
204-
20565 public static Map <String , String > createStringStringTreeMap (final DB db , final String indexFileName ) {
20666
20767 return db .createTreeMap (indexFileName )
@@ -214,32 +74,6 @@ public static Set<Long> createTreeSet(final DB db, final String indexFileName) {
21474 return db .createTreeSet (indexFileName ).makeOrGet ();
21575 }
21676
217- public static Map <Long , Long > createHashMap (final DB db , final String indexFileName ) {
218-
219- return db .createHashMap (indexFileName )
220- //.keySerializer(Serializer.LONG) // supported by 2.0-alpha1
221- .valueSerializer (Serializer .LONG ).makeOrGet ();
222- }
223-
224- public static Set <Long > createHashSet (final DB db , final String indexFileName ) {
225-
226- return db .createHashSet (indexFileName ).serializer (Serializer .LONG ).makeOrGet ();
227- }
228-
229- public static DB createNonTransactionalPermanentMapDB (final String indexFileName ) {
230-
231- final File file = createFile (indexFileName );
232-
233- return DBMaker
234- .newFileDB (file )
235- .asyncWriteEnable ()
236- // TODO: enable if, this performs better over time
237- //.compressionEnable().asyncWriteFlushDelay(1)
238- .closeOnJvmShutdown ()
239- .transactionDisable ()
240- .make ();
241- }
242-
24377 public static DB createNonTransactionalInMemoryMapDB () {
24478
24579 return DBMaker .newMemoryDirectDB ()
@@ -260,14 +94,6 @@ public static DB createGlobalTransactionalPermanentMapDB(final String indexFileN
26094 .make ();
26195 }
26296
263- public static DB createGlobalTransactionalInMemoryMapDB () {
264-
265- return DBMaker .newMemoryDirectDB ()
266- .asyncWriteEnable ()
267- .closeOnJvmShutdown ()
268- .make ();
269- }
270-
27197 private static File createFile (final String indexFileName ) {
27298
27399 return new File (indexFileName + Statics .INDEX_FILE_ENDING );
0 commit comments