Skip to content

Commit

Permalink
Add ydb status exception with factory based on StatusCode.isRetryable
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Oct 27, 2023
1 parent 760e621 commit edd529f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package tech.ydb.jdbc.exception;

import tech.ydb.core.StatusCode;
import tech.ydb.core.Status;

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

public YdbConditionallyRetryableException(String message, StatusCode statusCode) {
super(message, statusCode);
YdbConditionallyRetryableException(String message, String sqlState, Status status) {
super(message, sqlState, status);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package tech.ydb.jdbc.exception;

import tech.ydb.core.StatusCode;
import tech.ydb.core.Status;

public class YdbNonRetryableException extends YdbExecutionStatusException {
private static final long serialVersionUID = 1170815831963616837L;
public class YdbNonRetryableException extends YdbStatusException {
private static final long serialVersionUID = 687247673341671225L;

public YdbNonRetryableException(String message, StatusCode statusCode) {
super(message, statusCode);
YdbNonRetryableException(String message, String sqlState, Status status) {
super(message, sqlState, status);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package tech.ydb.jdbc.exception;

import tech.ydb.core.StatusCode;
import tech.ydb.core.Status;

public class YdbRetryableException extends YdbExecutionStatusException {
private static final long serialVersionUID = 688604408491567864L;
public class YdbRetryableException extends YdbStatusException {
private static final long serialVersionUID = 2082287790625648960L;

public YdbRetryableException(String message, StatusCode statusCode) {
super(message, statusCode);
YdbRetryableException(String message, String sqlState, Status status) {
super(message, sqlState, status);
}
}
40 changes: 40 additions & 0 deletions jdbc/src/main/java/tech/ydb/jdbc/exception/YdbStatusException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package tech.ydb.jdbc.exception;

import tech.ydb.core.Status;
import tech.ydb.core.StatusCode;

public class YdbStatusException extends YdbExecutionException {
private static final long serialVersionUID = -8082086858749679589L;

private final Status status;

protected YdbStatusException(String message, String state, Status status) {
super(message, state, status.getCode().getCode());
this.status = status;
}

public Status getStatus() {
return status;
}

public static YdbStatusException newException(String message, Status status) {
if (status.getCode().isRetryable(false)) {
String sqlState = "Retryable[" + status.toString() + "]";
return new YdbRetryableException(message, sqlState, status);
}

if (status.getCode().isRetryable(true)) {
String sqlState = "ConditionallyRetryable[" + status.toString() + "]";
return new YdbConditionallyRetryableException(message, sqlState, status);
}

String sqlState = "NonRetryable[" + status.toString() + "]";
return new YdbNonRetryableException(message, sqlState, status);
}

public static YdbStatusException newBadRequest(String message) {
Status status = Status.of(StatusCode.BAD_REQUEST);
String sqlState = "NonRetryable[" + status.toString() + "]";
return new YdbNonRetryableException(message, sqlState, status);
}
}

0 comments on commit edd529f

Please sign in to comment.