16.10.2015 Views

Getting Startedwith pureQuery

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

226<br />

<strong>Getting</strong> Started with <strong>pureQuery</strong><br />

?1.departmentNumber. Note how easy it is to specify multiple parameters to an SQL<br />

statement!<br />

Add the method shown in Listing 11.17 to<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesData. After you have added<br />

the method, build your project so that Optim Development Studio will generate an updated<br />

implementation class.<br />

@Select(sql = "SELECT e.EMPNO, e.FIRSTNME, e.MIDINIT, e.LASTNAME, "<br />

+ "e.WORKDEPT, e.PHONENO, e.HIREDATE, e.JOB, e.EDLEVEL, e.SEX, "<br />

+ "e.BIRTHDATE, e.SALARY, e.BONUS, e.COMM FROM "<br />

+ "(EMPLOYEE e INNER JOIN DEPARTMENT d ON (e.WORKDEPT = d.DEPTNO)) WHERE<br />

"<br />

// The employee is not his or her own manager.<br />

+ "(e.EMPNO ?1.employeeNumber) AND "<br />

// If the employee is not the manager of his or her department, find the<br />

// manager of his or her department.<br />

+ "(((0 = (SELECT COUNT(*) FROM DEPARTMENT WHERE "<br />

+ "MGRNO = ?1.employeeNumber AND DEPTNO = ?1.departmentNumber)) "<br />

+ "AND (e.WORKDEPT = ?1.departmentNumber) AND (e.EMPNO = d.MGRNO)) "<br />

// If the employee is the manager of his or her department, find the<br />

// manager of the department that administers it.<br />

+ "OR ((1 = (SELECT COUNT(*) FROM DEPARTMENT WHERE "<br />

+ "MGRNO = ?1.employeeNumber AND DEPTNO = ?1.departmentNumber)) "<br />

+ "AND e.WORKDEPT = (SELECT ADMRDEPT FROM DEPARTMENT "<br />

+ "WHERE DEPTNO = ?1.departmentNumber) AND e.EMPNO = d.MGRNO))")<br />

public EmployeeBean selectEmployeeManager (EmployeeBean employee);<br />

Listing 11.17 - Add an annotated method to the HumanResourcesData interface that<br />

creates an EmployeeBean object for the manager of the specified employee<br />

11.5.2.2 Modify the displayEmployeeInformation() method to use the new<br />

annotated method<br />

In hrm.inProgress.pdqMethodStyle.HumanResourcesManager, modify the<br />

displayEmployeeInformation method in as shown in Listing 11.18 so that it uses the<br />

new annotated method to query the database and create the EmployeeBean object<br />

representing the employee’s manager.<br />

// Add the manager of the employee.<br />

EmployeeBean manager = data.selectEmployeeManager (employee);<br />

Listing 11.18 - Modify the displayEmployeeInformation method to use the<br />

annotated method<br />

The displayEmployeeInformation method calls the utility method<br />

isEmployeeManagedByLoggedInUser. In that method as well, add code as in Listing

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!