Skip to content

Commit fd7f26b

Browse files
committed
Update usage of YdbStatusException
1 parent edd529f commit fd7f26b

File tree

5 files changed

+13
-84
lines changed

5 files changed

+13
-84
lines changed

jdbc/src/main/java/tech/ydb/jdbc/context/YdbExecutor.java

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@
1616
import tech.ydb.core.Issue;
1717
import tech.ydb.core.Result;
1818
import tech.ydb.core.Status;
19-
import tech.ydb.jdbc.exception.YdbConditionallyRetryableException;
2019
import tech.ydb.jdbc.exception.YdbExecutionException;
21-
import tech.ydb.jdbc.exception.YdbNonRetryableException;
22-
import tech.ydb.jdbc.exception.YdbRetryableException;
20+
import tech.ydb.jdbc.exception.YdbStatusException;
2321
import tech.ydb.table.Session;
2422

2523
/**
@@ -119,67 +117,8 @@ private void simpleExecute(Supplier<CompletableFuture<Status>> supplier) throws
119117

120118
private void validate(String message, Status status) throws SQLException {
121119
issues.addAll(Arrays.asList(status.getIssues()));
122-
123-
switch (status.getCode()) {
124-
case SUCCESS:
125-
return;
126-
127-
case BAD_REQUEST:
128-
case INTERNAL_ERROR:
129-
case CLIENT_UNAUTHENTICATED:
130-
// gRPC reports, request is not authenticated
131-
// Maybe internal error, maybe some issue with token
132-
case UNAUTHORIZED:
133-
// Unauthorized by database
134-
case SCHEME_ERROR:
135-
case GENERIC_ERROR:
136-
case CLIENT_CALL_UNIMPLEMENTED:
137-
case UNSUPPORTED:
138-
case UNUSED_STATUS:
139-
case ALREADY_EXISTS:
140-
throw new YdbNonRetryableException(message, status.getCode());
141-
142-
case ABORTED:
143-
case UNAVAILABLE:
144-
// Some of database parts are not available
145-
case OVERLOADED:
146-
// Database is overloaded, need to retry with exponential backoff
147-
case TRANSPORT_UNAVAILABLE:
148-
// Some issues with networking
149-
case CLIENT_RESOURCE_EXHAUSTED:
150-
// No resources to handle client request
151-
case NOT_FOUND:
152-
// Could be 'prepared query' issue, could be 'transaction not found'
153-
// Should be retries with new session
154-
case BAD_SESSION:
155-
// Retry with new session
156-
case SESSION_EXPIRED:
157-
// Retry with new session
158-
throw new YdbRetryableException(message, status.getCode());
159-
160-
case CANCELLED:
161-
// Query was canceled due to query timeout (CancelAfter)
162-
// Query was definitely canceled by database
163-
case CLIENT_CANCELLED:
164-
case CLIENT_INTERNAL_ERROR:
165-
// Some unknown client side error, probably on transport layer
166-
throw new YdbConditionallyRetryableException(message, status.getCode());
167-
168-
case UNDETERMINED:
169-
case TIMEOUT:
170-
// Database cannot respond in time, need to retry with exponential backoff
171-
case PRECONDITION_FAILED:
172-
case CLIENT_DEADLINE_EXCEEDED:
173-
// Query was canceled on transport layer
174-
case SESSION_BUSY:
175-
// Another query is executing already, retry with new session
176-
case CLIENT_DISCOVERY_FAILED:
177-
// Some issue with database endpoints discovery
178-
case CLIENT_LIMITS_REACHED:
179-
// Client side session limit was reached
180-
throw new YdbConditionallyRetryableException(message, status.getCode());
181-
default:
182-
throw new YdbNonRetryableException(message, status.getCode());
120+
if (!status.isSuccess()) {
121+
throw YdbStatusException.newException(message, status);
183122
}
184123
}
185124
}

jdbc/src/main/java/tech/ydb/jdbc/impl/YdbDatabaseMetaDataImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import tech.ydb.jdbc.common.FixedResultSetFactory;
3131
import tech.ydb.jdbc.common.YdbFunctions;
3232
import tech.ydb.jdbc.context.YdbExecutor;
33-
import tech.ydb.jdbc.exception.YdbExecutionStatusException;
33+
import tech.ydb.jdbc.exception.YdbStatusException;
3434
import tech.ydb.proto.scheme.SchemeOperationProtos;
3535
import tech.ydb.scheme.SchemeClient;
3636
import tech.ydb.scheme.description.ListDirectoryResult;
@@ -1352,8 +1352,8 @@ private TableDescription describeTable(String table) throws SQLException {
13521352
return executor.call("Describe table " + table,
13531353
() -> session.describeTable(databaseWithSuffix + table, settings)
13541354
);
1355-
} catch (YdbExecutionStatusException ex) {
1356-
if (ex.getStatusCode() != StatusCode.SCHEME_ERROR) { // ignore scheme errors like path not found
1355+
} catch (YdbStatusException ex) {
1356+
if (ex.getStatus().getCode() != StatusCode.SCHEME_ERROR) { // ignore scheme errors like path not found
13571357
throw ex;
13581358
}
13591359
LOGGER.log(Level.WARNING, "Cannot describe table {0} -> {1}",

jdbc/src/main/java/tech/ydb/jdbc/impl/params/BatchedParams.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import java.util.List;
99
import java.util.Map;
1010

11-
import tech.ydb.core.StatusCode;
1211
import tech.ydb.jdbc.YdbConst;
1312
import tech.ydb.jdbc.common.TypeDescription;
14-
import tech.ydb.jdbc.exception.YdbNonRetryableException;
13+
import tech.ydb.jdbc.exception.YdbStatusException;
1514
import tech.ydb.jdbc.impl.YdbJdbcParams;
1615
import tech.ydb.table.query.Params;
1716
import tech.ydb.table.values.ListType;
@@ -86,10 +85,7 @@ private StructValue validatedCurrentStruct() throws SQLException {
8685
continue;
8786
}
8887

89-
throw new YdbNonRetryableException(
90-
YdbConst.MISSING_VALUE_FOR_PARAMETER + prm.displayName(),
91-
StatusCode.BAD_REQUEST
92-
);
88+
throw YdbStatusException.newBadRequest(YdbConst.MISSING_VALUE_FOR_PARAMETER + prm.displayName());
9389
}
9490
return StructValue.of(currentValues);
9591
}

jdbc/src/main/java/tech/ydb/jdbc/query/YdbQuery.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import java.util.List;
77
import java.util.Map;
88

9-
import tech.ydb.core.StatusCode;
109
import tech.ydb.jdbc.YdbConst;
11-
import tech.ydb.jdbc.exception.YdbNonRetryableException;
10+
import tech.ydb.jdbc.exception.YdbStatusException;
1211
import tech.ydb.table.query.Params;
1312
import tech.ydb.table.values.Value;
1413

@@ -52,10 +51,7 @@ public String getYqlQuery(Params params) throws SQLException {
5251
for (int idx = 0; idx < indexesArgsNames.size(); idx += 1) {
5352
String prm = indexesArgsNames.get(idx);
5453
if (!values.containsKey(prm)) {
55-
throw new YdbNonRetryableException(
56-
YdbConst.MISSING_VALUE_FOR_PARAMETER + prm,
57-
StatusCode.BAD_REQUEST
58-
);
54+
throw YdbStatusException.newBadRequest(YdbConst.MISSING_VALUE_FOR_PARAMETER + prm);
5955
}
6056

6157
if (opts.isDeclareJdbcParameters()) {

jdbc/src/main/java/tech/ydb/jdbc/query/YdbQueryBuilder.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import tech.ydb.core.StatusCode;
76
import tech.ydb.jdbc.YdbConst;
8-
import tech.ydb.jdbc.exception.YdbNonRetryableException;
7+
import tech.ydb.jdbc.exception.YdbStatusException;
98

109
/**
1110
*
@@ -37,14 +36,13 @@ public String createNextArgName() {
3736
}
3837
}
3938

40-
public void setQueryType(QueryType type) throws YdbNonRetryableException {
39+
public void setQueryType(QueryType type) throws YdbStatusException {
4140
if (forcedType != null) {
4241
return;
4342
}
4443

4544
if (currentType != null && currentType != type) {
46-
String msg = YdbConst.MULTI_TYPES_IN_ONE_QUERY + currentType + ", " + type;
47-
throw new YdbNonRetryableException(msg, StatusCode.BAD_REQUEST);
45+
throw YdbStatusException.newBadRequest(YdbConst.MULTI_TYPES_IN_ONE_QUERY + currentType + ", " + type);
4846
}
4947
this.currentType = type;
5048
}

0 commit comments

Comments
 (0)