Classes that define pureQuery nested beans

You create Java classes that define the pureQuery nested beans. The annotations on the properties in the classes define the hierarchy of the nested beans.
These classes define the example pureQuery nested beans:
  • Dept1 class defines a top-level bean. The bean properties are defined by get and set methods.
  • Dept2 class defines a top-level bean. The bean properties are defined by public fields.
  • Emp class defines the child bean that is used with the interface and the inline SQL statement.
In this example, the Dept1 bean is used with an interface and the Dept2 bean is used with an inline SQL statement.

The classes define beans that return data from the example SQL query. The query is used as an inline SQL Query and in the example interface class.

JUnit test methods call pureQuery methods to instantiate and populate the beans. The test method lists the contents of the beans.

Dept1 class that is referenced in the example interface

The Dept1 class is the top-level bean of the set of pureQuery nested beans. The Dept1 class defines get and set methods for the department ID and department name from the table ORGANIZATION. The bean also defines a get and set method for Emp beans.

At least one @Id annotation is required for a top-level bean. The @JoinPoint annotation references the list of Emp beans as the child beans. The @JoinColumn annotation specifies the EMPLOYEE_CODE column as the identity column that links the Emp child beans to the parent Dept1 bean. When the Dept1 bean is the parent bean, @Id annotations in the Emp bean are ignored because an @JoinColumn is specified.

package mytest;

import java.util.List;

import com.ibm.pdq.annotation.Column;
import com.ibm.pdq.annotation.Id;
import com.ibm.pdq.annotation.JoinColumn;
import com.ibm.pdq.annotation.JoinPoint;
import com.ibm.pdq.annotation.Table;

@Table(name = "ORGANIZATION")
public class Dept1 {
    private String deptCode;
    private String deptNameEn;
    private List<Emp> deptEmployees;

    @Id
    @Column(name = "ORGANIZATION_CODE")
    public String getDeptCode() {
        return deptCode;
    }

    public void setDeptCode(String orgCode) {
        this.deptCode = orgCode;
    }

    @Column(name = "ORGANIZATION_NAME_EN")
    public String getDeptNameEn() {
        return deptNameEn;
    }

    public void setDeptNameEn(String orgNameEn) {
        this.deptNameEn = orgNameEn;
    }

    @JoinPoint(@JoinColumn(name = "EMPLOYEE_CODE", table = "EMPLOYEE", propertyName = "employeeId"))
    public List<Emp> getDeptEmployees() {
        return deptEmployees;
    }

    public void setDeptEmployees(List<Emp> deptEmployees) {
        this.deptEmployees = deptEmployees;
    }

}

Dept2 class that is referenced with an inline SQL query

The Dept2 class is used with the test for inline SQL. The class defines public fields to define the bean properties.

At least one @Id annotation is required for top-level bean. The @JoinPoint annotation references the list of Emp beans as the child beans. The @JoinPoint annotation does not contain a @JoinColumn annotation to specify the identity column. When a @JoinColumn annotation is not specified, the child bean property with @Id annotation is used. In the example Emp class, the @Id annotation is on the property for the EMPLOYEE_CODE column of the EMPLOYEE table.
package mytest;

import java.util.List;

import com.ibm.pdq.annotation.Column;
import com.ibm.pdq.annotation.Id;
import com.ibm.pdq.annotation.JoinColumn;
import com.ibm.pdq.annotation.JoinPoint;
import com.ibm.pdq.annotation.Table;

@Table(name = "ORGANIZATION")
public class Dept2 {

    @Id
    @Column(name = "ORGANIZATION_CODE")
    public String deptCode;

    @Column(name = "ORGANIZATION_NAME_EN")
    public String deptNameEn;

    @JoinPoint
    public List<Emp> deptEmployees;

}

Emp class that is referenced in the example

The Emp class contains the information from the EMPLOYEE and EMPOYEE_HISTORY tables. The @Table annotation for the class specifies the EMPLOYEE table. The @Column annotation for the getWorkDept( ) method specifies the table EMPOYEE_HISTORY.

The class contains get and set methods for employee information from the tables. The @Id annotation specifies the EMPLOYEE_CODE column that identifies the column as the identity column for the @JoinPoint annotation in the Dept2 class. For the Dept1 class, the @JoinColumn property values define the identity column.

package mytest;

import com.ibm.pdq.annotation.Column;
import com.ibm.pdq.annotation.Id;
import com.ibm.pdq.annotation.Table;

@Table(name = "EMPLOYEE")
public class Emp {
    private Integer employeeId;
    private String firstName;
    private String lastName;
    private String workDept;
    private java.sql.Date hireDate;

    @Id
    @Column(name = "EMPLOYEE_CODE")
    public Integer getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(Integer empCode) {
        this.employeeId = empCode;
    }

    public String toString() {
        return " ID: " + employeeId;
    }

    @Column(name = "FIRST_NAME")
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name = "LAST_NAME")
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name = "ORGANIZATIION_CODE", table = "EMPLOYEE_HISTORY")
    public String getWorkDept() {
        return workDept;
    }

    public void setWorkDept(String workDept) {
        this.workDept = workDept;
    }

    @Column(name = "DATE_HIRED")
    public java.sql.Date getHireDate() {
        return hireDate;
    }

    public void setHireDate(java.sql.Date hireDate) {
        this.hireDate = hireDate;
    }
}

Feedback