22
33import java .sql .SQLException ;
44import java .util .Properties ;
5+ import java .util .logging .Logger ;
56
7+ import tech .ydb .jdbc .YdbDriver ;
68import tech .ydb .jdbc .query .QueryType ;
79
810
1214 * @author Aleksandr Gorshenin
1315 */
1416public class YdbQueryProperties {
17+ private static final Logger LOGGER = Logger .getLogger (YdbDriver .class .getName ());
18+
1519 static final YdbProperty <Boolean > DISABLE_DETECT_SQL_OPERATIONS = YdbProperty .bool ("disableDetectSqlOperations" ,
1620 "Disable detecting SQL operation based on SQL keywords" , false );
1721
@@ -27,23 +31,33 @@ public class YdbQueryProperties {
2731 static final YdbProperty <Boolean > DISABLE_JDBC_PARAMETERS_DECLARE = YdbProperty .bool ("disableJdbcParameterDeclare" ,
2832 "Disable enforce DECLARE section for JDBC parameters '?'" , false );
2933
30- static final YdbProperty <QueryType > FORCE_QUERY_MODE = YdbProperty .enums ("forceQueryMode" , QueryType .class ,
31- "Force usage one of query modes (DATA_QUERY, SCAN_QUERY, SCHEME_QUERY or EXPLAIN_QUERYn) for all statements"
34+ @ Deprecated
35+ private static final YdbProperty <QueryType > FORCE_QUERY_MODE = YdbProperty .enums ("forceQueryMode" , QueryType .class ,
36+ "Force usage one of query modes (DATA_QUERY, SCAN_QUERY, SCHEME_QUERY or EXPLAIN_QUERY) for all statements"
3237 );
33- static final YdbProperty <Boolean > FORCE_SCAN_BULKS = YdbProperty .bool ("forceScanAndBulk" ,
38+ @ Deprecated
39+ private static final YdbProperty <Boolean > FORCE_SCAN_BULKS = YdbProperty .bool ("forceScanAndBulk" ,
3440 "Force usage of bulk upserts instead of upserts/inserts and scan query for selects" ,
3541 false
3642 );
3743
44+ static final YdbProperty <Boolean > REPLACE_INSERT_TO_UPSERT = YdbProperty .bool ("replaceInsertByUpsert" ,
45+ "Convert all INSERT statements to UPSERT statements" , false );
46+ static final YdbProperty <Boolean > FORCE_BULK_UPSERT = YdbProperty .bool ("forceBulkUpsert" ,
47+ "Execute all UPSERT statements as BulkUpserts" , false );
48+ static final YdbProperty <Boolean > FORCE_SCAN_SELECT = YdbProperty .bool ("forceScanSelect" ,
49+ "Execute all SELECT statements as ScanQuery" , false );
50+
3851 private final boolean isDetectQueryType ;
3952 private final boolean isDetectJdbcParameters ;
4053 private final boolean isDeclareJdbcParameters ;
4154
4255 private final boolean isPrepareDataQueries ;
4356 private final boolean isDetectBatchQueries ;
4457
45- private final QueryType forcedType ;
46- private final boolean isForcedScanAndBulks ;
58+ private final boolean isReplaceInsertToUpsert ;
59+ private final boolean isForceBulkUpsert ;
60+ private final boolean isForceScanSelect ;
4761
4862 public YdbQueryProperties (YdbConfig config ) throws SQLException {
4963 Properties props = config .getProperties ();
@@ -63,8 +77,24 @@ public YdbQueryProperties(YdbConfig config) throws SQLException {
6377 this .isDeclareJdbcParameters = !disableSqlOperationsDetect && !disableJdbcParametersParse
6478 && !disableJdbcParametersDeclare ;
6579
66- this .forcedType = FORCE_QUERY_MODE .readValue (props ).getValue ();
67- this .isForcedScanAndBulks = FORCE_SCAN_BULKS .readValue (props ).getValue ();
80+
81+ YdbValue <QueryType > forcedType = FORCE_QUERY_MODE .readValue (props );
82+ if (forcedType .hasValue ()) {
83+ LOGGER .warning ("Option 'forceQueryMode' is deprecated and will be removed in next versions. "
84+ + "Use options 'forceScanSelect' and 'forceBulkUpsert' instead" );
85+ }
86+ YdbValue <Boolean > forceScanAndBulk = FORCE_SCAN_BULKS .readValue (props );
87+ if (forceScanAndBulk .hasValue ()) {
88+ LOGGER .warning ("Option 'forceScanAndBulk' is deprecated and will be removed in next versions. "
89+ + "Use options 'replaceInsertByUpsert', 'forceScanSelect' and 'forceBulkUpsert' instead" );
90+ }
91+
92+ this .isReplaceInsertToUpsert = REPLACE_INSERT_TO_UPSERT .readValue (props )
93+ .getValueOrOther (forceScanAndBulk .getValue ());
94+ this .isForceBulkUpsert = FORCE_BULK_UPSERT .readValue (props )
95+ .getValueOrOther (forceScanAndBulk .getValue () || forcedType .getValue () == QueryType .BULK_QUERY );
96+ this .isForceScanSelect = FORCE_SCAN_SELECT .readValue (props )
97+ .getValueOrOther (forceScanAndBulk .getValue () || forcedType .getValue () == QueryType .SCAN_QUERY );
6898 }
6999
70100 public boolean isDetectQueryType () {
@@ -87,11 +117,15 @@ public boolean isDetectBatchQueries() {
87117 return isDetectBatchQueries ;
88118 }
89119
90- public QueryType getForcedQueryType () {
91- return forcedType ;
120+ public boolean isReplaceInsertToUpsert () {
121+ return isReplaceInsertToUpsert ;
122+ }
123+
124+ public boolean isForceBulkUpsert () {
125+ return isForceBulkUpsert ;
92126 }
93127
94- public boolean isForcedScanAndBulks () {
95- return isForcedScanAndBulks ;
128+ public boolean isForceScanSelect () {
129+ return isForceScanSelect ;
96130 }
97131}
0 commit comments