Class Holdability
java.lang.Object
org.postgresql.pljava.example.annotation.Holdability
- All Implemented Interfaces:
ResultSetHandle
@SQLAction(requires={"Holdability.stash","Holdability.unstash"},
install={"SELECT javatest.stashResultSet()","SELECT CASE WHEN 1000 < count(*) THEN javatest.logmessage(\'INFO\', \'Holdability OK\') ELSE javatest.logmessage(\'WARNING\', \'Holdability suspicious\') END FROM javatest.unstashResultSet()"})
public class Holdability
extends Object
implements ResultSetHandle
Demonstrate holdability of ResultSets (test for issue 168).
The stashResultSet
method will execute a query and save its
ResultSet
(wrapped in a ResultSetHandle
in a static
for later retrieval. The unstashResultSet
method, called later
in the same transaction, retrieves and returns the result set. A call after
the transaction has ended will fail.
The query selects all rows from pg_description
, a table that should
always exist, with more rows than the default connection fetchSize
,
to ensure the stashed ResultSet
has work to do.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static void
Query all rows frompg_description
, but stash theResultSet
for retrieval later in the same transaction byunstashResultSet
.static ResultSetHandle
Return the results stashed earlier in the same transaction bystashResultSet
.
-
Method Details
-
stashResultSet
@Function(schema="javatest", provides="Holdability.stash") public static void stashResultSet() throws SQLExceptionQuery all rows frompg_description
, but stash theResultSet
for retrieval later in the same transaction byunstashResultSet
.This must be called in an open, multiple-statement (non-auto) transaction to have any useful effect.
- Throws:
SQLException
-
unstashResultSet
@Function(schema="javatest", type="pg_catalog.pg_description", provides="Holdability.unstash") public static ResultSetHandle unstashResultSet() throws SQLExceptionReturn the results stashed earlier in the same transaction bystashResultSet
.- Throws:
SQLException
-
getResultSet
- Specified by:
getResultSet
in interfaceResultSetHandle
- Throws:
SQLException
-
close
- Specified by:
close
in interfaceResultSetHandle
- Throws:
SQLException
-