From e20c9b1d9aadc799169a70c9a7231cbea79419cb Mon Sep 17 00:00:00 2001 From: Mark Rotteveel Date: Sat, 13 Apr 2024 11:03:11 +0200 Subject: [PATCH] Clean up unnecessary constructor parameters, mark as internal API --- src/docs/asciidoc/release_notes.adoc | 5 ++- .../org/firebirdsql/jdbc/FBResultSet.java | 36 ++++++++----------- .../org/firebirdsql/jdbc/FBStatement.java | 22 ++++++++++-- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/docs/asciidoc/release_notes.adoc b/src/docs/asciidoc/release_notes.adoc index ca324e3cd..f8a03072e 100644 --- a/src/docs/asciidoc/release_notes.adoc +++ b/src/docs/asciidoc/release_notes.adoc @@ -1435,7 +1435,10 @@ When in doubt, use `false` to communicate that no such synchronization is requir ** `skipFully` was removed, use standard Java `InputStream.skipNBytes` instead ** `readShort` was removed as it was unused * The no-arg constructor of `FBXAException` was removed -* `FBResultSet.close(boolean)` was removed; +* `FBResultSet` +** The constructors are now all marked as internal API, as they effectively already were due to arguments of internal API classes +** The constructor `FBResultSet(FBConnection, FBStatement, FbStatement, FBObjectListener.ResultSetListener, boolean, int, int, int, boolean)` was replaced by `FBResultSet(FBStatement, FBObjectListener.ResultSetListener, boolean, int, int, int)` +** `close(boolean)` was removed; use `close(boolean, CompletionReason)` * `UnixCrypt` was replaced by `LegacyHash`, which only performs the password hash specific to Firebird legacy authentication * `GDSFactoryPlugin.getDatabasePath(String, Integer, String)` and `getDatabasePath(String)` no longer throw `GDSException`, but instead throw `SQLException` diff --git a/src/main/org/firebirdsql/jdbc/FBResultSet.java b/src/main/org/firebirdsql/jdbc/FBResultSet.java index f742326e3..5deab5e6a 100644 --- a/src/main/org/firebirdsql/jdbc/FBResultSet.java +++ b/src/main/org/firebirdsql/jdbc/FBResultSet.java @@ -32,6 +32,7 @@ import org.firebirdsql.jdbc.field.FBField; import org.firebirdsql.jdbc.field.FieldDataProvider; import org.firebirdsql.jdbc.field.TrimmableField; +import org.firebirdsql.util.InternalApi; import java.io.InputStream; import java.io.Reader; @@ -109,36 +110,25 @@ public void rowChanged(FBFetcher fetcher, RowValue newRow) throws SQLException { * Creates a new {@code FBResultSet} instance. */ @SuppressWarnings("java:S1141") - public FBResultSet(FBConnection connection, - FBStatement fbStatement, - FbStatement stmt, - FBObjectListener.ResultSetListener listener, - boolean metaDataQuery, - int rsType, - int rsConcurrency, - int rsHoldability, - boolean cached) - throws SQLException { + @InternalApi + public FBResultSet(FBStatement fbStatement, FBObjectListener.ResultSetListener listener, boolean metaDataQuery, + int rsType, int rsConcurrency, int rsHoldability) throws SQLException { + assert rsType != ResultSet.TYPE_SCROLL_SENSITIVE : "Received unsupported rsType == TYPE_SCROLL_SENSITIVE"; + this.fbStatement = fbStatement; + FbStatement stmt = fbStatement.getStatementHandle(); try { - this.connection = connection; + this.connection = (FBConnection) fbStatement.getConnection(); this.gdsHelper = connection != null ? connection.getGDSHelper() : null; cursorName = fbStatement.getCursorName(); this.listener = listener != null ? listener : FBObjectListener.NoActionResultSetListener.instance(); rowDescriptor = stmt.getRowDescriptor(); fields = new FBField[rowDescriptor.getCount()]; colNames = new HashMap<>(rowDescriptor.getCount(), 1); - this.fbStatement = fbStatement; - if (rsType == ResultSet.TYPE_SCROLL_SENSITIVE) { - fbStatement.addWarning(FbExceptionBuilder - .forWarning(JaybirdErrorCodes.jb_resultSetTypeDowngradeReasonScrollSensitive) - .toSQLException(SQLWarning.class)); - rsType = ResultSet.TYPE_SCROLL_INSENSITIVE; - } boolean serverSideScrollable = rsHoldability != ResultSet.HOLD_CURSORS_OVER_COMMIT && !metaDataQuery && connection != null && connection.isScrollableCursor(PropertyConstants.SCROLLABLE_CURSOR_SERVER) && stmt.supportsFetchScroll(); - cached = cached || metaDataQuery || !(rsType == TYPE_FORWARD_ONLY || serverSideScrollable); + boolean cached = metaDataQuery || !(rsType == TYPE_FORWARD_ONLY || serverSideScrollable); prepareVars(cached, metaDataQuery); if (cached) { @@ -157,7 +147,7 @@ public FBResultSet(FBConnection connection, if (rsConcurrency == ResultSet.CONCUR_UPDATABLE) { try { rowUpdater = new FBRowUpdater(connection, rowDescriptor, cached, listener); - if (serverSideScrollable && fbFetcher instanceof FBServerScrollFetcher) { + if (fbFetcher instanceof FBServerScrollFetcher) { fbFetcher = new FBUpdatableFetcher(fbFetcher, this, rowDescriptor.createDeletedRowMarker()); } } catch (FBResultSetNotUpdatableException ex) { @@ -170,7 +160,7 @@ public FBResultSet(FBConnection connection, this.rsType = rsType; this.rsConcurrency = rsConcurrency; this.rsHoldability = rsHoldability; - this.fetchDirection = fbStatement.getFetchDirection(); + fetchDirection = fbStatement.getFetchDirection(); } catch (SQLException e) { try { // Ensure cursor is closed to avoid problems with statement reuse @@ -198,6 +188,7 @@ public FBResultSet(FBConnection connection, * @param listener * result set listener */ + @InternalApi public FBResultSet(RowDescriptor rowDescriptor, List rows, FBObjectListener.ResultSetListener listener) throws SQLException { this(rowDescriptor, null, rows, listener, false, false); @@ -217,6 +208,7 @@ public FBResultSet(RowDescriptor rowDescriptor, List rows, FBObjectLis * @param rows * row data */ + @InternalApi public FBResultSet(RowDescriptor rowDescriptor, List rows) throws SQLException { this(rowDescriptor, rows, null); } @@ -239,6 +231,7 @@ public FBResultSet(RowDescriptor rowDescriptor, List rows) throws SQLE * @param retrieveBlobs * {@code true} retrieves the blob data */ + @InternalApi public FBResultSet(RowDescriptor rowDescriptor, FBConnection connection, List rows, boolean retrieveBlobs) throws SQLException { this(rowDescriptor, connection, rows, null, retrieveBlobs, true); @@ -264,6 +257,7 @@ public FBResultSet(RowDescriptor rowDescriptor, FBConnection connection, List rows, FBObjectListener.ResultSetListener listener, boolean retrieveBlobs, boolean trimStrings) throws SQLException { diff --git a/src/main/org/firebirdsql/jdbc/FBStatement.java b/src/main/org/firebirdsql/jdbc/FBStatement.java index f9571d19a..67fd7c181 100644 --- a/src/main/org/firebirdsql/jdbc/FBStatement.java +++ b/src/main/org/firebirdsql/jdbc/FBStatement.java @@ -49,7 +49,7 @@ * @author David Jencks * @author Mark Rotteveel */ -@SuppressWarnings("RedundantThrows") +@SuppressWarnings({ "RedundantThrows", "SqlSourceToSinkFlow" }) public class FBStatement implements FirebirdStatement { private static final System.Logger log = System.getLogger(FBStatement.class.getName()); @@ -168,6 +168,11 @@ public void executionStarted(FirebirdRowUpdater updater) throws SQLException { } protected FBStatement(GDSHelper c, int rsType, int rsConcurrency, int rsHoldability, FBObjectListener.StatementListener statementListener) throws SQLException { + if (rsType == ResultSet.TYPE_SCROLL_SENSITIVE) { + throw new FBDriverNotCapableException( + "Received TYPE_SCROLL_SENSITIVE, but Jaybird does not support this type. This is likely " + + "an implementation bug, so please report this."); + } this.gdsHelper = c; this.rsConcurrency = rsConcurrency; @@ -604,8 +609,8 @@ public ResultSet getResultSet(boolean metaDataQuery) throws SQLException { if (cursorName != null) { fbStatement.setCursorName(cursorName); } - return currentRs = new FBResultSet(connection, this, fbStatement, resultSetListener, metaDataQuery, - rsType, rsConcurrency, rsHoldability, false); + return currentRs = new FBResultSet(this, resultSetListener, metaDataQuery, + rsType, rsConcurrency, rsHoldability); } else if (!specialResult.isEmpty()) { return currentRs = createSpecialResultSet(resultSetListener); } @@ -848,6 +853,17 @@ public Connection getConnection() throws SQLException { return connection; } + /** + * @return Instance of {@link FbStatement} associated with this statement. Can be {@code null} if no statement has + * been executed yet. + * @throws SQLException + * if this statement is closed + */ + final FbStatement getStatementHandle() throws SQLException { + checkValidity(); + return fbStatement; + } + void closeResultSet(boolean notifyListener) throws SQLException { closeResultSet(notifyListener, CompletionReason.OTHER); }