Print
Object Query Languages

What is an Object Query Language?

An Object Query Language (OQL) is usually an expression language combined with an API to help users query a set of objects, navigate through an object graph, and get or set values on those objects. There are lots of different implementations of Object Query Languages, most of them tied to a specific technology (EJB-QL and JDOQL, for example).

Does Prevayler have an Object Query Language?

Implementing a Prevayler-specific object query language was discussed several times on the Mailing Lists, but was ruled out of scope for the project. This decision was backed by the need to free users and developers of Prevayler to choose whatever querying mechanism suits their needs best, instead of requiring them to adapt to a specific query model.

What Object Query Languages are available?

Fortunately, a handful of Object Query Languages are available, which you can pick and choose to best fit your needs. Among the best generic ones we have found so far are JXPath and OGNL. Jaxen might also be interesting to look at. Also, some scripting languages, like Groovy can be used.

How Object Query Languages speed up Prevayler application development?

Using an OQL is a nice way to avoid the baptism problem, and it's also an easy and powerful way to allow ad-hoc querying on prevalent systems.

To better demonstrate the flexibility offered by an OQL, this is the Java code to query all the street addresses from employees located in the UK office:

public List getEmployeesLocatedInUK(List employees) {
  List ret = new ArrayList();
  for(Iterator it = employees.iterator(); it.hasNext(); ) {
    Employee e = (Employee) it.next();
    if(e.getLocation().getCountry().equals("United Kingdom")) {
      ret.add(e.getLocation().getStreet());
    }
  }
  return ret;
}

And below is a table with the same example using different languages:

Language Example query
JXPath /employees/location[@country = 'United Kingdom']/street
OGNL employees.location.{? #this.country == 'United Kingdom'}.street
Groovy employees.location.findAll { it.country == 'United Kingdom' }.street
Powered by Atlassian Confluence