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.

11.4.1.3 Methods with the @Call annotation<br />

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

• What do you want the method to return?<br />

o<br />

o<br />

o<br />

o<br />

A com.ibm.pdq.runtime.StoredProcedureResult object:<br />

Specify com.ibm.pdq.runtime.StoredProcedureResult<br />

as the return type. <strong>pureQuery</strong> automatically creates and return a<br />

StoredProcedureResult object containing the query results.<br />

void: Specify void as the return type if the stored procedure<br />

will not produce any results that you want the method to return.<br />

The first query result: If you want the method to return only the<br />

first query result, using one of the return types allowed with the<br />

@Select annotation, specify the return type that you want to<br />

use. You can use any of the types that are allowed for @Select,<br />

except for those that involve either a ResultHandler or a<br />

RowHandler and those that return only a single row of the query<br />

result.<br />

An object of a specific type, constructed by a<br />

com.ibm.pdq.runtime.handlers.CallHandlerWithPara<br />

meters object: Specify the parameterized type<br />

(represented by CAL) as the return type of the method. You will<br />

have to specify the CallHandlerWithParameters that<br />

will construct the object.<br />

11.4.2 In practice: Execute a simple SELECT statement that uses cursor<br />

attributes -- Complete the “Company Employees” screen<br />

The Company Employees screen displays all of the employees in the company in pages of<br />

10 employees each. It allows the user to request additional information about any<br />

particular employee on the screen. The displayAllEmployees (Data data) method<br />

creates this screen. Add the <strong>pureQuery</strong> code to it to get the employee information from the<br />

database using the annotated-method style.<br />

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

First, we need to determine an SQL statement to use. We will use the query shown in<br />

Listing 11.8, which will select all the employees and sort them by their names.<br />

SELECT * FROM EMPLOYEE ORDER BY LASTNAME, FIRSTNME, MIDINIT<br />

Listing 11.8 - An SQL query for selecting all the employees in the company<br />

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

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

query.

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

Saved successfully!

Ooh no, something went wrong!