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 12 – Stored Procedures 253<br />

this to happen, we need to specify the parameters in java.util.Map<br />

objects or <strong>pureQuery</strong> beans.<br />

We choose to use the first approach. You can implement the second approach as an<br />

exercise if you wish.<br />

As for the inline style, we will specify the values of the IN parameters by using variables of<br />

the type double, and we will use the ? type of parameter markers. We specify parameters<br />

for all of the stored procedure parameters, but what we specify for the OUT parameters<br />

does not matter, as long as some parameter is referenced by the parameter marker. Add<br />

the annotated method in Listing 12.9 to the<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesData interface and build the<br />

project so that the <strong>pureQuery</strong> Generator regenerates the implementation class.<br />

// Execute the bonus_increase stored procedure.<br />

@Call(sql = "CALL bonus_increase (?, ?, ?, ?, ?, ?)")<br />

StoredProcedureResult callBonusIncrease (double bonusFactor,<br />

double bonusMaxSumForDepartment, String departmentsWithoutNewBonuses,<br />

int countDepartmentsViewed, int countDepartmentsBonusChanged, String<br />

errorMessage);<br />

Listing 12.9 - An annotated method that executes the stored procedure<br />

Add code to the increaseEmployeeBonuses method in<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesManager that calls the<br />

annotated method. The values for the parameters that represent the OUT parameters do<br />

not matter, so specify null and 0. Listing 12.10 shows the completed code.<br />

// Execute the bonus_increase stored procedure.<br />

storedProcedureResult = data.callBonusIncrease (bonusFactor,<br />

bonusMaxSumForDepartment,<br />

null, 0, 0, null);<br />

Listing 12.10 - Code that calls the annotated method callBonusIncrease<br />

After the StoredProcedureResult object is created, the application must get the OUT<br />

parameters first, and then the query results, just as in inline style. Finally, the application<br />

should close the Iterator object and storedProcedureResult.<br />

The procedure for doing all of these things is identical to that in the inline method style, and<br />

the code is the same, too. Refer to Section 12.3.1 to add the necessary code. Finally, test<br />

the application by logging in with the employee number 000010 and selecting the option 5<br />

on the main menu.<br />

12.5 Summary<br />

Both the inline style and the annotated-method style provide ways to execute SQL stored<br />

procedure calls. The inline style provides methods named call in the<br />

com.ibm.pdq.runtime.Data interface for this purpose. The annotated-method style<br />

provides the com.ibm.pdq.annotation.Call annotation for placing on methods to

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

Saved successfully!

Ooh no, something went wrong!