You can set cursor
attributes for query results from queries
that you run from annotated and inline methods. With these attributes,
you can create scrollable or updatable query results.
You can set the following
attributes:
- Attributes that define the concurrency
mode for a ResultSet object
- java.sql.ResultSet.CONCUR_READ_ONLY
- The integer constant that specifies that the cursor
prevents updates while the query result is open.
- java.sql.ResultSet.CONCUR_UPDATABLE
- The integer constant that specifies that the cursor
allows updates while the query result is open.
Attention: pureQuery supports positioned updates and
deletes with annotated methods, but not with inline methods.
- Attributes that define
whether or not a ResultSet object should
be closed when the Connection.commit() method is called
- java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT
- The integer constant that specifies that the
cursor is closed at the end of a transaction.
- java.sql.ResultSet.HOLD_CURSORS_OVER_COMMIT
- The integer constant that specifies that the
cursor remains open at the end of a transaction.
- Attributes that define type for a
ResultSet object
- java.sql.ResultSet.TYPE_FORWARD_ONLY
- The integer constant that specifies that the cursor
can move forward only.
- java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE
- The integer constant that specifies that the cursor
can move forward and backward. The query result gives a snapshot of
the data.
- java.sql.ResultSet.TYPE_SCROLL_SENSITIVE
- The integer constant that specifies that the cursor
can move forward and backward. The query result reflects changes that
are made to the data while the cursor is held.
- If you
use this attribute for a query that is bound against DB2® Database for Linux, UNIX and Windows or against DB2 for z/OS®,
the cursor is bound as a SENSITIVE STATIC SCROLL cursor. Please see
the DB2 for z/OS Application Programming and SQL Guide for
further information about this type of cursor.
By default, when you do not explicitly set any
attributes, pureQuery
uses these attributes:
- java.sql.ResultSet.CONCUR_READ_ONLY
- java.sql.ResultSet.CLOSE_CURSORS_AT_COMMIT
- java.sql.ResultSet.TYPE_FORWARD_ONLY
Using annotated methods to set cursor attributes
Use
the @Cursor annotation, together with the @Select annotation, to specify
the cursor attributes that you want for a query result. See the syntax
diagram for annotated methods that run SQL statements against databases.
Using inline methods to set cursor attributes
Use
one of the following methods in the
Data interface:
- public <T> T query (int type, int concurrency, int holdability,
String sql, ResultHandler<T> handler, Object... parameters);
- public Iterator<Map<String, Object>> queryIterator
(int type, int concurrency, int holdability, String sql, Object...
parameters);
- public <T> Iterator<T> queryIterator
(int type, int
concurrency, int holdability, String sql, Class<T> returnClass,
Object... parameters);
- public <T> Iterator<T>
queryIterator (int type, int
concurrency, int holdability, String sql, RowHandler<T> rowHandler,
Object... parameters);
- public ResultSet queryResults (int
type, int concurrency, int
holdability, String sql, Object... parameters);
See the pureQuery Javadoc for
the
Data interface
for information about these methods.