NexJ Logo

Report queries

Report queries are used by the JasperReports engine to execute commands and obtain data to populate the report. Queries are written in NexJ Scheme syntax and retrieve data from classes in the NexJ Solutions business model to be presented in the report. Data retrieved by the report queries are displayed in the detail band.

Since this chapter focuses on using Jaspersoft Studio Professional as a NexJ report development tool, the query must be set to NexJOO, the NexJ object query format, to directly connect to the NexJ Solutions business model. Querying the business model allows you to leverage the exact business logic that the NexJ application uses, accessing all available attributes, including the ones that are not persisted to the database. It also ensures data is properly localized and secured when you are executing the report. Every report must contain a report query.

NexJOO query language

When used as a NexJ report development tool, Jaspersoft Studio Professional uses a Scheme-like syntax called NexJOO to retrieve information from business model classes.

The NexJOO query language is formatted similar to this:

(ObjectClassToRead
   (field1 field2 ... fieldn)  //fields to query
   ()  // where clause
   ()  //orderBy clause
)

ObjectClassToRead

Identifies the class to read in the business model.

fields

A list of class attributes to include in the report.

where clause

Filters the class instances retrieved by the query. Often in NexJ reports, the clause is left blank. This allows the NexJ application to dynamically construct the expression.

orderBy clause

Specifies the sort order of the data retrieved. Sorting is only done on persisted attributes; if data is not persisted, it cannot be sorted.

The following code is an example of a report query using NexJOO syntax:

(Person
   (firstName lastName)
   ()  
   (
      (lastName  . #t)
      (firstName . #t)
   )  
)

This query gathers the firstName and lastName attributes of instances of the Person class, ordered by last name. The #t (true) value in the orderBy clause orders each attribute in ascending order.