Using MapDB flat-file object database
Code: "io_mapdb.py". Programming language: Python DMelt Version 1. Last modified: 09/05/2015. License: Pro
https://datamelt.org/code/cache/io_mapdb_7973.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.



from jhplot import *
from java.io import *
from  java.util.concurrent import *
from org.mapdb import DB,DBMaker
 
# 1D array & histogram 
p1=P0D(); p1.randomNormal(1000,0,10)
h1=H1D("histogram",100,1,10)

dfile=File("mapdb.db");
db=DBMaker.fileDB(dfile).closeOnJvmShutdown().make()
map = db.getTreeMap("data");
map.put("array",p1)
map.put("histogram",h1)
db.commit() # persist changes into disk
db.close()


print "Reading database.."
#db=DBMaker.fileDB(dfile)
db =DBMaker.newFileDB(File("mapdb.db")).make()
#db=DBMaker.fileDB(dfile).closeOnJvmShutdown().make()
print type(db)
#db.readOnly()
map = db.getTreeMap("data")
print map["array"]
print map["histogram"]
db.close()

Ads help maintain this website.