pureQuery® Runtime
automates the creation and the populating of Java™ objects that return results from SQL queries
that contain table joins. A set of nested beans represents the data
that are returned from the SQL query.
The hierarchy of
the beans represents the relational structure of the tables and data
in the database. pureQuery Runtime
also handles the data from the query. In most cases, it generates
the required ResultHandlers and RowHandlers for data access object
(DAO) interfaces and inline methods.
As a simple example, an SQL query joins a department table and
an employee table with the employee ID that is in both tables. You
can develop Java classes with
pureQuery annotations
that create a set of nested beans that organizes employee information
by department:
- Each department bean contains information for a department and
each employee bean contains information for an employee.
- Each employee bean is a child of a department bean.
- Each department bean contains a list of employee beans for that
department.
With pureQuery Runtime,
the nested beans can return data with one-to-many and one-to-one relationships
and can simulate many-to-many and many-to-one relationships.
pureQuery Runtime supports
the automatic generation of a nested bean structure from the results
of an SQL query that joins the data from multiple tables. The data
from each matching row in each joined table is combined into a single
row of data in the ResultSet object. By allowing one bean to contain
a java.util.List of other beans, a bean can contain multiple rows
of data from the ResultSet object. The nesting preserves the hierarchical
nature of the data in multiple tables and implements a one-to-many
relationship. Allowing one bean to contain another bean simplifies
the layout of a bean and implements a one-to-one relationship.
Many-to-many relationships can be simulated with multiple one-to-many
relationships and many-to-one relationships can be simulated with
multiple one-to-one relationships.
You can use a bean class with multiple SQL statements. The following
scenario describes how the same beans can be used in different situations:
- The Department bean could contain a list of Employee beans for
that Department and a list of Project beans for that Department
- The Employee bean could contain a list of Project beans that belong
to that employee and a list of Activity beans that the Employee participates
in.
- The Project bean could contain a list of Employee beans for the
employees that work on that project. It could also contain a single
Employee bean that had the information of project leader. It could
also contain a list of Activity beans that describe all activities
within the Project.
- The Activity bean could contain information about a project and
a list of Projects the Activity is used in.
- The reuse of these beans comes from various SQL that contains
differing information in the ResultSet, examples of these SQL queries
are:
- Join SQL that joins Department table columns, Employee table columns,
and Project table columns. Using the Department bean as the parent
bean you would get one or more Department beans. Each Department bean
contains a list of all the employees for that department and another
list of Projects for that department.
- Join SQL that joins the Employee table columns, Project table
columns, and Activity table columns. Using the Employee bean as the
parent bean you would get one or more Employee beans. Each Employee
bean contains a list of Projects for that employee and a list of Activity
beans that employee participates in.
- Join SQL that joins the Project table columns and Activity table
columns. Using the Project bean as the parent bean you would get one
or more Project beans. Each Project beans contains a list of Activity
beans for a Project.
- Join SQL that joins the Activity table columns and Project table
columns. Using the Activity bean as the parent bean you would get
one or more Activity beans. Each Activity bean contains a list of
Project beans that the Activity is used in.