You can set a timeout for SQL statements and set a maximum
number of rows for pureQuery to return in query results.
About this task
You can set values for these properties globally for all
SQL data manipulation language (DML) statements that your pureQuery
application runs, or locally for all SQL DML statements that the application
uses with an instance of an implementation of the Data interface.
You cannot set them locally for individual statements.
pureQuery
passes the values for these properties to corresponding JDBC Statement
methods.
- queryTimeoutInSeconds
- The number of seconds to wait for the SQL DML statement to run.
If the statement does not complete within the specified time, pureQuery
throws a runtime exception that is caused by an SQLException. A value
of 0 allows statements to run indefinitely.
- maxResultsRow
- The maximum number of rows that a statement returns in query results.
The rows are discarded after the count of rows reaches this limit.
A value of 0 allows query results to contain an indefinite number
of rows.
If you want to configure this maximum number of rows for
individual statements, rather than for all statements in your application
that return query results, you have two choices:
- Use the FETCH FIRST n ROWS clause in your statements, or the equivalent
syntax that your target database supports.
- Use a ResultHandler that processes a limited number of rows. For
example, you might use an IteratorPagingResultHandler.
Procedure
To set values for these properties, follow either of
these two steps. pureQuery searches for values in the order in which
the two methods appear.
- Set the values locally in a Properties object. Then, pass
the Properties object into a DataFactory.getData() method that accepts
a Properties object.
Local settings take precedence
over global settings.
For example, you might create a new Properties
object, set the values, and pass the object to the getData() method
like this:
java.util.Properties myPdqProperties = new java.util.Properties();
myPdqProperties.setProperty("pdq.queryTimeoutInSeconds", "5");
myPdqProperties.setProperty(“pdq.maxResultRows”, "100");
Connection connection = ...
Data data = DataFactory.getData (com.MyInterface.class, connection, myPdqProperties);
- Set the properties globally in a pdq.properties file. You
can place this file on the file system or in your application's classpath.
Local settings take precedence over global settings.
For
example, you might add the following entries to a pdq.properties file:
pdq.queryTimeoutInSeconds = 5
pdq.maxResultRows = 100
By default, pureQuery expects the name of the file
to be pdq.properties and the location of the file to be in your application's
classpath.
If you use a different file name, place the file
in a different location, or both, use the
configFile JVM
system property to point to the file when you run your application,
as follows:
-Dpdq.configFile=path-and-file-name or resource-name Java-package.application
If
you are developing a Web application, place the pdq.properties file
in your application's WEB-INF/classes folder
or in a JAR file in the WEB-INF/lib folder.
If you are developing a stand-alone application,
place the pdq.properties file in any folder or JAR file that is in
the classpath for the application.