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.

Chapter 9 – Persistence Frameworks and Data Access: Context for <strong>pureQuery</strong> 175<br />

INSERT INTO none getEmpno() Parameter marker name is a case<br />

EMPLOYEE(EMPNO)<br />

insensitive match to a field with a<br />

VALUES :empno<br />

public accessor method<br />

Table 9.1 – Examples of default <strong>pureQuery</strong> bean mapping without annotations<br />

Even though the <strong>pureQuery</strong> data access layer covers a wide variety of basic mappings by<br />

default, there are cases when the user might want to override the default mapping<br />

mechanism.. If so, the user will specify the mapping by using the Annotations described<br />

above in the bean definition. Table 3.2 gives examples for using Annotations to override<br />

the default <strong>pureQuery</strong> mapping mechanism:<br />

sql property<br />

of annotated<br />

method<br />

SELECT<br />

FIRSTNM FROM<br />

EMPLOYEE<br />

SELECT<br />

GOESBYNAME<br />

FROM<br />

EMPLOYEE<br />

INSERT INTO<br />

EMPLOYEE<br />

(LASTNAME)<br />

VALUES<br />

(:lastname)<br />

<strong>pureQuery</strong> bean Annotation<br />

@Column (name=”firstnm”)<br />

@ColumnOverride<br />

(column=”goesbyname”,<br />

propertyName=”firstName”)<br />

@GeneratedKey<br />

Bean field or<br />

method<br />

<strong>pureQuery</strong> mapping<br />

rule<br />

setFirstName() @Column annotation<br />

specifies non default<br />

mapping between a<br />

result column name<br />

and a property’s<br />

public accessor<br />

method using a case<br />

insensitive match with<br />

the result column<br />

name<br />

setFirstName() @ColumnOverride<br />

annotation at the<br />

bean class level<br />

overrides any other<br />

mappings<br />

getEmpno()<br />

Before an annotated<br />

method with a bean<br />

parameter returns, the<br />

bean field<br />

corresponding to the<br />

@GeneratedKey<br />

annotation will be<br />

populated using the<br />

value returned from<br />

the database<br />

Table 9.2 – Examples of <strong>pureQuery</strong> bean mapping using annotations

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

Saved successfully!

Ooh no, something went wrong!