-
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 3ed5ad9
Showing
3 changed files
with
105 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
58 changes: 58 additions & 0 deletions
58
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,58 @@ | ||
/* | ||
* Copyright 2022 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
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