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.

208<br />

<strong>Getting</strong> Started with <strong>pureQuery</strong><br />

application. After an implementation class has been generated for an interface, you can<br />

create an instance of the interface using DataFactory (which actually creates an instance of<br />

the generated implementation class whose name ends in “...Impl”) and run its methods, as<br />

shown in Listing 11.2.<br />

DepartmentData data = DataFactory.getData (DepartmentData.class,<br />

connection);<br />

List allDepartments = data.selectAllDepartments());<br />

// Iterate through the departments<br />

DepartmentBean department = data.selectDepartmentByNumber<br />

(departmentNumber);<br />

// Do something with the department<br />

Listing 11.2 - A simple example of using the annotated-method style to execute two<br />

SQL statements<br />

Figure 11.1 shows how you can create an instance of a user-defined interface.<br />

DataFactory<br />

User-defined<br />

Interface<br />

getData(…)<br />

User input:<br />

Connection<br />

DataSource<br />

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

Generator<br />

Utility<br />

Implementation<br />

Class of<br />

User-defined<br />

Interface<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 />

Figure 11.1 - Creating an instance of a user-defined interface

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

Saved successfully!

Ooh no, something went wrong!