|
29 | 29 | import tech.ydb.jdbc.exception.ExceptionFactory; |
30 | 30 | import tech.ydb.jdbc.impl.YdbTracerImpl; |
31 | 31 | import tech.ydb.jdbc.impl.YdbTracerNone; |
| 32 | +import tech.ydb.jdbc.query.QueryKey; |
32 | 33 | import tech.ydb.jdbc.query.QueryType; |
33 | 34 | import tech.ydb.jdbc.query.YdbPreparedQuery; |
34 | 35 | import tech.ydb.jdbc.query.YdbQuery; |
@@ -83,7 +84,7 @@ public class YdbContext implements AutoCloseable { |
83 | 84 | private final String prefixPath; |
84 | 85 | private final String prefixPragma; |
85 | 86 |
|
86 | | - private final Cache<String, YdbQuery> queriesCache; |
| 87 | + private final Cache<QueryKey, YdbQuery> queriesCache; |
87 | 88 | private final Cache<String, QueryStat> statsCache; |
88 | 89 | private final Cache<String, Map<String, Type>> queryParamsCache; |
89 | 90 | private final Cache<String, TableDescription> tableDescribeCache; |
@@ -348,22 +349,21 @@ public <T extends BaseRequestSettings.BaseBuilder<T>> T withRequestTimeout(T bui |
348 | 349 | return builder.withRequestTimeout(operation); |
349 | 350 | } |
350 | 351 |
|
351 | | - public YdbQuery parseYdbQuery(String sql) throws SQLException { |
352 | | - return YdbQuery.parseQuery(sql, queryOptions, types); |
| 352 | + public YdbQuery parseYdbQuery(String query) throws SQLException { |
| 353 | + return YdbQuery.parseQuery(new QueryKey(query), queryOptions, types); |
353 | 354 | } |
354 | 355 |
|
355 | | - public YdbQuery findOrParseYdbQuery(String sql) throws SQLException { |
| 356 | + public YdbQuery findOrParseYdbQuery(QueryKey key) throws SQLException { |
356 | 357 | if (queriesCache == null) { |
357 | | - return parseYdbQuery(sql); |
| 358 | + return YdbQuery.parseQuery(key, queryOptions, types); |
358 | 359 | } |
359 | 360 |
|
360 | | - YdbQuery cached = queriesCache.getIfPresent(sql); |
| 361 | + YdbQuery cached = queriesCache.getIfPresent(key); |
361 | 362 | if (cached == null) { |
362 | | - cached = parseYdbQuery(sql); |
363 | | - queriesCache.put(sql, cached); |
| 363 | + cached = YdbQuery.parseQuery(key, queryOptions, types); |
| 364 | + queriesCache.put(key, cached); |
364 | 365 | } |
365 | 366 |
|
366 | | - |
367 | 367 | return cached; |
368 | 368 | } |
369 | 369 |
|
@@ -432,16 +432,19 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode) |
432 | 432 | tableDescribeCache.put(tablePath, description); |
433 | 433 | } else { |
434 | 434 | if (type == QueryType.BULK_QUERY) { |
435 | | - throw new SQLException(YdbConst.BULKS_DESCRIBE_ERROR + result.getStatus()); |
| 435 | + throw new SQLException(YdbConst.BULK_DESCRIBE_ERROR + result.getStatus()); |
436 | 436 | } |
437 | 437 | } |
438 | 438 | } |
439 | 439 | if (type == QueryType.BULK_QUERY) { |
| 440 | + if (query.getReturning() != null) { |
| 441 | + throw new SQLException(YdbConst.BULK_NOT_SUPPORT_RETURNING); |
| 442 | + } |
440 | 443 | return BulkUpsertQuery.build(types, tablePath, query.getYqlBatcher().getColumns(), description); |
441 | 444 | } |
442 | 445 |
|
443 | 446 | if (description != null) { |
444 | | - BatchedQuery params = BatchedQuery.createAutoBatched(types, query.getYqlBatcher(), description); |
| 447 | + BatchedQuery params = BatchedQuery.createAutoBatched(types, query, description); |
445 | 448 | if (params != null) { |
446 | 449 | return params; |
447 | 450 | } |
|
0 commit comments