16.10.2015 Views

Getting Startedwith pureQuery

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 11 – Annotated-Method Programming Style 225<br />

Listing 11.15 - An annotated method that creates an EmployeeBean object for the<br />

employee with the specified employee number<br />

11.5.1.2 Modify the displayLogin() method to use the new annotated method<br />

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

displayLogin method to use the new annotated method to query the database and<br />

create the EmployeeBean object. This is shown in Listing 11.16.<br />

// Search the database for an employee with the employee number that the<br />

// user entered.<br />

employeeUsedForLogin = data.selectEmployee (employeeNumber);<br />

Listing 11.16 - Modify the displayLogin() method to use the annotated method<br />

11.5.2 In practice: Specify a <strong>pureQuery</strong> bean as a parameter to an SQL<br />

statement-- Complete the “Employee Information” screen<br />

The "Employee Information" screen displays detailed information for a single employee.<br />

The displayEmployeeInformation method has an EmployeeBean parameter that<br />

provides details about the employee. The screen also displays summary information about<br />

the manager of the employee. Information about an employee’s manager is not included in<br />

an EmployeeBean object. Add an annotated method that gets the information about an<br />

employee’s manager.<br />

11.5.2.1 Add an annotated method to HumanResourcesData that executes the SQL<br />

We next need an SQL statement to determine the manager of an employee... Listing<br />

10.12 shows the SQL query that we will use to select the information about the employee<br />

who manages the specified employee. This SQL statement is described in Section 6.4.2.1.<br />

Next, we need to declare an annotated method in<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesData that will execute this<br />

query. Since we are executing a SELECT statement, we use the<br />

com.ibm.pdq.annotation.Select annotation. We want the method to return the<br />

manager’s information in an EmployeeBean object, and there will be at most one row, so<br />

we choose to have EmployeeBean as the return type of the method.<br />

We will use <strong>pureQuery</strong> parameter markers for the parameters to the SQL. We need the<br />

employee number and the department number for the employee. Both of these pieces of<br />

information are available in the EmployeeBean object that is a parameter to the method.<br />

Refer to Table 11.1, which lists the various types of parameter markers. Both the ?n.name<br />

type of parameter marker and the :name type expect that the information is a property in a<br />

<strong>pureQuery</strong> bean. We choose to use the ?n.name type. The names of the appropriate<br />

properties in EmployeeBean are employeeNumber and departmentNumber.<br />

Therefore, the two parameter markers are ?1.employeeNumber and

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

Saved successfully!

Ooh no, something went wrong!