Using NeoDatis database to store objects
Source code name: "io_database_neodatis.py"
Programming language: Python
Topic: File IO/Database
DMelt Version 1. Last modified: 09/05/2015. License: Pro
https://datamelt.org/code/cache/io_database_neodatis_7541.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.


# This example is based on http://www.neodatis.org/  (NeoDatis database)

from java.awt import Color,Font
from jhplot  import * 
from java.util import Random,ArrayList
import os 

# import from NeoDatis DB
from  org.neodatis.odb import *;
from  org.neodatis.odb.impl.core.query.criteria import *;
from  org.neodatis.odb.core.query.criteria import *;
from  org.neodatis.odb.xml import *;


c1 = HPlot("Canvas",600,400)
c1.setGTitle("Writing and reading objects from a NeoDatis database");
c1.visible(1)
c1.setAutoRange()

p1=P1D("X-Y points")
p1.add(10,20)
p1.add(30,40)

h1 = H1D("GaussianHistogram",20, -2, 2.0)
h1.fillGauss(100,10,2)

lab=HLabel("Label", 0.15, 0.7, "NDC")
lab.setColor(Color.blue)

# remove database  if exists
if os.path.exists("database.db"):
    os.remove("database.db")

print "Store all objects in a database"
odb = ODBFactory.open("database.db")
odb.store(p1)
odb.store(h1)
odb.store(lab)
odb.close()



print "######### open the database ################"

odb = ODBFactory.open("database.db")
query = CriteriaQuery(P0D);
obj = odb.getObjects(query)
print  "Number of P0D objects=",obj.size()
query = CriteriaQuery(H1D);
obj = odb.getObjects(query)
print  "Number of H1D  objects=",obj.size()


# find an P0D object with the name data1
query =  CriteriaQuery(P0D, Where.equal("title", "data1"));
#p0d=odb.getObjects(query).getFirst()
#print p0d.toString()
   
# find an H1D object with the name GaussianHistogram
query =  CriteriaQuery(H1D, Where.equal("title", "GaussianHistogram"));
h1d=odb.getObjects(query).getFirst()
h1d.setTitle("GaussianHistogram from a database")
c1.draw( h1d)
            


odb.close()


You see the box below because you did not login.