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.

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

11.19 so that it uses the new annotated method to search the database for a employee’s<br />

manager.<br />

// Determine if the logged-in user manages the employee by going<br />

// up the management chain until we either find the logged-in<br />

// user, or until we reach the highest manager in the company.<br />

EmployeeBean manager;<br />

while (null != (manager = data.selectEmployeeManager (employee))) {<br />

Listing 11.19 - Modify the isEmployeeManagedByLoggedInUser method to use the<br />

annotated method<br />

11.5.2.3 Test the "Company Employees" screen<br />

Save and test your application. Supply 000030 when the Human Resources Manager<br />

asks for your employee number. On the main menu, select option 1 to display information<br />

about Sally Kwan.<br />

11.5.3 Special case scenarios for parameter types<br />

Some scenarios call for specific parameter types. When you declare an annotated<br />

method, see if your application falls under one of these special cases.<br />

11.5.3.1 Methods with the @Update annotation<br />

• Executing an SQL statement multiple times with different parameters<br />

each time: If you want <strong>pureQuery</strong> to execute the SQL statement multiple<br />

times, using different parameters each time, specify a<br />

java.util.List, java.util.Iterator, or array in which<br />

entry provides objects for setting the parameters. <strong>pureQuery</strong> executes<br />

the SQL statement once for each entry. If you use an array for this<br />

purpose, you must not use an array of type Object[].<br />

• Creating generated keys: If your method is executing an INSERT<br />

statement, <strong>pureQuery</strong> can update the values of keys generated by the<br />

statement. To use this feature, provide the parameters for the SQL<br />

statement using one <strong>pureQuery</strong> bean, and provide the<br />

com.ibm.pdq.annotation.GeneratedKey annotation on the<br />

properties you want <strong>pureQuery</strong> to update.<br />

11.5.3.2 Methods with the @Call annotation<br />

• Updating the values of OUT and INOUT parameters: If the method<br />

does not specify a CallHandlerWithParameters, and if the<br />

method executes a stored procedure that has OUT or INOUT parameters,<br />

<strong>pureQuery</strong> updates the corresponding properties in maps or <strong>pureQuery</strong><br />

beans provided as method parameters after the execution of the stored

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

Saved successfully!

Ooh no, something went wrong!