Skip to content

Commit edd529f

Browse files
committed
Add ydb status exception with factory based on StatusCode.isRetryable
1 parent 760e621 commit edd529f

File tree

5 files changed

+54
-32
lines changed

5 files changed

+54
-32
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package tech.ydb.jdbc.exception;
22

3-
import tech.ydb.core.StatusCode;
3+
import tech.ydb.core.Status;
44

55
// Treat this as non retryable exception by nature, i.e. need to handle in consciously
66
public class YdbConditionallyRetryableException extends YdbNonRetryableException {
7-
private static final long serialVersionUID = 1135970796364528563L;
7+
private static final long serialVersionUID = -2371144941971339449L;
88

9-
public YdbConditionallyRetryableException(String message, StatusCode statusCode) {
10-
super(message, statusCode);
9+
YdbConditionallyRetryableException(String message, String sqlState, Status status) {
10+
super(message, sqlState, status);
1111
}
1212
}

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

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package tech.ydb.jdbc.exception;
22

3-
import tech.ydb.core.StatusCode;
3+
import tech.ydb.core.Status;
44

5-
public class YdbNonRetryableException extends YdbExecutionStatusException {
6-
private static final long serialVersionUID = 1170815831963616837L;
5+
public class YdbNonRetryableException extends YdbStatusException {
6+
private static final long serialVersionUID = 687247673341671225L;
77

8-
public YdbNonRetryableException(String message, StatusCode statusCode) {
9-
super(message, statusCode);
8+
YdbNonRetryableException(String message, String sqlState, Status status) {
9+
super(message, sqlState, status);
1010
}
1111
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package tech.ydb.jdbc.exception;
22

3-
import tech.ydb.core.StatusCode;
3+
import tech.ydb.core.Status;
44

5-
public class YdbRetryableException extends YdbExecutionStatusException {
6-
private static final long serialVersionUID = 688604408491567864L;
5+
public class YdbRetryableException extends YdbStatusException {
6+
private static final long serialVersionUID = 2082287790625648960L;
77

8-
public YdbRetryableException(String message, StatusCode statusCode) {
9-
super(message, statusCode);
8+
YdbRetryableException(String message, String sqlState, Status status) {
9+
super(message, sqlState, status);
1010
}
1111
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package tech.ydb.jdbc.exception;
2+
3+
import tech.ydb.core.Status;
4+
import tech.ydb.core.StatusCode;
5+
6+
public class YdbStatusException extends YdbExecutionException {
7+
private static final long serialVersionUID = -8082086858749679589L;
8+
9+
private final Status status;
10+
11+
protected YdbStatusException(String message, String state, Status status) {
12+
super(message, state, status.getCode().getCode());
13+
this.status = status;
14+
}
15+
16+
public Status getStatus() {
17+
return status;
18+
}
19+
20+
public static YdbStatusException newException(String message, Status status) {
21+
if (status.getCode().isRetryable(false)) {
22+
String sqlState = "Retryable[" + status.toString() + "]";
23+
return new YdbRetryableException(message, sqlState, status);
24+
}
25+
26+
if (status.getCode().isRetryable(true)) {
27+
String sqlState = "ConditionallyRetryable[" + status.toString() + "]";
28+
return new YdbConditionallyRetryableException(message, sqlState, status);
29+
}
30+
31+
String sqlState = "NonRetryable[" + status.toString() + "]";
32+
return new YdbNonRetryableException(message, sqlState, status);
33+
}
34+
35+
public static YdbStatusException newBadRequest(String message) {
36+
Status status = Status.of(StatusCode.BAD_REQUEST);
37+
String sqlState = "NonRetryable[" + status.toString() + "]";
38+
return new YdbNonRetryableException(message, sqlState, status);
39+
}
40+
}

0 commit comments

Comments
 (0)