InterMine Query Package

The InterMine database query system is implemented in the Java package org.intermine.objectstore.query. The main class of the package is Query which represents a query that can be passed to the ORMappingTool. The Java Query maps directly onto IQL. It may be useful to refer to our QueryExamples. In fact, by far the easiest method of creating a Java InterMine Query object is to use the following constructor:

 import org.intermine.objectstore.query.Query;
 import org.intermine.objectstore.query.iql.IqlQuery;

 Query q = new IqlQuery("--- IQL Query text ---", null).toQuery();

However, in a Java program, one will occasionally require more flexibility - the Java interface is a more direct method of inserting parameters into the Query, rather than converting them into text and expecting the parser to convert back.

Structure

The Java Query object contains:

An Example

This is an example of how one would build a Java InterMine Query object to represent the IQL query:

    SELECT a.field1, a.field2 FROM a WHERE a.field3 = 'Hello';

The Query is built up in stages.

    import org.intermine.objectstore.query.Query;
    import org.intermine.objectstore.query.QueryClass;
    import org.intermine.objectstore.query.QueryField;
    import org.intermine.objectstore.query.QueryValue;
    import org.intermine.objectstore.query.SimpleConstraint;

    Query q = new Query();
    QueryClass c = new QueryClass(a.class);
    QueryField f1 = new QueryField(c, "field1");
    QueryField f2 = new QueryField(c, "field2");
    QueryField f3 = new QueryField(c, "field3");
    QueryValue v = new QueryValue("Hello");
    SimpleConstraint sc = new SimpleConstraint(f3, SimpleConstraint.EQUALS, v);
    q.addFrom(c);
    q.addToSelect(f1);
    q.addToSelect(f2);
    q.setConstraint(sc);
    q.setDistinct(false);