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.

?n.name<br />

:name<br />

<strong>pureQuery</strong><br />

beans and<br />

Map objects<br />

<strong>pureQuery</strong><br />

beans and<br />

Map objects<br />

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

method parameter, ?2<br />

represents the second<br />

method parameter, and<br />

so forth.<br />

Directs <strong>pureQuery</strong> to use<br />

the value of the property<br />

name in the nth method<br />

parameter as the value<br />

of the SQL parameter.<br />

For example,<br />

?1.lastName<br />

represents the<br />

lastName property of<br />

first method parameter.<br />

The property name is<br />

case sensitive.<br />

Directs <strong>pureQuery</strong> to use<br />

the value of the property<br />

name in the first method<br />

parameter as the value<br />

of the SQL parameter.<br />

This is a shorter way of<br />

specifying ?1.name that<br />

is useful when only one<br />

<strong>pureQuery</strong> bean or Map<br />

object is specified. The<br />

property name is case<br />

sensitive.<br />

// <strong>pureQuery</strong> bean<br />

@Select(sql = "SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

?1.departmentNumber AND EMPNO<br />

!= ?1.managerEmployeeNumber")<br />

List<br />

selectDeptEmloyees<br />

(DepartmentBean dept);<br />

// Map<br />

@Select(sql = "SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

:departmentNumber AND EMPNO<br />

!= :managerEmployeeNumber")<br />

List<br />

selectDeptEmployees<br />

(DepartmentBean dept);<br />

// <strong>pureQuery</strong> bean<br />

@Select(sql = "SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

?1.departmentNumber AND EMPNO<br />

!= ?1.managerEmployeeNumber")<br />

List<br />

selectDeptEmployees<br />

(Map map);<br />

// Map<br />

@Select(sql = "SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

:departmentNumber AND EMPNO<br />

!= :managerEmployeeNumber")<br />

List<br />

selectDeptEmployees<br />

(Map map);<br />

Table 11.1 - Parameter markers in the annotated-method programming style<br />

11.5.1 In practice: Specify a scalar as a parameter to an SQL statement --<br />

Complete the “Login” screen<br />

When Human Resources Manager starts, it asks the user for his or her employee number.<br />

The application queries the database for information about the employee with that<br />

employee number. If the database contains an employee with that employee number, it<br />

displays the main menu. If it does not contain such an employee, the application exits.

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

Saved successfully!

Ooh no, something went wrong!