JPOX
JPOX
 Project  |  Ver 1.1  |  Ver 1.2  |  JDO  |  JPA  |  Guides  |  Tools
1.2 | Persistence | JDO ORM | JPA ORM | Runtime | JDO Runtime | JPA Runtime | Extensions | Developer
JPOX Runtime
RDBMS Datastores
DB4O Datastore
DB4O Native Queries

DB4O provides its own "native" query interface, and if you are using the JDO API you can utilise this for querying. This is present in jpox-db4o from version 1.2.1 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.





Using Comparators

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.