Skip to content

Commit

Permalink
#785 Remove generics from SQLExceptionChainBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mrotteveel committed Feb 27, 2024
1 parent e74123b commit d3697c6
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 101 deletions.
8 changes: 8 additions & 0 deletions src/docs/asciidoc/release_notes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,14 @@ use `decodeLocalDate(byte[])`
* `FetchResponse` was converted to a record, and its getters (`getStatus()` and `getCount()`) have been replaced by accessor methods (`status()` and `count()`)
* `GenericResponse` was converted to a record, and its getters (`getObjectHandle()`, `getBlobId()`, `getData()` and `exception()`) have been replaced by accessor methods (`objectHandle()`, `blobId()`, `data()` and `exception()`)
* `SQLResponse` was converted to a record, and its getter (`getCount()`) has been replaced by an accessor method (`count()`)
* `SQLExceptionChainBuilder`
** Moved to package `org.firebirdsql.jaybird.util`;
this package is internal API only, and not exported from the module (see also earlier)
** The generics `<E extends SQLException>` were removed from this class
*** `append` and `addFirst` now always expect `SQLException`
*** `getException()` now always returns `SQLException`
** Constructor `SQLExceptionChainBuilder(SQLException)` was removed, as in practice this was never used;
replacement is `new SQLExceptionChainBuilder().append(exception)`

