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.

13<br />

Chapter 13 - Handlers<br />

In this chapter, you will learn how to use handlers to modify how <strong>pureQuery</strong> returns query<br />

results, and how <strong>pureQuery</strong> sets the values of SQL parameters.<br />

13.1 Handlers: The big picture<br />

<strong>pureQuery</strong> provides a wide variety of ways to specify parameters for the SQL statements<br />

that you execute, along with many formats for returning query results. However, there<br />

might be times when the built-in functionality does not meet the needs of your application.<br />

In these cases, you can use handlers to customize various aspects of <strong>pureQuery</strong><br />

processing by writing classes that implement the handler interfaces. <strong>pureQuery</strong> provides<br />

the following types of handlers:<br />

Customizing input:<br />

Customizing output:<br />

• com.ibm.pdq.runtime.handlers.ParameterHandler: You can<br />

use a ParameterHandler object to determine how the <strong>pureQuery</strong> sets the<br />

values of parameters in prepared SQL statement. The interface defines a<br />

method named handleParameters that <strong>pureQuery</strong> calls to set the<br />

values of the parameters in the SQL statement.<br />

• com.ibm.pdq.runtime.handlers.RowHandler: You can use<br />

a RowHandler object to determine how <strong>pureQuery</strong> returns each<br />

row of a query result. Use this when you want to use one of <strong>pureQuery</strong>'s<br />

built-in objects for returning all the rows, but you want to modify the way<br />

<strong>pureQuery</strong> returns each row. The RowHandler interface defines a<br />

method named handle. <strong>pureQuery</strong> processes each row of the query<br />

result by calling this method. The handle method returns an object of<br />

type ROW, which <strong>pureQuery</strong> uses to represent the row in the object that<br />

the annotated or inline method returns. If you are using the annotatedmethod<br />

style to execute an SQL INSERT statement, and if you use a<br />

single <strong>pureQuery</strong> bean to provide the values of the SQL parameters,<br />

<strong>pureQuery</strong> can update properties in the bean with values generated by

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

Saved successfully!

Ooh no, something went wrong!