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 14 – Best Practices 283<br />

@Select(sql="SELECT PROJECT.PROJNO, DEPARTMENT.DEPTNO " +<br />

"FROM PROJECT, DEPARTMENT " +<br />

"WHERE PROJECT.DEPTNO =<br />

DEPARTMENT.DEPTNO")<br />

List getProjectsDepartment();<br />

Listing 14.3 – Returning a types list of beans<br />

Using table collation to aggregate results form multiple tables leverages the table-to-bean<br />

mapping provided by <strong>pureQuery</strong> and prevents you from having to design complex beans<br />

that would store the result of the join SQL statement.<br />

14.4 Working with Exception categorization<br />

When <strong>pureQuery</strong> executes JDBC calls, it encapsulates any generated exception into<br />

unchecked exceptions, so that you don’t have to enclose all your <strong>pureQuery</strong> method calls<br />

in try/catch blocks. By using this process, <strong>pureQuery</strong> is also able to provide you with<br />

extended metadata about the generated exception when it encapsulates the base JDBC or<br />

SQL exception in a <strong>pureQuery</strong> DataRuntimeException. This metadata provides you with<br />

the version of <strong>pureQuery</strong> you are using, the associated SQL state and error code of the<br />

generated exception and also exception categorization information. <strong>pureQuery</strong> is<br />

aggregating errors and their causes into categories that let you better handle and recover<br />

from the error situation. Some example categories used by <strong>pureQuery</strong> are<br />

AUTHORIZATION_ERROR, CONSTRAINT_VIOLATION,<br />

DUPLICATE_ROW_VIOLATION, SYNTAX_ERROR, amongst others. For a complete list<br />

of all possible error types, please refer to the <strong>pureQuery</strong> documentation.<br />

When developing your application, it is recommended that you use these error types as a<br />

strategy for error handling and recovery, as it eliminates the need to handle individual error<br />

types for each <strong>pureQuery</strong> method call.<br />

14.5 Customizing the code generation templates<br />

<strong>pureQuery</strong> code generation tooling is based on JET (Java Emitter Templates), a generic<br />

template engine built into Eclipse that can be used to express code you want to generate.<br />

When you use the tooling to generate <strong>pureQuery</strong> code, there are templates for all the<br />

generated Java class files, as the bean representing the database table, the inline and<br />

annotated method style sample classes and even the JUnit test cases.<br />

ODS allows you to override the existing templates, to write customized code that you wish<br />

to have added automatically to each one of the generated classes. This code can be as<br />

simple as a copyright statement, or more complex like adding some setup code to the<br />

generated test cases. See the official <strong>pureQuery</strong> documentation for more information<br />

about creating Eclipse Modeling Framework Technologies (EMFT) Java Emitter Templates<br />

(JET) to generate customized code.

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

Saved successfully!

Ooh no, something went wrong!