[#breaking-changes-unlikely]
=== Unlikely breaking changes
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/ds/FBPooledConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ PooledConnectionHandler createConnectionHandler(Connection connection) {
@Override
public void close() throws SQLException {
try (LockCloseable ignored = withLock()) {
var chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
if (handler != null) {
try {
handler.close();
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/firebirdsql/ds/PooledConnectionHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ boolean isRollbackAllowed() throws SQLException {
* if underlying connection threw an exception.
*/
void handleClose(boolean notifyOwner) throws SQLException {
var chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
try {
closeStatements();
} catch (SQLException ex) {
Expand Down Expand Up @@ -229,7 +229,7 @@ void forgetStatement(StatementHandler stmtHandler) {
}

void closeStatements() throws SQLException {
var chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
try (LockCloseable ignored = owner.withLock()) {
// Make copy as the StatementHandler close will remove itself from openStatements
for (StatementHandler stmt : new ArrayList<>(openStatements)) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/event/FBEventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void disconnect() throws SQLException {
if (!connected) {
throw new IllegalStateException("Disconnect called while not connected");
}
var chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
try (LockCloseable ignored = withLock()) {
try {
for (String eventName : new HashSet<>(handlerMap.keySet())) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/firebirdsql/gds/ng/FbExceptionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public FbExceptionBuilder cause(Throwable cause) {
*/
public SQLException toSQLException() {
checkNonEmpty();
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
for (ExceptionInformation info : exceptionInfo) {
chain.append(info.toSQLException());
}
Expand Down Expand Up @@ -452,8 +452,8 @@ public SQLException toSQLException() {
public SQLException toFlatSQLException() {
checkNonEmpty();
// We are recording the unflattened state if people need the details
SQLExceptionChainBuilder<FBSQLExceptionInfo> chain = new SQLExceptionChainBuilder<>();
StringBuilder fullExceptionMessage = new StringBuilder();
var chain = new SQLExceptionChainBuilder();
var fullExceptionMessage = new StringBuilder();
ExceptionInformation interestingExceptionInfo = null;

for (ExceptionInformation info : exceptionInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void batchPutSegment(byte[] b, int off, int len) throws SQLException {

protected void consumePutSegmentResponses(int requestCount) throws SQLException {
if (requestCount == 0) return;
var chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
try {
while (requestCount-- > 0) {
consumePutSegmentResponse(chain);
Expand All @@ -151,7 +151,7 @@ protected void consumePutSegmentResponses(int requestCount) throws SQLException
}
}

private void consumePutSegmentResponse(SQLExceptionChainBuilder<SQLException> chain) throws IOException {
private void consumePutSegmentResponse(SQLExceptionChainBuilder chain) throws IOException {
try {
getDatabase().readResponse(null);
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private CryptSessionConfig getCryptSessionConfig(EncryptionIdentifier encryption
}

private void tryKnownServerKeys() throws IOException, SQLException {
var chainBuilder = new SQLExceptionChainBuilder<>();
var chainBuilder = new SQLExceptionChainBuilder();

EncryptionIdentifier selectedEncryption = null;
for (KnownServerKey.PluginSpecificData pluginSpecificData : getPluginSpecificData()) {
Expand All @@ -199,7 +199,7 @@ private void tryKnownServerKeys() throws IOException, SQLException {
}

private Optional<EncryptionIdentifier> tryKnownServerKey(KnownServerKey.PluginSpecificData pluginSpecificData,
SQLExceptionChainBuilder<SQLException> chainBuilder) throws IOException {
SQLExceptionChainBuilder chainBuilder) throws IOException {
EncryptionIdentifier encryptionIdentifier = pluginSpecificData.encryptionIdentifier();
EncryptionPluginSpi currentEncryptionSpi =
EncryptionPluginRegistry.getEncryptionPluginSpi(encryptionIdentifier);
Expand Down Expand Up @@ -240,7 +240,7 @@ private void throwIfWireCryptRequired(SQLException encryptionException) throws S
}
}

private static void logWireCryptPluginFailures(SQLExceptionChainBuilder<SQLException> chainBuilder,
private static void logWireCryptPluginFailures(SQLExceptionChainBuilder chainBuilder,
EncryptionIdentifier selectedEncryption) {
if (chainBuilder.hasException() && log.isLoggable(WARNING)) {
if (selectedEncryption == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,12 @@
* a single thread or with proper external synchronisation.
* </p>
*
* @param <E>
* type of SQLException (definition: {@code E extends SQLException})
* @author Mark Rotteveel
* @since 2.2
*/
public final class SQLExceptionChainBuilder<E extends SQLException> {
public final class SQLExceptionChainBuilder {

private E root;

/**
* Create SQLExceptionChainBuilder
*/
public SQLExceptionChainBuilder() {
this(null);
}

/**
* Create SQLExceptionChainBuilder with the specified root exception.
*
* @param root
* root SQLException
*/
public SQLExceptionChainBuilder(E root) {
this.root = root;
}
private SQLException root;

/**
* Appends the passed SQLException to the exception chain.
Expand All @@ -63,7 +44,7 @@ public SQLExceptionChainBuilder(E root) {
* SQLException to add to the chain.
* @return this SQLExceptionChainBuilder
*/
public SQLExceptionChainBuilder<E> append(E sqle) {
public SQLExceptionChainBuilder append(SQLException sqle) {
if (root == null) {
root = sqle;
} else {
Expand All @@ -84,7 +65,7 @@ public SQLExceptionChainBuilder<E> append(E sqle) {
* @return this SQLExceptionChainBuilder
* @since 5
*/
public SQLExceptionChainBuilder<E> addFirst(E sqle) {
public SQLExceptionChainBuilder addFirst(SQLException sqle) {
SQLException originalRoot = root;
if (originalRoot != null) {
sqle.setNextException(originalRoot);
Expand All @@ -103,7 +84,7 @@ public boolean hasException() {
/**
* @return the root SQLException or {@code null} if no SQLException was added to this SQLExceptionChainBuilder
*/
public E getException() {
public SQLException getException() {
return root;
}
}
2 changes: 1 addition & 1 deletion src/main/org/firebirdsql/jdbc/FBBlob.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ LockCloseable withLock() {
public void free() throws SQLException {
try (LockCloseable ignored = withLock()) {
try {
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();

for (FBBlobInputStream blobIS : new ArrayList<>(inputStreams)) {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/firebirdsql/jdbc/FBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected void freeStatements() throws SQLException {
List<Statement> statements = new ArrayList<>(activeStatements);

// iterate through the set, close statements and collect exceptions
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
for (Statement stmt : statements) {
try {
stmt.close();
Expand Down Expand Up @@ -431,7 +431,7 @@ public void close() throws SQLException {
if (log.isLoggable(TRACE)) {
log.log(TRACE, "Connection closed requested at", new RuntimeException("Connection close logging"));
}
var chainBuilder = new SQLExceptionChainBuilder<>();
var chainBuilder = new SQLExceptionChainBuilder();
try (LockCloseable ignored = withLock()) {
try {
if (metaData != null) metaData.close();
Expand All @@ -448,7 +448,7 @@ public void close() throws SQLException {
}
}

private void closeMc(SQLExceptionChainBuilder<SQLException> chainBuilder) {
private void closeMc(SQLExceptionChainBuilder chainBuilder) {
FBManagedConnection mc = this.mc;
if (mc == null) return;
// leave managed transactions alone, they are normally committed after the Connection handle is closed.
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/firebirdsql/jdbc/FBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ protected void closeFields() throws SQLException {
if (closeableFields.isEmpty())
return;

SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
// close current fields, so that resources are freed.
for (final FBCloseableField field : closeableFields) {
try {
Expand Down Expand Up @@ -413,7 +413,7 @@ public boolean isClosed() throws SQLException {
void close(boolean notifyListener, CompletionReason completionReason) throws SQLException {
if (isClosed()) return;
closed = true;
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();

try {
closeFields();
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/firebirdsql/jdbc/FBRowUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private void notifyExecutionCompleted(boolean success) throws SQLException {
processing = false;
}

private void deallocateStatement(FbStatement handle, SQLExceptionChainBuilder<SQLException> chain) {
private void deallocateStatement(FbStatement handle, SQLExceptionChainBuilder chain) {
if (handle == null) return;
try {
handle.close();
Expand All @@ -187,7 +187,7 @@ private void deallocateStatement(FbStatement handle, SQLExceptionChainBuilder<SQ
@Override
public void close() throws SQLException {
closed = true;
var chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
for (FbStatement statement : statements) {
deallocateStatement(statement, chain);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void handleConnectionAbort() throws SQLException {
private void setCoordinator(AbstractTransactionCoordinator coordinator) throws SQLException {
try (LockCloseable ignored = withLock()) {
if (this.coordinator != null) {
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
try {
this.coordinator.completeStatements(CompletionReason.COMMIT);
} catch (SQLException ex) {
Expand Down Expand Up @@ -234,7 +234,7 @@ protected final void setStatements(Collection<FBStatement> statements) {
}

protected void completeStatements(CompletionReason reason) throws SQLException {
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();

// we have to loop through the array, since the statement.completeStatement() call causes
// ConcurrentModificationException
Expand Down Expand Up @@ -314,7 +314,7 @@ public AutoCommitCoordinator(FBConnection connection, FBLocalTransaction localTr
@SuppressWarnings("resource")
public void executionStarted(FBStatement stmt) throws SQLException {
List<FBStatement> tempList = new ArrayList<>(statements);
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();

// complete all open statements for the connection (there should be only one anyway)
for (Iterator<FBStatement> iter = tempList.iterator(); iter.hasNext(); ) {
Expand Down Expand Up @@ -493,7 +493,7 @@ public FirebirdAutoCommitCoordinator(FBConnection connection, FBLocalTransaction
@SuppressWarnings("resource")
public void executionStarted(FBStatement stmt) throws SQLException {
List<FBStatement> tempList = new ArrayList<>(statements);
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();

// complete all open statements for the connection (there should be only one anyway)
for (Iterator<FBStatement> iter = tempList.iterator(); iter.hasNext(); ) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/org/firebirdsql/jdbc/ServerBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public List<Long> execute() throws SQLException {
return emptyList();
}
Collection<RowValue> rowValues = toRowValues();
SQLExceptionChainBuilder<SQLException> chain = new SQLExceptionChainBuilder<>();
var chain = new SQLExceptionChainBuilder();
// Create server-side batch
if (!state.isOpenOnServer()) {
createBatch(chain);
Expand Down Expand Up @@ -156,7 +156,7 @@ public List<Long> execute() throws SQLException {
* For database access errors (I/O errors)
*/
@SuppressWarnings("NonAtomicOperationOnVolatileField")
private void createBatch(SQLExceptionChainBuilder<SQLException> chain) throws SQLException {
private void createBatch(SQLExceptionChainBuilder chain) throws SQLException {
try {
statement.deferredBatchCreate(batchConfig,
new BatchDeferredAction(chain, "exception creating batch") {
Expand All @@ -183,7 +183,7 @@ public void onException(Exception exception) {
* For database access errors (I/O errors)
*/
@SuppressWarnings("NonAtomicOperationOnVolatileField")
private void sendBatch(Collection<RowValue> rowValues, SQLExceptionChainBuilder<SQLException> chain)
private void sendBatch(Collection<RowValue> rowValues, SQLExceptionChainBuilder chain)
throws SQLException {
try {
statement.deferredBatchSend(rowValues,
Expand Down Expand Up @@ -212,7 +212,7 @@ public void onException(Exception exception) {
* for database access errors
*/
@SuppressWarnings("NonAtomicOperationOnVolatileField")
private BatchCompletion executeBatch(SQLExceptionChainBuilder<SQLException> chain) throws SQLException {
private BatchCompletion executeBatch(SQLExceptionChainBuilder chain) throws SQLException {
try {
state = state.onExecute();
BatchCompletion batchCompletion = statement.batchExecute();
Expand Down Expand Up @@ -368,10 +368,10 @@ BatchUpdateException toBatchUpdateException(BatchCompletion batchCompletion) {

private static class BatchDeferredAction implements DeferredResponse<Void> {

private final SQLExceptionChainBuilder<? super SQLException> chain;
private final SQLExceptionChainBuilder chain;
private final String genericExceptionMessage;

BatchDeferredAction(SQLExceptionChainBuilder<? super SQLException> chain, String genericExceptionMessage) {
BatchDeferredAction(SQLExceptionChainBuilder chain, String genericExceptionMessage) {
this.chain = chain;
this.genericExceptionMessage = genericExceptionMessage;
}
Expand Down
Loading

0 comments on commit d3697c6

Please sign in to comment.