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 237<br />

and you add or change something in your interface, you need to rebind your interface<br />

before you can run methods in it again.<br />

You can specify <strong>pureQuery</strong> properties either in a properties file, in a<br />

java.util.Properties object that you pass to a DataFactory.getData method, or<br />

as the value of the IBM Data Server Driver for JDBC and SQLJ property pdqProperties.<br />

Refer to the IBM Optim <strong>pureQuery</strong> Runtime documentation for details about specifying<br />

<strong>pureQuery</strong> properties.<br />

One common way to specify a properties file is to provide a file named pdq.properties.<br />

If your application creates a connection to the database by using a<br />

javax.sql.DataSource object, this file must be in the classpath that indicates the<br />

location of the JDBC driver. If your application creates a connection by using the<br />

java.sql.DriverManager class, this file must be in the classpath. If your application<br />

creates a connection by using a javax.sql.DataSource object, another way to specify<br />

a properties file is to use a file named pdq.dataSourceName.properties in your<br />

application classpath, where dataSourceName represents the name of the DataSource<br />

object.<br />

If you use a properties file to specify <strong>pureQuery</strong> properties, each line of a properties file<br />

should contain the name of a property, then an equal sign (=), and finally the value for that<br />

property.<br />

11.8.2.1 In practice: Run the application statically<br />

If you are using IBM ® DB2 ® Database for your database, run your application statically.<br />

We will specify our <strong>pureQuery</strong> properties in a file named<br />

pdq.dataSourceName.properties. The class hrm.HRMDataSourceFactory<br />

defines the javax.sql.DataSource object that Human Resources Manager uses. The<br />

name of the DataSource that the application uses is<br />

DataSourceHumanResourcesManager. Therefore, the name of our properties file is<br />

pdq.DataSourceHumanResourcesManager.properties. Locate this file in the src<br />

directory of the project, and set the pdq.executionMode property in it. In the project, a<br />

single classpath indicates the location of the source code and the location of the JDBC<br />

driver, so this file is in the classpath that indicates the location of the JDBC driver. Listing<br />

11.32 shows what the file should contain.<br />

pdq.executionMode=STATIC<br />

Listing 11.32 - The property to set in your properties file<br />

After you have set the property, run and test your application.

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

Saved successfully!

Ooh no, something went wrong!