Using the Query Package in 3rd party applications

The Query Package is an framework designed to provide a general model of a query based on boolean logical operators. This model is designed to embody the query structure accepted by most search engines and the front-end interfaces to most publically-accessible biomedical databases (such as NIH's Entrez).

The Query Package comes configured to provide direct access to 8 different biomedical databases from the National Center for Biotechnology Information (NCBI). In order to utilize this package in a 3rd-party application you must do 3 things:

  1. Download the query package library (available as the file query.jar) and include this file. as part of the application's installation library
  2. Download the querys-config.zip file and unpack it into the base directory of your application. This will install the META-INF directory containing the querys.xml file.
  3. Download and put a copy of jdom.jar in your installation library. Depending on the version of Java you are using you may need to also include a copy of xerces.jar. These are utilities for reading XML documents and may already be installed. They are available at:
    www.jdom.org/downloads/
    xml.apache.org/dist/xerces-j/

To create and submit Querys your application should:

  1. Ask the QueryFactory class to return a list of databases.
  2. Ask the QueryFactory to return an instance of a Query object configured to query a specific database.
  3. Configure a Query and build a Search by calling methods on the Query object.
  4. To submit the Query: ask the Query object to return it's QuerySubmitter.
  5. Ask the QuerySubmitter to submit the Search to the database and return the results.

An application that utilizes Query objects should not instantiate a Query object directly, but should rather use the QueryFactory class. Likewise, the application should not directly instantiate a QuerySubmitter object, but should instead ask the Query to return a QuerySubmitter designed for it's specific database.

Here is an example of how to request information about the Query types available, and then instantiate a specific Query:


// make the package accessible to your class
import org.bioquery.query.*;

    try {
        // Get the list of available databases
        List databaseList = QueryFactory.getDatabaseList();
        Object[] databases = databaseList.toArray();

        // Ask the user to select one of the databases.
        String databaseName = (String)JOptionPane.showInputDialog(me,
                "Please choose the database for this Query.",
                "Choose Database", JOptionPane.QUESTION_MESSAGE,
                null, databases, databases[0]);

        // Ask the QueryFactory to return a subclass of Query based
        // on the database name chosen.
        Query q = QueryFactory.createQuery(databaseName);
    }
    catch (IOException ex) { ex.printStackTrace(); }

Here is a simple example of how to submit a Query object and get the results from the database:


    // Get the QuerySubmitter specific for this Query object.
    QuerySubmitter submitter = theQuery.getQuerySubmitter();

    // The results of the Query returned to the client.
    BufferedReader results = null;
    try { results = submitter.getQueryResults(); }
    catch (QueryException ex) { }

    if ( results != null ) {
       // Read the results
    }

The results come back as a BufferedReader containing the textual response from the database. This is typically a complete HTML document that can be displayed inside a web browser or a JEditorPane container.

For more information on how to utilize this package, please see the JavaDoc API for package org.bioquery.query or write us at: support@bioquery.org

Download the query package

Click here:
Download Package org.bioquery.query

 

 

Developer Guide.

BioQuery Home.