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.

11.4.1 Declaring the return type<br />

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

Use the following questions as a guide to help you select the right return type for your<br />

annotated methods.<br />

11.4.1.1 Methods with the @Select annotation<br />

• What format do you want to use for each row?<br />

o<br />

o<br />

o<br />

A <strong>pureQuery</strong> bean or a scalar: <strong>pureQuery</strong> creates and populates<br />

the object automatically. For <strong>pureQuery</strong> beans, <strong>pureQuery</strong> uses<br />

the rules defined in Section 3.31 to determine the bean property<br />

that represents each column that is selected from the database.<br />

When <strong>pureQuery</strong> cannot find a property that represents a column<br />

in the SQL statement, <strong>pureQuery</strong> does not store the value of that<br />

column in the bean. For scalars, <strong>pureQuery</strong> constructs an object<br />

and attempts to store the contents of the first column of the query<br />

result in that object.<br />

An object of a specific type, constructed by a<br />

com.ibm.pdq.runtime.handlers.RowHandler<br />

object: You will have to specify the RowHandler that will<br />

construct the object.<br />

A java.util.Map object: <strong>pureQuery</strong><br />

constructs a Map in which the keys contain the labels of the<br />

columns and the values contain the contents of the columns.<br />

• What object do you want to contain all of the rows?<br />

o<br />

o<br />

o<br />

An array in which each entry represents a row: Specify an array<br />

as the return type, such as MyPureQueryBean[].<br />

A java.util.List object in which each element represents a<br />

row: Specify the parameterized List as the return type, such as<br />

java.util.List.<br />

A java.util.Iterator object for which each call to the<br />

Iterator's next() method returns a row. Specify the<br />

parameterized Iterator as the return type, such as<br />

java.util.Iterator. Methods with<br />

this return type do not fully materialize the information from the<br />

database during the initial method call. Instead, <strong>pureQuery</strong><br />

retrieves one row each time the application calls the next<br />

method. This is particularly useful if your application retrieves<br />

large amounts of information from the database, and you do not<br />

want to store all of the information in memory at one time. When<br />

the application calls next() to retrieve all of the rows from the

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

Saved successfully!

Ooh no, something went wrong!