DataNucleus supports persisting/retrieving objects to/from DB4O datastores (using the datanucleus-db4o plugin). If you wish to contribute to this plugin either by contributing or by sponsoring particular functionality please contact us via the DataNucleus Forum.
DataNucleus supports 3 modes of operation of db4o - file-based, embedded-server-based and client-server based. In order to do so and to fit in with the JDO/JPA APIs we have defined the following means of connection. The following persistence properties will connect to a local file-based DB4O running on your local machine
datanucleus.ConnectionURL=db4o:file:{my_db4o_file}
datanucleus.ConnectionUserName=
datanucleus.ConnectionPassword=The filename {my_db4o_file} can be absolute OR relative (and not include the curly brackets!). The following persistence properties will connect to embedded-server-based DB4O running on with a local file
datanucleus.ConnectionURL=db4o:server:{my_db4o_file}
datanucleus.ConnectionUserName=
datanucleus.ConnectionPassword=The filename {my_db4o_file} can be absolute OR relative. The following persistence properties will connect as a client to a TCP/IP DB4O Server
datanucleus.ConnectionURL=db4o:{db4o_host}:{db4o_port}
datanucleus.ConnectionUserName=
datanucleus.ConnectionPassword=DB4O doesn't itself use such URLs so it was necessary to define this DataNucleus-specific way of addressing DB4O. So you create your PersistenceManagerFactory or EntityManagerFactory with these properties. Thereafter you have the full power of the JDO or JPA APIs at your disposal, for your db4o datastore.
Access Platform allows you to query the objects in the datastore using the following
DB4O provides its own "native" query interface, and if you are using the JDO API you can utilise this for querying. To take a simple example
// Find all employees older than 31
Query q = pm.newQuery("Native", new Predicate()
{
public boolean match(Person p)
{
return p.getAge() >= 32;
}
});
List results = (List)q.execute();So we are utilising the JDO API to generate a query and passing in the DB4O Predicate. In DB4O's API you can also specify "comparators" to control the ordering of the returned objects. You can make use of these also using the JDO API. Like this
// Find all employees older than 31
Query q = pm.newQuery("Native", new Predicate()
{
public boolean match(Person p)
{
return p.getAge() >= 32;
}
});
q.addExtension("db4o.native.comparator",
new QueryComparator()
{
public int compare(Object o1, Object o2)
{
Person p1 = (Person)o1;
Person p2 = (Person)o2;
return (p1.getAge() - p2.getAge());
}
});
List results = (List)q.execute();So we make use of the query extension db4o.native.comparator and pass the comparator in.
The following are known limitations of the current implementation
|