JDBC properties for setting rollback scope v16
If you're using a JDBC connector to connect to a client application, you use the
transaction_rollback_scope properties together to specify the transaction rollback scope.
You can specify these properties in either the connection URL or as an
additional properties object parameter to
autosave parameter is a string that specifies what the driver does if a query containing
multiple statements fails. The possible values are:
autosave=servermode, JDBC relies on the server-side parameter
transaction_rollback_scopeto save each statement by way of internal server savepoints before executing the next. The server rolls back to the previous statement if any statement in the query fails. If this parameter isn't supported on the server side, JDBC rejects the connection.
autosave=alwaysmode, the JDBC driver first tries to use the server-side
transaction_rollback_scopeproperty. If it isn't supported, then JDBC driver sets a savepoint before each query statement and rolls back to that savepoint in case of failure.
autosave=nevermode (default), no savepoint activity is ever carried out. In
autosave=conservativemode, savepoint is set for each query. However, the rollback is done only for rare cases like 'cached statement cannot change return type' or 'statement XXX is not valid', so JDBC driver rolls back and retries.
The default value for this property is
autosave=server property is useful only
with the PostgreSQL server providing
autosave parameter is a string that determines the range of
operations that roll back when an SQL statement fails.
The default value is
TRANSACTION, which causes the entire transaction or
current subtransaction to roll back. This is the only mode
that you can select with the
SET TRANSACTION command.
You can specify the other possible mode,
STATEMENT, only during connection establishment,
ALTER USER, or
ALTER DATABASE. In that mode, only
SQL statement is rolled back, and the transaction is put back in normal mode.
Test cases for trying out values of the
are available in the
BatchAutoSaveTest.java file. The following
SQL code shows the behavior that's expected when the
transaction_rollback_scope functionality and
autosave=server is used on the JDBC side.
autosave=server, the following query inserts values
(4) and disregards the
duplicate key violation error:
artifacts directory contains the
pgjdbc jar file
postgresql-REL2Q.188.8.131.52601.jar. This file needs to
be added to the CLASSPATH as usual. It also contains the
postgresql-REL2Q.184.108.40.206601-tests.jar jar that can be used to test
You can test the
BatchAutoSaveTest.java file provided in the
artifacts as follows:
Export CLASSPATH to build and run the test case:
Compile the supplied test file:
Run the test (assuming user as
testand running on localhost):
To modify the test cases, you can modify the
artifacts directory. Then compile and run the test cases.