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.
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;
}
}
The Dept2 class is used with the test for inline SQL. The class defines public fields to define the bean properties.
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;
}
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;
}
}