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.

264<br />

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

Customizing output:<br />

• If you are executing an SQL SELECT statement, and you want to<br />

customize the way <strong>pureQuery</strong> sets the parameters to the SQL statement,<br />

use a query method that accepts an object of type ParameterHandler<br />

as a parameter. Note that this method also has a<br />

ResultHandler parameter.<br />

• If you are executing an SQL stored procedure call, and you want to<br />

customize the way <strong>pureQuery</strong> sets the parameters to the SQL call<br />

statement, use the call method that accepts an object of type<br />

ParameterHandler as a parameter. Note that this method also has a<br />

CallHandlerWithParameters parameter.<br />

• If you are executing an SQL SELECT statement, and you want to<br />

customize how each row is returned, use one of the queryXXX methods<br />

that accept an object of type RowHandler as a parameter. Use<br />

the queryXXX method that has the return type that you want.<br />

• If you are executing an SQL SELECT statement, and you want to use a<br />

type of object to contain all of the rows that is not one of <strong>pureQuery</strong>'s built<br />

in objects, use one of the query methods. These methods have a<br />

ResultHandler parameter.<br />

• If you are executing an SQL stored procedure call, and you want to use<br />

an object other than <strong>pureQuery</strong>'s<br />

com.ibm.pdq.runtime.StoredProcedureResult to contain the<br />

query results, use one of the call methods that accepts an object of type<br />

CallHandlerWithParameters as a parameter.<br />

13.2.1 In practice: Specify a handler using the inline style -- Complete the<br />

“Company Employees” screen<br />

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

of 10 employees each. Let’s use the IteratorPagingResultHandler to retrieve<br />

the employees, one page at a time. Modify the displayAllEmployees method in<br />

hrm.inProgress.pdqInlineStyleWithHandlers.HumanResourcesManager.<br />

You will also need to modify the utility method selectPageOfEmployees, which is<br />

located in the same class.<br />

13.2.1.1 Use <strong>pureQuery</strong> to create an Iterator object that contains<br />

the information about the employees<br />

In order to get information about all the employees in the company, we need to execute a<br />

query against the database. We will use the query shown in Listing 13.1, which will select<br />

all the employees and sort them by their names.

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

Saved successfully!

Ooh no, something went wrong!