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.

222<br />

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

If the functionality of <strong>pureQuery</strong>’s parameter markers does not meet the needs of your<br />

application, you can write an implementation of the<br />

com.ibm.pdq.runtime.handlers.ParameterHandler interface to set the<br />

parameters appropriately.<br />

// Scalars<br />

String deptNo = "C01";<br />

String managerEmpNo = "000030";<br />

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

DepartmentBean dept = new DepartmentBean ();<br />

dept.setDepartmentNumber ("C01");<br />

dept.setManagerEmployeeNumber ("000030");<br />

// Map<br />

Map map = new HashMap ();<br />

map.put ("departmentNumber", "C01");<br />

map.put ("managerEmployeeNumber", "000030");<br />

Listing 11.12 - Definitions of the objects referenced in the "Sample usage" column of<br />

Table 11.1<br />

Marker<br />

Types of<br />

objects in<br />

method<br />

parameters<br />

Meaning<br />

Sample usage<br />

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

the value of one of the<br />

method parameters as<br />

the value of this SQL<br />

parameter. The first ?<br />

represents the first<br />

method parameter, the<br />

second ? represents the<br />

second method<br />

parameter, and so forth.<br />

?n Scalars Directs <strong>pureQuery</strong> to use<br />

the value of the nth<br />

method parameter as<br />

the value of the SQL<br />

parameter. ?1<br />

represents the first<br />

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

EMPLOYEE WHERE WORKDEPT = ?<br />

AND EMPNO != ?")<br />

List<br />

selectDeptEmployees (String<br />

deptNo, String managerEmpNo);<br />

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

EMPLOYEE WHERE WORKDEPT = ?1<br />

AND EMPNO != ?2")<br />

List<br />

selectDeptEmployees (String<br />

deptNo, String managerEmpNo);

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

Saved successfully!

Ooh no, something went wrong!