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

Development Studio for development, and that you have added <strong>pureQuery</strong> support to the<br />

<strong>Getting</strong>StartedWithPureQuery project. If you have not already added <strong>pureQuery</strong><br />

support to your project, refer to Section 2.4.1 for instructions.<br />

The Generator utility uses metadata about your database to know how to generate the<br />

code that processes the tables in your database. Therefore, the Generator utility relies on<br />

Optim Development Studio having a live database connection, or on using the “work<br />

offline” feature in which it stores metadata locally. The “In practice” sections in this chapter<br />

assume that you have a live database connection in Optim Development Studio, or that<br />

you are using the “work offline” feature.<br />

11.2.2 In practice: Observe the HumanResourcesData interface<br />

Human Resources Manager uses only one interface of annotated methods:<br />

HumanResourcesData. Locate the declaration of this interface in the<br />

hrm.inProgress.pdqMethodStyle package.<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesData does not yet contain any<br />

annotated methods. You can add them in the “In practice” sections in this chapter.<br />

11.2.3 In practice: Create an instance of an interface of annotated methods in<br />

the displayLogin() method<br />

The Human Resources Manager application creates a single instance of<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesData in the displayLogin()<br />

method, passes that instance to other methods as required, and then closes the instance<br />

before the application exits. Modify the displayLogin() method in the class<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesManager so that it creates and<br />

closes an instance of hrm.inProgress.pdqMethodStyle.HumanResourcesData.<br />

11.2.3.1 Add code to the displayLogin() method to create the<br />

HumanResourcesData object<br />

Since we are using the annotated-method programming style, we need a getData method<br />

that takes a Class interfaceClass parameter. We will be using a database, so<br />

we choose a method that has a javax.sql.DataSource parameter. We choose the<br />

method shown in Listing 11.3.<br />

DataFactory.getData (Class interfaceClass, DataSource ds)<br />

Listing 11.3 - The getData method that we will use to create an instance of<br />

HumanResourcesData<br />

The method displayLogin() in the class<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesManager contains a<br />

declaration for a variable named data. Add code that creates an instance of<br />

hrm.inProgress.pdqMethodStyle.HumanResourcesData and assigns the result to<br />

data. Listing 11.4 shows the updated version of the code.

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

Saved successfully!

Ooh no, something went wrong!