DB4O Queries

Using a DB4O datastore DataNucleus allows you to query the objects in the datastore using the following

  • JDOQL - language based around the objects that are persisted and using Java-type syntax
  • JPQL - language based around the objects that are persisted and using Java-type syntax
  • Native - DB4Os own type-safe query language
  • SQL - SQL queries of DB4O

It is hoped to provide more options in the future.

When using queries there are some specific situations where it can be useful to benefit from special treatment. These are listed here.

Flush changes before execution

When using optimistic transactions all updates to data are held until flush()/commit(). This means that executing a query may not take into account changes made during that transaction in some objects. DataNucleus allows a convenience of calling flush() just before execution of queries so that all updates are taken into account. The property name is datanucleus.query.flushBeforeExecution and defaults to "false".

To do this on a per query basis for JDOQL/JPQL/SQL using the JDO API you would do

query.addExtension("datanucleus.query.flushBeforeExecution","true");

To do this on a per query basis for JPQL/SQL using the JPA API you would do

query.setFlushMode(FlushModeType.AUTO);

You can also specify this for all queries using a persistence property datanucleus.query.flushBeforeExecution which would then apply to ALL queries for that PMF/EMF.



Evaluate queries in-memory

By default with JDOQL/JPQL with db4o DataNucleus will execute a SODA query in db4o specifying the candidate, filter and ordering. It will then use in-memory evaluation for any other parts of the query (grouping, result, range). If desired you can also execute the filter and ordering in-memory . To do this you specify the query extension/hint datanucleus.query.evaluateInMemory to true .

To do this on a per query basis for JDO you would do

query.addExtension("datanucleus.query.evaluateInMemory","true");

To do this on a per query basis for JPA you would do

query.setHint("datanucleus.query.evaluateInMemory","true");