forked from wildfirechat/im-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapdbWalTest.groovy
More file actions
43 lines (37 loc) · 999 Bytes
/
Copy pathmapdbWalTest.groovy
File metadata and controls
43 lines (37 loc) · 999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@Grab(group='org.mapdb', module='mapdb', version='1.0.8')
import org.mapdb.DB
import org.mapdb.DBMaker
class User implements Serializable {
String name
String surname
}
def writeSomeData(Map m) {
m.put(1, new User(name: "mario", surname: "rossi"))
m.put(2, new User(name: "gianni", surname: "bianchi"))
m.put(3, new User(name: "pino", surname: "verdi"))
}
def readSomeData(Map m) {
m.each {k, v ->
println "id: $k, value: $v"
}
}
if (args.size() != 1) {
println "groovy mapdbWalTest.groovy [writer|reader]"
exit 1
}
String mode = args[0]
File tmpFile = new File("test_store.mapdb")
tmpFile.createNewFile()
DB db = DBMaker.newFileDB(tmpFile).make()
Map mapStore = db.getHashMap("storageMap")
switch (mode) {
case "writer":
writeSomeData(mapStore)
db.commit()
return
case "reader":
readSomeData(mapStore)
return
default:
println "Error option not recognized must be one of [writer|reader]"
}