Quick Start: Generate a Java report application
Use the Business Application Modeler to generate a Java report library, where the library feeds the report data from a database using SQL.
-
Create a new Java project.
- Select File > New > Java > BAM Java Project (.4pw).
-
Enter a name for your project in the Project name field.
This name will become the name of the project workspace file.
- Specify the project directory in the Location field.
-
Click OK.
The project is created and saved in the selected project directory.
The project is created, to include nodes for database-related files, the data source library files, and the report designs. A ReportLauncher application is created as well, allowing you to test your data source library from within the Genero Studio project.
-
Add your database meta-schema (.4db) file under
the Database node in the project tree, and save your changes.
If you need to create the database schema (.4db) file, see Create the database meta-schema file.
- Right-click on the Database node and select Add Files.
- Select the meta-schema (.4db) file and click Open.
-
Configure the database meta-schema.
In most cases, the database meta-schema will have been created with the tables set to Active and the primary keys defined.
- Open the .4db file.
-
Set the table property for each table you will include to Active.
Tip: To easily set multiple tables as active, hold down the CTRL key as you select the tables in the Database Structure view, then check the Active property.
- Define a primary key for each table. See Add constraints or indexes.
- Save the changes to your data schema.
-
Create the data source (.4rdj) file.
For this quick start, you will select a single table. Most reporting, however, will involve multiple tables and their relation. See Create a report with BAM for details on creating more complex data sources.
- Select File > New > Java > Report Data from Database (.4rdj). Click OK.
-
In the Column selection page, select columns from a single table to
include in the record.
The record defines the data that will stream, one record at a time, to the report engine.Click Next > to continue.
- In the Query Creation page, one typically sets the Join, Where and Order by criteria for the data source. As only a single table was selected, this page can be skipped.
-
Click Finish.
A record is created and displayed in a .4rdj tab.
-
Select File >> Save as and save the .4rdj file, adding the file to the DataSourceLib
library node.
Important: Check the directory before saving your file! It is recommended that you save the file in $(ProjectDir)/src.Selecting the right name in this step is important; the name of the .4rdj file becomes the name of the Java source, which ultimately becomes the name of the Java class. You should choose a name following java class naming conventions, see http://www.oracle.com/technetwork/java/codeconventions-135099.html for details.
- Save the changes to your project.
-
Generate the code and the data schema.
-
Right-click the DataSourceLib library node and select
Build.
The DataSourceLib library node is the node containing the data source (.4rdj) file.The report library source and the data schema (.xsd) files are created and listed in the Intermediate Files folder. The location of these intermediate files is determined by the setting of the Target directory property.
-
Right-click the DataSourceLib library node and select
Build.
-
Create a report design from a template.
For this quick start, we are going to use a template to create a simple, non-grouped list report. For more information on using report templates, see Create and manage report templates.
- Select File >> New, Report from Template.
- Select Simple List (PULSE). Click OK.
-
In the Schema location field, select the schema created in the previous step.
The rows field populates for you with the record name. Complete the Repetitions section, mapping the template repetitions to the schema repetitions. Click Next >.
- Add several fields from the Available Fields column to the Selected Fields column. Click Next >.
-
On the Variables page, modify the title placeholder to state
"My Report". Click Finish.
The report is created.
- Select File >> Save untitled.4rp as... and save the file in the $ProjectDir/src directory, and in the Designs node.
-
Run the Report Launcher application.
- Right-click the Report Launcher node and select Execute.
-
In the Select archive or directory containing data model classes
combobox, select either the directory containing the class files or the archives.
If your library is not listed:
- Click the Directory... button to specify a directory containing
classes:
- For .class files in an unnamed packages, the directory that contains the .class files
- For .class files in named packages (or mixed), the directory that contains the "root" package (the first package in the full package name).
- Click the Archives... button to select a java archive (.jar or .zip) containing the classes with the right package structure.
The Select data model class to run combobox populates with possible classes to use. - Click the Directory... button to specify a directory containing
classes:
- In the Select data model class to run combobox, select the name of the class to use as the data model.
- In the Report field, select the report to run from the combobox. If your report is not listed, click the Add button to locate and add your report.
-
Click Run.
The report displays. We did not take the time to properly specify all the placeholders, or to verify the report row lengths, so the report may have some formatting issues, however it should display and be populated with data.