Skip to content

Commit f6395f3

Browse files
committed
Extended support of standard JDBC exceptions
1 parent 0a3f63f commit f6395f3

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

jdbc/src/main/java/tech/ydb/jdbc/exception/ExceptionFactory.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,24 @@ public static SQLException createException(String message, UnexpectedResultExcep
2424
String sqlState = getSQLState(code);
2525
int vendorCode = getVendorCode(code);
2626

27+
// base retryable statuses are translated to SQLRecoverableException
2728
if (code.isRetryable(false)) {
2829
return new YdbRetryableException(message, sqlState, vendorCode, cause);
2930
}
31+
32+
// transport problems are translated to SQLTransientConnectionException
33+
if (code == StatusCode.TRANSPORT_UNAVAILABLE || code == StatusCode.UNAVAILABLE) {
34+
return new YdbUnavailbaleException(message, sqlState, vendorCode, cause);
35+
}
36+
37+
// timeouts are translated to SQLTimeoutException
38+
if (code == StatusCode.TIMEOUT ||
39+
code == StatusCode.CLIENT_DEADLINE_EXPIRED ||
40+
code == StatusCode.CLIENT_DEADLINE_EXCEEDED) {
41+
return new YdbTimeoutException(message, sqlState, vendorCode, cause);
42+
}
43+
44+
// all others transient problems are translated to base SQLTransientException
3045
if (code.isRetryable(true)) {
3146
return new YdbConditionallyRetryableException(message, sqlState, vendorCode, cause);
3247
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package tech.ydb.jdbc.exception;
2+
3+
import java.sql.SQLTimeoutException;
4+
5+
import tech.ydb.core.Status;
6+
import tech.ydb.core.UnexpectedResultException;
7+
8+
/**
9+
*
10+
* @author Aleksandr Gorshenin
11+
*/
12+
public class YdbTimeoutException extends SQLTimeoutException {
13+
private static final long serialVersionUID = -6309565506198809222L;
14+
15+
private final Status status;
16+
17+
YdbTimeoutException(String message, String sqlState, int code, UnexpectedResultException cause) {
18+
super(message, sqlState, code, cause);
19+
this.status = cause.getStatus();
20+
}
21+
22+
public Status getStatus() {
23+
return status;
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package tech.ydb.jdbc.exception;
2+
3+
import java.sql.SQLTransientConnectionException;
4+
5+
import tech.ydb.core.Status;
6+
import tech.ydb.core.UnexpectedResultException;
7+
8+
/**
9+
*
10+
* @author Aleksandr Gorshenin
11+
*/
12+
public class YdbUnavailbaleException extends SQLTransientConnectionException {
13+
private static final long serialVersionUID = 7162301155514557562L;
14+
15+
private final Status status;
16+
17+
YdbUnavailbaleException(String message, String sqlState, int code, UnexpectedResultException cause) {
18+
super(message, sqlState, code, cause);
19+
this.status = cause.getStatus();
20+
}
21+
22+
public Status getStatus() {
23+
return status;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)