Database API
Table of Contents
Also see javadoc:
Get a database
Within plugins the database is automatically provided. In standalone programs a Database instance is created as follows:
Database db = new JDBCDatabase("molgenis.properties"); //assumes molgenis.properties in root of your project
Add objects in batch
Verbose and not efficient:
List<Foo> fooList = ... for(Foo f: fooList) { db.add(f); }
Can be compacted to:
List<Foo> fooList = ... db.add(fooList);
Queries made simple
Verbose:
Query<Foo> q = db.query(Foo.class); q.addRules(new QueryRule("barField", Operator.EQUALS, "bar")); List<Foo> result = q.find();
Can be compacted to
List<Foo> result = db.query(Foo.class).eq("barField", "bar").find();
Shorthand for query by primary key (id)
Verbose
int myId = 1; Foo myObject = q.query(Foo.class).eq("id", myId).find().get(0);
Shorthand
int myId = 1; Foo myObject = db.findById(Foo.class, myId);
N.B. if you would rename the id field the second method will still work while the first will break.