db4o module provides a high level function on top of the db4o API.
open_db4o() opens a db4o data file and returns a handle to manupilate it.
db = open_db4o("d:/tmp/db4o.odb")
Newly stores objects or updates stored objects.
Pilot = beanclass("Pilot", [Serializable], {"name"=>String, "points"=>int}, ["name"])
p = Pilot("foo")
db.set(p)
db.commit()
columns = ["address", "zip_code"]
g = classGenerator(".")
zip = g.beanclass("zip", null, {"address"=>String, "zip_code"=>String}, columns)
db = open_db4o("zip_db")
db.bufferSize = 1000
for (i:readCSV(csv_file, columns)){
db.set(zip(i.address, i.zip_code))
}
db.commit()
db.close()
Deletes a stored object permanently.
for (i: db.query(Pilot())) db.delete(i)
Commits the running transaction.
db.commit()
Rolls back the running transaction.
try {
...
db.commit()
} catch (Exception e){
db.rollback()
}
Closes the ObjectContainer.
db.close()
If no argument is specified, it creates a Query object, from which a query is built in S.O.D.A style.
oc = Db4o.configure().objectClass(zip)
oc.maximumActivationDepth(0)
oc.objectField("zip_code").indexed(true)
db = open_db4o("zip_db")
q = db.query()
q.constrain(zip)
q.descend("zip_code").constrain("1000000")
for (record : query.execute()){
println(record)
}
db.close()
If an object is specified as the argument, it executes a query in 'Query By Example' style, and return a generator to retrieve the result.
for (i: db.query(Pilot())) println(i.name)
If a class and a unary function are specified, it executes a query in Predicate style, and return a generator to retrieve the result.
oc = Db4o.configure().objectClass(zip)
oc.maximumActivationDepth(0)
oc.objectField("zip_code").indexed(true)
db = open_db4o("zip_db")
for (record : db.query(zip, function (record) record.zip_code == "1000000")){
println(record)
}
db.close()
Returns the ObjectContainer from the handle that open_db4o() returns.
If bufferSize has an integer value, object added with db.set() are buffered up to bufferSize and automatically committed with db.commit().