-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from alex268/release_v2.0.4
Use standart exception classes for detecting retryable problems
- Loading branch information
Showing
34 changed files
with
187 additions
and
240 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
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
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
36 changes: 36 additions & 0 deletions
36
jdbc/src/main/java/tech/ydb/jdbc/exception/ExceptionFactory.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,36 @@ | ||
package tech.ydb.jdbc.exception; | ||
|
||
import java.sql.SQLException; | ||
|
||
import tech.ydb.core.StatusCode; | ||
import tech.ydb.core.UnexpectedResultException; | ||
|
||
/** | ||
* | ||
* @author Aleksandr Gorshenin | ||
*/ | ||
public class ExceptionFactory { | ||
static String getSQLState(StatusCode status) { | ||
// TODO: Add SQLSTATE message with order with https://en.wikipedia.org/wiki/SQLSTATE | ||
return null; | ||
} | ||
|
||
static int getVendorCode(StatusCode code) { | ||
return code.getCode(); | ||
} | ||
|
||
public static SQLException createException(String message, UnexpectedResultException cause) { | ||
StatusCode code = cause.getStatus().getCode(); | ||
String sqlState = getSQLState(code); | ||
int vendorCode = getVendorCode(code); | ||
|
||
if (code.isRetryable(false)) { | ||
return new YdbRetryableException(message, sqlState, vendorCode, cause); | ||
} | ||
if (code.isRetryable(true)) { | ||
return new YdbConditionallyRetryableException(message, sqlState, vendorCode, cause); | ||
} | ||
|
||
return new YdbSQLException(message, sqlState, vendorCode, cause); | ||
} | ||
} |
18 changes: 13 additions & 5 deletions
18
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbConditionallyRetryableException.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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package tech.ydb.jdbc.exception; | ||
|
||
import java.sql.SQLTransientException; | ||
|
||
import tech.ydb.core.Status; | ||
import tech.ydb.core.UnexpectedResultException; | ||
|
||
public class YdbConditionallyRetryableException extends SQLTransientException { | ||
private static final long serialVersionUID = 2155728765762467203L; | ||
private final Status 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 = -2371144941971339449L; | ||
YdbConditionallyRetryableException(String message, String sqlState, int code, UnexpectedResultException cause) { | ||
super(message, sqlState, code, cause); | ||
this.status = cause.getStatus(); | ||
} | ||
|
||
YdbConditionallyRetryableException(String message, String sqlState, Status status) { | ||
super(message, sqlState, status); | ||
public Status getStatus() { | ||
return status; | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbConfigurationException.java
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbExecutionException.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbNonRetryableException.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbResultTruncatedException.java
This file was deleted.
Oops, something went wrong.
17 changes: 13 additions & 4 deletions
17
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbRetryableException.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 |
---|---|---|
@@ -1,11 +1,20 @@ | ||
package tech.ydb.jdbc.exception; | ||
|
||
import java.sql.SQLRecoverableException; | ||
|
||
import tech.ydb.core.Status; | ||
import tech.ydb.core.UnexpectedResultException; | ||
|
||
public class YdbRetryableException extends SQLRecoverableException { | ||
private static final long serialVersionUID = -7171306648623023924L; | ||
private final Status status; | ||
|
||
public class YdbRetryableException extends YdbStatusException { | ||
private static final long serialVersionUID = 2082287790625648960L; | ||
YdbRetryableException(String message, String sqlState, int code, UnexpectedResultException cause) { | ||
super(message, sqlState, code, cause); | ||
this.status = cause.getStatus(); | ||
} | ||
|
||
YdbRetryableException(String message, String sqlState, Status status) { | ||
super(message, sqlState, status); | ||
public Status getStatus() { | ||
return status; | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbRuntimeException.java
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbSQLException.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,21 @@ | ||
package tech.ydb.jdbc.exception; | ||
|
||
import java.sql.SQLException; | ||
|
||
import tech.ydb.core.Status; | ||
import tech.ydb.core.UnexpectedResultException; | ||
|
||
public class YdbSQLException extends SQLException { | ||
private static final long serialVersionUID = 6204553083196091739L; | ||
|
||
private final Status status; | ||
|
||
YdbSQLException(String message, String sqlState, int code, UnexpectedResultException cause) { | ||
super(message, sqlState, code, cause); | ||
this.status = cause.getStatus(); | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
jdbc/src/main/java/tech/ydb/jdbc/exception/YdbStatusException.java
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.