11package tech .ydb .jdbc .query ;
22
3+ import java .util .Map ;
4+
35import com .google .common .annotations .VisibleForTesting ;
46
7+ import tech .ydb .jdbc .settings .ParsedProperty ;
58import tech .ydb .jdbc .settings .YdbOperationProperties ;
9+ import tech .ydb .jdbc .settings .YdbOperationProperty ;
10+
611
712/**
813 *
914 * @author Aleksandr Gorshenin
1015 */
1116public class YdbQueryOptions {
17+ private final boolean isEnforceSyntaxV1 ;
18+
1219 private final boolean isDetectQueryType ;
1320 private final boolean isDetectJdbcParameters ;
1421 private final boolean isDeclareJdbcParameters ;
15- private final boolean isEnforceSyntaxV1 ;
1622
17- public YdbQueryOptions (YdbOperationProperties props ) {
18- this .isDetectQueryType = props .isDetectSqlOperations ();
19- this .isDetectJdbcParameters = !props .isJdbcParametersSupportDisabled ();
20- this .isDeclareJdbcParameters = true ;
21- this .isEnforceSyntaxV1 = props .isEnforceSqlV1 ();
22- }
23+ private final boolean isPrepareDataQueries ;
24+ private final boolean isDetectBatchQueries ;
2325
2426 @ VisibleForTesting
25- YdbQueryOptions (boolean queryType , boolean jdbcParams , boolean declare , boolean syntaxV1 ) {
26- this .isDetectQueryType = queryType ;
27- this .isDetectJdbcParameters = jdbcParams ;
28- this .isDeclareJdbcParameters = declare ;
29- this .isEnforceSyntaxV1 = syntaxV1 ;
27+ YdbQueryOptions (
28+ boolean enforceV1 ,
29+ boolean detectQueryType ,
30+ boolean detectJbdcParams ,
31+ boolean declareJdbcParams ,
32+ boolean prepareDataQuery ,
33+ boolean detectBatchQuery
34+ ) {
35+ this .isEnforceSyntaxV1 = enforceV1 ;
36+
37+ this .isDetectQueryType = detectQueryType ;
38+ this .isDetectJdbcParameters = detectJbdcParams ;
39+ this .isDeclareJdbcParameters = declareJdbcParams ;
40+
41+ this .isPrepareDataQueries = prepareDataQuery ;
42+ this .isDetectBatchQueries = detectBatchQuery ;
3043 }
3144
3245 public boolean isEnforceSyntaxV1 () {
@@ -44,4 +57,67 @@ public boolean isDetectJdbcParameters() {
4457 public boolean isDeclareJdbcParameters () {
4558 return isDeclareJdbcParameters ;
4659 }
60+
61+ public boolean iPrepareDataQueries () {
62+ return isPrepareDataQueries ;
63+ }
64+
65+ public boolean isDetectBatchQueries () {
66+ return isDetectBatchQueries ;
67+ }
68+
69+ public static YdbQueryOptions createFrom (YdbOperationProperties props ) {
70+ int level = props .getJdbcSupportLevel ();
71+
72+ boolean enforceV1 = level > 5 ;
73+ boolean declareJdbcParams = level > 4 ;
74+ boolean detectJbdcParams = level > 3 ;
75+ boolean detectBatchQuery = level > 2 ;
76+ boolean prepareDataQuery = level > 1 ;
77+ boolean detectQueryType = level > 0 ;
78+
79+ // forced properies
80+ Map <YdbOperationProperty <?>, ParsedProperty > params = props .getParams ();
81+ if (params .containsKey (YdbOperationProperty .ENFORCE_SQL_V1 )) {
82+ enforceV1 = params .get (YdbOperationProperty .ENFORCE_SQL_V1 ).getParsedValue ();
83+ }
84+
85+ if (params .containsKey (YdbOperationProperty .DISABLE_AUTO_PREPARED_BATCHES )) {
86+ boolean v = params .get (YdbOperationProperty .DISABLE_AUTO_PREPARED_BATCHES ).getParsedValue ();
87+ detectBatchQuery = !v ;
88+ }
89+
90+ if (params .containsKey (YdbOperationProperty .DISABLE_PREPARE_DATAQUERY )) {
91+ boolean v = params .get (YdbOperationProperty .DISABLE_PREPARE_DATAQUERY ).getParsedValue ();
92+ prepareDataQuery = !v ;
93+ detectBatchQuery = detectBatchQuery && prepareDataQuery ;
94+ }
95+
96+ if (params .containsKey (YdbOperationProperty .DISABLE_JDBC_PARAMETERS_DECLARE )) {
97+ boolean v = params .get (YdbOperationProperty .DISABLE_JDBC_PARAMETERS_DECLARE ).getParsedValue ();
98+ declareJdbcParams = !v ;
99+ }
100+
101+ if (params .containsKey (YdbOperationProperty .DISABLE_JDBC_PARAMETERS )) {
102+ boolean v = params .get (YdbOperationProperty .DISABLE_JDBC_PARAMETERS ).getParsedValue ();
103+ detectJbdcParams = !v ;
104+ declareJdbcParams = declareJdbcParams && detectJbdcParams ;
105+ }
106+
107+ if (params .containsKey (YdbOperationProperty .DISABLE_DETECT_SQL_OPERATIONS )) {
108+ boolean v = params .get (YdbOperationProperty .DISABLE_DETECT_SQL_OPERATIONS ).getParsedValue ();
109+ detectQueryType = !v ;
110+ detectJbdcParams = detectJbdcParams && detectQueryType ;
111+ declareJdbcParams = declareJdbcParams && detectJbdcParams ;
112+ }
113+
114+ return new YdbQueryOptions (
115+ enforceV1 ,
116+ detectQueryType ,
117+ detectJbdcParams ,
118+ declareJdbcParams ,
119+ prepareDataQuery ,
120+ detectBatchQuery
121+ );
122+ }
47123}
0 commit comments