Specifying the data to retrieve from a POJO
BIRT reports must use data that is structured as a table consisting of rows and columns. For a POJO data set to return data in this format, you map methods or members of a POJO class to columns. Listing 9‑1 shows an example of a class that represents music CDs. The class describes the members and uses pairs of get and set methods to persist the data. To create a data set using this class, you would map the get methods to columns.
Listing 9‑1 Class representing music CDs
package dataset;
public class CD {
private String cdTitle;
private String cdArtist;
private String cdCountry;
private String cdCompany;
private String cdPrice;
private String cdYear;
public CD(String title) {
this.cdTitle = title;
}
public String getCDTitle() {
return cdTitle;
}
public void setCDTitle(String title) {
this.cdTitle = title;
}
public String getCDArtist() {
return cdArtist;
}
public void setCDArtist(String artist) {
this.cdArtist = artist;
}
public String getCDCountry() {
return cdCountry;
}
public void setCDCountry(String country) {
this.cdCountry = country;
}
public String getCDCompany() {
return cdCompany;
}
public void setCDCompany(String company) {
this.cdCompany = company;
}
public String getCDPrice() {
return cdPrice;
}
public void setCDPrice(String price) {
this.cdPrice = price;
}
public String getCDYear() {
return cdYear;
}
public void setCDYear(String year) {
this.cdYear = year;
}
}
How to create a POJO data set
This procedure assumes you have already created the POJO data source that this data set uses. Examples in this section refer to the POJO example in Listing 9‑1.
1 In Data Explorer, right-click Data Sets, then choose New Data Set.
2 In New Data Set, specify the following information:
1 In Data Source Selection, select the POJO data source to use. Data Set Type displays POJO Data Set.
2 In Data Set Name, type a name for the data set.
3 Choose Next.
3 In New POJO Data Set, specify the following information:
1 In POJO Data Set Class Name, specify the POJO class that retrieves the data at run time. Choose Browse to find and select the class.
2 In Application Context Key, use the default key or delete it. This property is optional.
Figure 9‑3 shows an example of properties set for a POJO data set.
Figure 2-28 POJO data set propertiesFigure 2-28 POJO data set properties
Figure 9‑3 POJO data set properties
4 Choose Next.
5 Map methods or fields in a POJO class to data set columns, using the following steps:
1 In POJO Class Name, specify the POJO class that contains the get methods to map to columns. You can choose Browse to find and select the class.
The data set editor uses a get* filter to display all the get methods in the specified POJO class, as shown in Figure 9‑4.
Figure 2-29 Data set editor displaying the get methods in a POJO classFigure 2-29 Data set editor displaying the get methods in a POJO class
Figure 9‑4 Data set editor displaying the get methods in a POJO class
2 Double-click the get method to map to a data set column.
Add Column Mapping displays the mapping information, as shown in Figure 9‑5.
Figure 2-30 Column mapping informationFigure 2-30 Column mapping information
Figure 9‑5 Column mapping information
Choose OK to accept the default values.
3 Repeat the previous step for every column to add to the data set. Figure 9‑6 shows an example of column mappings defined in a POJO data set.
Figure 2-31 Data set editor displaying the column mappingsFigure 2-31 Data set editor displaying the column mappings
Figure 9‑6 Data set editor displaying the column mappings
6 Choose Finish to save the data set. Edit Data Set displays the columns, and provides options for editing the data set.
7 Choose Preview Results to view the data rows returned by the data set. Figure 9‑7 shows an example of data rows returned by a POJO data set.
Figure 2-32 Data rows returned by a POJO data setFigure 2-32 Data rows returned by a POJO data set
Figure 9‑7 Data rows returned by a POJO data set