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 10 – Inline Programming Style 193<br />

?n.name<br />

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

beans and<br />

Map objects<br />

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

use the value of the<br />

property name in the<br />

nth object in<br />

parameters as the<br />

value of the SQL<br />

parameter. For<br />

example,<br />

?1.lastName<br />

represents the<br />

lastName property of<br />

first object. The<br />

property name is case<br />

sensitive.<br />

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

List employees =<br />

data.queryList ("SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

?1.departmentNumber AND EMPNO<br />

!= ?1.managerEmployeeNumber<br />

EmployeeBean.class, dept);<br />

// Map<br />

List employees =<br />

data.queryList ("SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

?1.departmentNumber AND EMPNO<br />

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

EmployeeBean.class, map);<br />

:name<br />

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

beans and<br />

Map objects<br />

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

use the value of the<br />

property name in the<br />

first object in<br />

parameters as the<br />

value of the SQL<br />

parameter. This is a<br />

shorter way of<br />

specifying ?1.name<br />

that is useful when<br />

only one <strong>pureQuery</strong><br />

bean or Map object is<br />

specified. The<br />

property name is case<br />

sensitive.<br />

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

List employees =<br />

data.queryList ("SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

:departmentNumber AND EMPNO !=<br />

:managerEmployeeNumber",<br />

EmployeeBean.class, dept);<br />

// Map<br />

List employees =<br />

data.queryList ("SELECT * FROM<br />

EMPLOYEE WHERE WORKDEPT =<br />

:departmentNumber AND EMPNO !=<br />

:managerEmployeeNumber",<br />

EmployeeBean.class, map);<br />

Table 10.1 - Parameter markers in the inline-method programming style<br />

10.4.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.<br />

The original code provided in the displayLogin method of<br />

hrm.inProgress.pdqInlineStyle.HumanResourcesManager does not query the<br />

database for the employee; instead, it just creates an empty EmployeeBean object. This<br />

is shown in Listing 10.9.

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

Saved successfully!

Ooh no, something went wrong!