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 11 – Annotated-Method Programming Style 209<br />

Figure 11.2 shows the return types that user-defined annotated methods can have.<br />

RowType[]<br />

RowType<br />

Iterator<br />

List<br />

ResultSet<br />

ResultType<br />

Instance of<br />

User-defined interface<br />

User-defined method<br />

@Select(sql=“SELECT …”)<br />

User-defined method<br />

@Update(sql=“INSERT …”)<br />

User-defined method<br />

@Update(sql=“UPDATE …”)<br />

User-defined method<br />

@Update(sql=“DELETE …”)<br />

User-defined method<br />

@Call(sql=“CALL …”)<br />

Update<br />

count<br />

Update<br />

counts<br />

RowType[]<br />

Iterator<br />

List<br />

ResultSet<br />

StoredProcedureResult<br />

CallResultType<br />

Figure 11.2 - The possible return types of user-defined annotated methods<br />

In Figure 11.2, RowType represents the format in which each row of a query result is<br />

returned. There are a number of ways to specify this. ResultType represents the format<br />

that is specified by the parameterized type RES of a<br />

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

represents the format that is specified by the parameterized type CAL of a<br />

com.ibm.pdq.runtime.handlers.CallHandlerWithParameters object.<br />

Chapter 8 discusses <strong>pureQuery</strong> handlers.<br />

There are several benefits to using the annotated-method programming style. These are<br />

some of them:<br />

• You can speed-up your application development. <strong>pureQuery</strong> generates<br />

the method implementations. All you have to do is declare methods with<br />

your choice of parameters and return types, and write the SQL statements<br />

for the methods to execute. The tools take care of the rest of the work.<br />

• You can choose from a wide variety of return types for the query results.<br />

A few of the possible formats are a single <strong>pureQuery</strong> bean, a single<br />

java.util.Map, a collection of <strong>pureQuery</strong> beans, and a collection of<br />

Maps.<br />

• If you are using the IBM ® DB2 ® Database, you can easily switch between<br />

dynamic and static execution of the SQL. Static SQL has many<br />

performance, reliability, and security advantages. For a brief description<br />

of static SQL see Appendix C.

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

Saved successfully!

Ooh no, something went wrong!