-
Notifications
You must be signed in to change notification settings - Fork 959
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rethrow ConnectException from ConnectionProvider as RetriableExceptio…
…n to provide proper retries.
- Loading branch information
yevgenp
committed
Oct 31, 2022
1 parent
8f20bdf
commit 692d780
Showing
3 changed files
with
91 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/io/confluent/connect/jdbc/util/ExceptionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.confluent.connect.jdbc.util; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
|
||
public class ExceptionUtil { | ||
|
||
public static Iterable<Throwable> iterator(Throwable ex) { | ||
return ex instanceof SQLException | ||
? ((SQLException) ex) | ||
: () -> new Iterator<Throwable>() { | ||
Throwable firstException = ex; | ||
Throwable cause = firstException.getCause(); | ||
|
||
@Override | ||
public boolean hasNext() { | ||
return firstException != null || cause != null; | ||
} | ||
|
||
@Override | ||
public Throwable next() { | ||
Throwable throwable; | ||
if(firstException != null){ | ||
throwable = firstException; | ||
firstException = null; | ||
} | ||
else if(cause != null){ | ||
throwable = cause; | ||
cause = cause.getCause(); | ||
} | ||
else | ||
throw new NoSuchElementException(); | ||
return throwable; | ||
} | ||
|
||
@Override | ||
public void remove() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters