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.

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

Chapter 10 – Inline Programming Style 189<br />

• An array: queryArray methods return an array in which each entry represents a<br />

row.<br />

• A java.util.List object: queryList methods return a<br />

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

• A java.util.Iterator object: queryIterator methods return a<br />

java.util.Iterator object for which each call to the Iterator's next()<br />

method returns a row. These methods do not fully materialize the information from<br />

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

each time the application calls the next method. This is particularly useful if your<br />

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

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

calls next() to retrieve all of the rows from the Iterator, <strong>pureQuery</strong> closes it<br />

automatically, freeing the associated database resources. However, if you have an<br />

application that does not retrieve all the rows, you must free the database resources<br />

by closing the Iterator explicitly. Do so by casting the Iterator object<br />

as a com.ibm.pdq.runtime.ResultIterator object and calling its<br />

close() method, like this: ((com.ibm.pdq.runtime.ResultIterator)<br />

myIterator).close()<br />

• Only the first row, in the object used to contain the row: queryFirst methods<br />

return only the first row. If the query result does not contain any rows, these<br />

methods return null.<br />

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

com.ibm.pdq.runtime.handlers.ResultHandler object: query<br />

methods use the parameter ResultHandler resultHandler to<br />

construct the object that is returned. For this method, there is not a parameter for<br />

specifying the format for each row. Instead, resultHandler determines the<br />

format that is used for each row.<br />

• A java.sql.ResultSet object: queryResults methods return an instance of<br />

java.sql.ResultSet.<br />

10.3.2 Overriding the default cursor attributes<br />

By default, inline methods use the cursor type “forward only,” the cursor concurrency mode<br />

“read only,” and the cursor holdability “close cursors at commit.” You can change the<br />

values of these attributes by using an inline method that has these parameters: int<br />

type, int concurrency, int holdability

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

Saved successfully!

Ooh no, something went wrong!