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.

230<br />

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

Listing 11.25 - An SQL statement for updating an employee’s last name<br />

UPDATE EMPLOYEE SET FIRSTNME = [new first name] WHERE EMPNO = [original<br />

employee number]<br />

Listing 11.26 - An SQL statement for updating an employee’s first name<br />

Since we are executing UPDATE statements, we use the<br />

com.ibm.pdq.annotation.Update annotation. We want the methods to return an<br />

update count, so we use int as the return type.<br />

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

information about the employee will be available in the EmployeeBean object that<br />

describes the employee. Refer to Table 11.1, which lists the various types of parameter<br />

markers. Both the ?n.name type of parameter marker and the :name type that the<br />

information is a property in a <strong>pureQuery</strong> bean. We choose to use the :name type.<br />

Add annotated methods for these SQL statements. You need one method for each of the<br />

following columns: LASTNAME, FIRSTNME, MIDINIT, EDLEVEL, BIRTHDATE, JOB,<br />

SALARY, BONUS, and COMM. The corresponding properties in EmployeeBean are,<br />

respectively: lastName, firstName, middleInitial, educationLevel, birthDate,<br />

job, salary, bonus, and commission. Listing 11.27 and Listing 11.28 show two of the<br />

annotated methods; the remaining methods are similar. You can refer to the completed<br />

methods in hrm.completed.pdqMethodStyle.HumanResourcesData if you want<br />

help. After you have added the methods, build your project so that Optim Development<br />

Studio will generate an updated implementation class.<br />

@Update(sql = "UPDATE EMPLOYEE SET LASTNAME = :lastName WHERE EMPNO =<br />

:employeeNumber")<br />

int updateEmployeeLastName (EmployeeBean employee);<br />

Listing 11.27 - An annotated method that updates an employee’s last name<br />

@Update(sql = "UPDATE EMPLOYEE SET FIRSTNME = :firstName WHERE EMPNO =<br />

:employeeNumber")<br />

int updateEmployeeFirstName (EmployeeBean employee);<br />

Listing 11.28 - An annotated method that updates an employee’s first name<br />

11.6.2.2 Modify the changeEmployeeInformation() method to use the new<br />

annotated methods<br />

Modify the changeEmployeeInformation method in<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesManager to use the new<br />

annotated methods to update the database. Listing 11.29 and Listing 11.30 show two of<br />

the changes; the remaining changes are similar.<br />

// Update the last name in the database<br />

updateCount = data.updateEmployeeLastName (employee);

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

Saved successfully!

Ooh no, something went wrong!