@@ -437,49 +437,46 @@ public YdbPreparedQuery findOrPrepareParams(YdbQuery query, YdbPrepareMode mode)
437437 }
438438
439439 // try to prepare data query
440- try {
441- Map <String , Type > types = queryParamsCache .getIfPresent (query .getOriginQuery ());
442- if (types == null ) {
443- String yql = prefixPragma + query .getPreparedYql ();
444- YdbTracer tracer = config .isTxTracedEnabled () ? YdbTracer .current () : null ;
445- if (tracer != null ) {
446- tracer .trace ("--> prepare data query" );
447- tracer .traceRequest (yql );
448- }
440+ Map <String , Type > types = queryParamsCache .getIfPresent (query .getOriginQuery ());
441+ if (types == null ) {
442+ String yql = prefixPragma + query .getPreparedYql ();
443+ YdbTracer tracer = config .isTxTracedEnabled () ? YdbTracer .current () : null ;
444+ if (tracer != null ) {
445+ tracer .trace ("--> prepare data query" );
446+ tracer .traceRequest (yql );
447+ }
449448
450- PrepareDataQuerySettings settings = withDefaultTimeout (new PrepareDataQuerySettings ());
451- Result <DataQuery > result = retryCtx .supplyResult (
452- session -> session .prepareDataQuery (yql , settings )
453- ).join ();
449+ PrepareDataQuerySettings settings = withDefaultTimeout (new PrepareDataQuerySettings ());
450+ Result <DataQuery > result = retryCtx .supplyResult (
451+ session -> session .prepareDataQuery (yql , settings )
452+ ).join ();
454453
454+ if (tracer != null ) {
455+ tracer .trace ("<-- " + result .getStatus ());
456+ }
457+ if (!result .isSuccess ()) {
455458 if (tracer != null ) {
456- tracer .trace ( "<-- " + result . getStatus () );
459+ tracer .close ( );
457460 }
458- if (!result .isSuccess ()) {
459- if (tracer != null ) {
460- tracer .close ();
461- }
462- throw new SQLException (YdbConst .UNABLE_PREPARE_STATEMENT + result .getStatus ());
463- }
464-
465- types = result .getValue ().types ();
466- queryParamsCache .put (query .getOriginQuery (), types );
461+ throw ExceptionFactory .createException ("Cannot prepare data query: " + result .getStatus (),
462+ new UnexpectedResultException ("Unexpected status" , result .getStatus ()));
467463 }
468464
469- boolean requireBatch = mode == YdbPrepareMode .DATA_QUERY_BATCH ;
470- if (requireBatch || (mode == YdbPrepareMode .AUTO && queryOptions .isDetectBatchQueries ())) {
471- BatchedQuery params = BatchedQuery .tryCreateBatched (query , types );
472- if (params != null ) {
473- return params ;
474- }
465+ types = result .getValue ().types ();
466+ queryParamsCache .put (query .getOriginQuery (), types );
467+ }
475468
476- if (requireBatch ) {
477- throw new SQLDataException (YdbConst .STATEMENT_IS_NOT_A_BATCH + query .getOriginQuery ());
478- }
469+ boolean requireBatch = mode == YdbPrepareMode .DATA_QUERY_BATCH ;
470+ if (requireBatch || (mode == YdbPrepareMode .AUTO && queryOptions .isDetectBatchQueries ())) {
471+ BatchedQuery params = BatchedQuery .tryCreateBatched (query , types );
472+ if (params != null ) {
473+ return params ;
474+ }
475+
476+ if (requireBatch ) {
477+ throw new SQLDataException (YdbConst .STATEMENT_IS_NOT_A_BATCH + query .getOriginQuery ());
479478 }
480- return new PreparedQuery (query , types );
481- } catch (UnexpectedResultException ex ) {
482- throw ExceptionFactory .createException ("Cannot prepare data query: " + ex .getMessage (), ex );
483479 }
480+ return new PreparedQuery (query , types );
484481 }
485482}
0 commit comments