After tables have been added to a catalog, you can now use them to build reports. However, in your daily work, you may often be dealing with a set of tables in your queries. You will have to define relationships and create joins among different tables every time you create a new report. For XML data source, if the parent and children nodes are transformed to different tables, joins will be embodied by the parent-child relationship, which is maintained by primary key and foreign key in tables.
JReport Designer provides you with the pre-join feature which can be used for creating/editing queries and setting up joins in business cubes. The pre-join information is one kind of resource information stored in the catalog. It is saved in a standalone file with the extension .pre, and shares the same prefix as the catalog file. It is not used at report runtime. In JReport Designer, when you open a catalog, the pre-join file is opened at the same time. When you save the catalog, the pre-join file is also saved.
The Pre-join Editor is a convenient tool for you to predefine the relationships between tables all at once.
To predefine joins between tables in a catalog, follow the steps below:
From the column drop-down lists, select the columns in the two tables on which the condition will be built, then specify the operator to compose the condition.
To add another condition line, click the Add Condition button and define the condition as required. Then from the logic drop-down list, specify the relationship between the two condition lines. Repeat this to add more condition lines if necessary.
To make some conditions grouped, select them and click the Group button, then the selected conditions will be added in one group and work as one line of condition expression. Conditions and groups together can be further grouped.
To take any condition or group in a group out, select it and click Ungroup.
To adjust the priority of the conditions, select it and click the Up or Down button.
To delete a condition line, select it and click the Delete button.
With conventional joins, records that do not satisfy the join condition are eliminated from the result. An outer join preserves these records in the result and replaces the missing values with nulls. SQL syntax uses the left outer join if the records in the left side table are preserved and right outer join if the records on the right side table are preserved. The left side is determined by where the arrow begins and the right side is determined by the side the arrow points to. It is independent of the location of the table in the query editor. When you drag to make the join, you always drag logically from left to right even if your view in the query editor is right to left.
For example, consider the following two tables where the join arrow points from the Customer.C# to the Order.C#:
Table 1
Order | O# | C# |
---|---|---|
101 | 001 | |
102 | 002 | |
103 | 004 |
Table 2
Customer | C# | Name |
---|---|---|
001 | GE | |
002 | IBM | |
003 | DELL |
The inner join of Customer.C# = Order.C#
will produce the following result:
JoinResult | O# | C# | Name |
---|---|---|---|
101 | 001 | GE | |
102 | 002 | IBM |
The Customer LEFT JOIN Order ON (Customer.C# = Order.C#)
will produce the following result:
JoinResult | O# | C# | Name |
---|---|---|---|
101 | 001 | GE | |
102 | 002 | IBM | |
<null> | 003 | DELL |
The Customer RIGHT JOIN Order ON (Customer.C# = Order.C#)
will produce the following result:
JoinResult | O# | C# | Name |
---|---|---|---|
101 | 001 | GE | |
102 | 002 | IBM | |
103 | <null> | <null> |
The Customer FULL OUTER JOIN Order ON (customer.C# = order.C#)
will produce the following result:
JoinResult | O# | Order.C# | Customer.C# | Name |
---|---|---|---|---|
101 | 001 | 001 | GE | |
102 | 002 | 002 | IBM | |
<null> | <null> | 003 | DELL | |
103 | 004 | <null> | <null> |
After you have created joins between the tables in the Pre-join Editor window, you can then use them to define paths. To do this:
To edit or delete a path, select it in the Pre-join Paths box, then click the Edit or Delete button.
To rename a path, select it in the Pre-join Paths box, then in the Rename box, type the new name and then press Enter to confirm.
You must define at least one path for the joins you create. If no path is defined, when you click the OK button on the Pre-join Editor:
You can save the relationships by clicking OK on the Pre-join Editor toolbar. Note that the pre-join information won't really be saved to disk until you save the catalog. After you have saved the catalog, you can then use the just created pre-join to develop reports.
Notes: