DB4O Native Queries
Note that if you choose to use db4o Native Queries then these are not portable to any other datastore. Use JDOQL/JPQL for portability

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.





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.