Skip to content

Commit

Permalink
#802 Stop upgrading TYPE_FORWARD_ONLY to TYPE_SCROLL_INSENSITIVE for …
Browse files Browse the repository at this point in the history
…holdable result sets
  • Loading branch information
mrotteveel committed Nov 5, 2024
1 parent 189f0bb commit b3a117b
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

== Status

* Draft
* Proposed for: Jaybird 6
* Published: 2024-11-05
* Implemented in: Jaybird 6

== Type

Expand Down
4 changes: 4 additions & 0 deletions src/main/org/firebirdsql/gds/JaybirdErrorCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public interface JaybirdErrorCodes {
int jb_clumpletReaderUsageError = 337248262;
int jb_invalidConnectionString = 337248263;
int jb_concurrencyResetReadOnlyReasonNotUpdatable = 337248264;
/**
* @deprecated Jaybird no longer uses this error code
*/
@Deprecated(since = "6")
int jb_resultSetTypeUpgradeReasonHoldability = 337248265;
int jb_resultSetTypeDowngradeReasonScrollSensitive = 337248266;
int jb_concurrencyResetReadOnlyReasonStoredProcedure = 337248267;
Expand Down
5 changes: 4 additions & 1 deletion src/main/org/firebirdsql/jdbc/FBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public FBResultSet(AbstractStatement statement, FBObjectListener.@Nullable Resul
behavior.isScrollable() && behavior.isCloseCursorsAtCommit() && !metaDataQuery
&& connection.isScrollableCursor(PropertyConstants.SCROLLABLE_CURSOR_SERVER)
&& stmt.supportsFetchScroll();
boolean cached = metaDataQuery || behavior.isScrollable() && !serverSideScrollable;
boolean cached =
metaDataQuery
|| behavior.isScrollable() && !serverSideScrollable
|| behavior.isHoldCursorsOverCommit();

fields = createFields(cached, metaDataQuery);
closeableFields = toCloseableFields(fields);
Expand Down
11 changes: 1 addition & 10 deletions src/main/org/firebirdsql/jdbc/ResultSetBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,7 @@ public static ResultSetBehavior of(int type, int concurrency, int holdability) t
public static ResultSetBehavior of(int type, int concurrency, int holdability, Consumer<SQLWarning> warningConsumer)
throws SQLException {
int bitset = switch (type) {
case ResultSet.TYPE_FORWARD_ONLY -> {
if (holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT) {
warningConsumer.accept(
FbExceptionBuilder.forWarning(JaybirdErrorCodes.jb_resultSetTypeUpgradeReasonHoldability)
.toSQLException(SQLWarning.class));
// Upgrade to scrollable so we cache the result set to provide the holdable semantics
yield SCROLLABLE_BIT;
}
yield NO_BIT_SET;
}
case ResultSet.TYPE_FORWARD_ONLY -> NO_BIT_SET;
case ResultSet.TYPE_SCROLL_INSENSITIVE -> SCROLLABLE_BIT;
case ResultSet.TYPE_SCROLL_SENSITIVE -> {
warningConsumer.accept(
Expand Down
10 changes: 4 additions & 6 deletions src/test/org/firebirdsql/jdbc/AutoCommitBehaviourTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,18 @@ void testDifferentStatementExecution_ClosesResultSet(int resultSetType) throws E
@ValueSource(ints = { ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_FORWARD_ONLY })
void testHoldableDifferentStatementExecution_ResultSetRemainsOpen(int resultSetType) throws Exception {
connection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
// TYPE_FORWARD_ONLY is upgraded to TYPE_SCROLL_INSENSITIVE
final int expectedType = ResultSet.TYPE_SCROLL_INSENSITIVE;
var stmt1 = connection.createStatement(resultSetType, ResultSet.CONCUR_READ_ONLY);
assertEquals(expectedType, stmt1.getResultSetType(), "stmt1.getResultSetType");
assertEquals(resultSetType, stmt1.getResultSetType(), "stmt1.getResultSetType");
var stmt2 = connection.createStatement(resultSetType, ResultSet.CONCUR_READ_ONLY);
assertEquals(expectedType, stmt2.getResultSetType(), "stmt2.getResultSetType");
assertEquals(resultSetType, stmt2.getResultSetType(), "stmt2.getResultSetType");

var rs1 = stmt1.executeQuery(SELECT_ALL_ID_TABLE);
assertEquals(expectedType, rs1.getType(), "rs1.getType");
assertEquals(resultSetType, rs1.getType(), "rs1.getType");
assertNextRow(rs1);
assertResultSetOpen(rs1, "Expected rs1 open");

var rs2 = stmt2.executeQuery(SELECT_ALL_ID_TABLE);
assertEquals(expectedType, rs2.getType(), "rs2.getType");
assertEquals(resultSetType, rs2.getType(), "rs2.getType");

assertResultSetOpen(rs1, "Expected rs1 open");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void resultSetTypeConcurrencyHoldability(int type, int concurrency, int holdabil
private static Stream<Arguments> resultSetTypeConcurrencyHoldability() {
return Stream.of(
Arguments.of(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT, TYPE_FORWARD_ONLY),
Arguments.of(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT, TYPE_SCROLL_INSENSITIVE),
Arguments.of(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT, TYPE_FORWARD_ONLY),
Arguments.of(TYPE_SCROLL_INSENSITIVE, CONCUR_UPDATABLE, CLOSE_CURSORS_AT_COMMIT,
TYPE_SCROLL_INSENSITIVE),
Arguments.of(TYPE_SCROLL_INSENSITIVE, CONCUR_UPDATABLE, HOLD_CURSORS_OVER_COMMIT,
Expand Down
6 changes: 2 additions & 4 deletions src/test/org/firebirdsql/jdbc/ResultSetBehaviorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,9 @@ void testWithReadOnly(int type, int concurrency, int holdability) throws SQLExce
static Stream<Arguments> testCases() {
return Stream.of(
testCaseBasic(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT),
testCaseTypeChange(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT,
TYPE_SCROLL_INSENSITIVE, JaybirdErrorCodes.jb_resultSetTypeUpgradeReasonHoldability),
testCaseBasic(TYPE_FORWARD_ONLY, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT),
testCaseBasic(TYPE_FORWARD_ONLY, CONCUR_UPDATABLE, CLOSE_CURSORS_AT_COMMIT),
testCaseTypeChange(TYPE_FORWARD_ONLY, CONCUR_UPDATABLE, HOLD_CURSORS_OVER_COMMIT,
TYPE_SCROLL_INSENSITIVE, JaybirdErrorCodes.jb_resultSetTypeUpgradeReasonHoldability),
testCaseBasic(TYPE_FORWARD_ONLY, CONCUR_UPDATABLE, HOLD_CURSORS_OVER_COMMIT),
testCaseBasic(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY, CLOSE_CURSORS_AT_COMMIT),
testCaseBasic(TYPE_SCROLL_INSENSITIVE, CONCUR_READ_ONLY, HOLD_CURSORS_OVER_COMMIT),
testCaseBasic(TYPE_SCROLL_INSENSITIVE, CONCUR_UPDATABLE, CLOSE_CURSORS_AT_COMMIT),
Expand Down

0 comments on commit b3a117b

Please sign in to comment.