Skip Headers

# Report Query

Previous

Next

Report query lets you retrieve data from a set of objects and their related objects. Report query supports database reporting functions and features.

For more information, see "Report Query Results".

Example: Optimization Through Report Query demonstrates the use of report query to read only the last name of the employees. This reduces the amount of data read from the database compared to the code in Example: No Optimization, and avoids instantiating employee instances.

Optimization Through Report Query

    /* Read all the employees from the database, ask the user to choose one and return it. The report query is used to read just the last name of the employees. Then the primary key stored in the report query result to read the real object */
    List list;

    // Fetch data from database and add to list box
    ExpressionBuilder builder = new ExpressionBuilder();
    ReportQuery query = new ReportQuery (Employee.class, builder);
    query.addAttribute("lastName");
    query.retrievePrimaryKeys();
    Vector reportRows = (Vector) session.executeQuery(query);
    list.addAll(reportRows);

    // Display list box
    ....

    // Get selected employee from list
    ReportQueryResult result = (ReportQueryResult) list.getSelectedItem();
    Employee selectedEmployee =     (Employee)result.readobject(Employee.Class,session);

Although the differences between the unoptimized example (Example: No Optimization) and the report query optimization in Example: Optimization Through Report Query appear to be minor, report queries offer a substantial performance improvement.