Les classes définissent des beans qui renvoient des données depuis l'exemple de requête SQL. La requête est utilisée comme requête SQL intégrée et dans l'exemple de classe d'interface.
Les méthodes de test JUnit appellent les méthodes pureQuery pour instancier et remplir les beans. La méthode de test répertorie les contenus des beans.
La classe Dept1 est le bean de niveau supérieur de l'ensemble de beans imbriqués pureQuery. La classe Dept1 définit des méthodes d'obtention et de définition pour l'ID et le nom du département depuis la table ORGANIZATION. Le bean définit également une méthode d'obtention et de définition pour les beans Emp.
Au moins une annotation @Id est requise pour un bean de niveau supérieur. L'annotation @JoinPoint référence la liste de beans Emp en tant que beans enfants. L'annotation @JoinColumn spécifie la colonne EMPLOYEE_CODE en tant que colonne d'identité qui associe des beans enfants Emp au bean parent Dept1. Lorsque le bean Dept1 est le bean parent, les annotations @Id dans le bean Emp sont ignorées car un @JoinColumn est spécifié.
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;
}
}
La classe Dept2 est utilisée avec le test pour le SQL intégré. La classe définit les zones publiques pour définir les propriétés du bean.
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;
}
La classe Emp contient les informations des tables EMPLOYEE et EMPOYEE_HISTORY. L'annotation @Table pour la classe spécifie la table EMPLOYEE. L'annotation @Column pour la méthode getWorkDept( ) spécifie la table EMPOYEE_HISTORY.
La classe contient des méthodes d'obtention et de définition pour les informations d'employé à partir des tables. L'annotation @Id spécifie la colonne EMPLOYEE_CODE qui identifie la colonne en tant que colonne d'identité pour l'annotation @JoinPoint dans la classe Dept2. Pour la classe Dept1, les valeurs de la propriété @JoinColumn définissent la colonne d'identité.
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;
}
}