Skip to content

Commit add4df0

Browse files
committed
Add new property jdbcSupportLevel
1 parent dd12371 commit add4df0

File tree

9 files changed

+130
-73
lines changed

9 files changed

+130
-73
lines changed

jdbc/src/main/java/tech/ydb/jdbc/YdbConst.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public final class YdbConst {
131131
*/
132132
public static final int STALE_CONSISTENT_READ_ONLY = 3; // TODO: verify if we can do that
133133

134+
public static final int DEFAULT_JDBC_SUPPORT_LEVEL = 5;
134135

135136
// Processing queries
136137
public static final String PREFIX_SYNTAX_V1 = "--!syntax_v1";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private YdbContext(YdbConfig config, GrpcTransport transport, PooledTableClient
5050
this.grpcTransport = Objects.requireNonNull(transport);
5151
this.tableClient = Objects.requireNonNull(tableClient);
5252
this.schemeClient = SchemeClient.newClient(transport).build();
53-
this.queryOptions = new YdbQueryOptions(config.getOperationProperties());
53+
this.queryOptions = YdbQueryOptions.createFrom(config.getOperationProperties());
5454
this.autoResizeSessionPool = autoResize;
5555
}
5656

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import tech.ydb.jdbc.YdbConst;
1010
import tech.ydb.jdbc.YdbPrepareMode;
1111
import tech.ydb.jdbc.common.TypeDescription;
12-
import tech.ydb.jdbc.query.YdbQuery;
1312
import tech.ydb.jdbc.exception.YdbExecutionException;
1413
import tech.ydb.jdbc.impl.params.BatchedParams;
1514
import tech.ydb.jdbc.impl.params.InMemoryParams;
1615
import tech.ydb.jdbc.impl.params.PreparedParams;
17-
import tech.ydb.jdbc.settings.YdbOperationProperties;
16+
import tech.ydb.jdbc.query.YdbQuery;
17+
import tech.ydb.jdbc.query.YdbQueryOptions;
1818
import tech.ydb.table.query.DataQuery;
1919
import tech.ydb.table.query.Params;
2020
import tech.ydb.table.values.Type;
@@ -43,18 +43,18 @@ public interface YdbJdbcParams {
4343
Params getCurrentParams() throws SQLException;
4444

4545
static YdbJdbcParams create(YdbConnectionImpl connection, YdbQuery query, YdbPrepareMode mode) throws SQLException {
46-
YdbOperationProperties props = connection.getCtx().getOperationProperties();
46+
YdbQueryOptions opts = connection.getCtx().getQueryOptions();
4747

4848
if (query.hasIndexesParameters()
4949
|| mode == YdbPrepareMode.IN_MEMORY
50-
|| props.isPrepareDataQueryDisabled()) {
50+
|| !opts.iPrepareDataQueries()) {
5151
return new InMemoryParams(query.getIndexesParameters());
5252
}
5353

5454
DataQuery prepared = connection.prepareDataQuery(query);
5555

5656
boolean requireBatch = mode == YdbPrepareMode.DATA_QUERY_BATCH;
57-
if (requireBatch || (mode == YdbPrepareMode.AUTO && !props.isAutoPreparedBatchesDisabled())) {
57+
if (requireBatch || (mode == YdbPrepareMode.AUTO && opts.isDetectBatchQueries())) {
5858
BatchedParams params = BatchedParams.tryCreateBatched(prepared.types());
5959
if (params != null) {
6060
return params;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.ydb.jdbc.query;
22

3+
34
import java.sql.SQLException;
45

56

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tech.ydb.jdbc.query;
22

33

4+
45
import java.sql.SQLException;
56
import java.util.List;
67
import java.util.Map;
Lines changed: 88 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
package tech.ydb.jdbc.query;
22

3+
import java.util.Map;
4+
35
import com.google.common.annotations.VisibleForTesting;
46

7+
import tech.ydb.jdbc.settings.ParsedProperty;
58
import tech.ydb.jdbc.settings.YdbOperationProperties;
9+
import tech.ydb.jdbc.settings.YdbOperationProperty;
10+
611

712
/**
813
*
914
* @author Aleksandr Gorshenin
1015
*/
1116
public 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
}

jdbc/src/main/java/tech/ydb/jdbc/settings/YdbOperationProperties.java

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ public class YdbOperationProperties {
1717
private final boolean autoCommit;
1818
private final int transactionLevel;
1919
private final int maxRows;
20-
private final boolean enforceSqlV1;
21-
private final boolean enforceVariablePrefix;
2220
private final boolean cacheConnectionsInDriver;
23-
private final boolean detectSqlOperations;
2421

25-
private final boolean disablePrepareDataQuery;
26-
private final boolean disableAutoPreparedBatches;
27-
private final boolean disableJdbcParametersSupport;
22+
private final int jdbcSupportLevel;
2823

2924
public YdbOperationProperties(Map<YdbOperationProperty<?>, ParsedProperty> params) {
3025
this.params = Objects.requireNonNull(params);
@@ -38,17 +33,9 @@ public YdbOperationProperties(Map<YdbOperationProperty<?>, ParsedProperty> param
3833
this.autoCommit = params.get(YdbOperationProperty.AUTOCOMMIT).getParsedValue();
3934
this.transactionLevel = params.get(YdbOperationProperty.TRANSACTION_LEVEL).getParsedValue();
4035
this.maxRows = MAX_ROWS;
41-
this.enforceSqlV1 = params.get(YdbOperationProperty.ENFORCE_SQL_V1).getParsedValue();
42-
this.enforceVariablePrefix = params.get(YdbOperationProperty.ENFORCE_VARIABLE_PREFIX).getParsedValue();
4336
this.cacheConnectionsInDriver = params.get(YdbOperationProperty.CACHE_CONNECTIONS_IN_DRIVER).getParsedValue();
44-
this.detectSqlOperations = params.get(YdbOperationProperty.DETECT_SQL_OPERATIONS).getParsedValue();
45-
46-
this.disablePrepareDataQuery = params.get(YdbOperationProperty.DISABLE_PREPARE_DATAQUERY)
47-
.getParsedValue();
48-
this.disableAutoPreparedBatches = params.get(YdbOperationProperty.DISABLE_AUTO_PREPARED_BATCHES)
49-
.getParsedValue();
50-
this.disableJdbcParametersSupport = params.get(YdbOperationProperty.DISABLE_JDBC_PARAMETERS)
51-
.getParsedValue();
37+
38+
this.jdbcSupportLevel = params.get(YdbOperationProperty.JDBC_SUPPORT_LEVEL).getParsedValue();
5239
}
5340

5441
public Map<YdbOperationProperty<?>, ParsedProperty> getParams() {
@@ -91,31 +78,11 @@ public int getMaxRows() {
9178
return maxRows;
9279
}
9380

94-
public boolean isEnforceSqlV1() {
95-
return enforceSqlV1;
96-
}
97-
98-
public boolean isEnforceVariablePrefix() {
99-
return enforceVariablePrefix;
100-
}
101-
10281
public boolean isCacheConnectionsInDriver() {
10382
return cacheConnectionsInDriver;
10483
}
10584

106-
public boolean isDetectSqlOperations() {
107-
return detectSqlOperations;
108-
}
109-
110-
public boolean isPrepareDataQueryDisabled() {
111-
return disablePrepareDataQuery;
112-
}
113-
114-
public boolean isAutoPreparedBatchesDisabled() {
115-
return disableAutoPreparedBatches;
116-
}
117-
118-
public boolean isJdbcParametersSupportDisabled() {
119-
return disableJdbcParametersSupport;
85+
public int getJdbcSupportLevel() {
86+
return jdbcSupportLevel;
12087
}
12188
}

jdbc/src/main/java/tech/ydb/jdbc/settings/YdbOperationProperty.java

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import javax.annotation.Nullable;
88

9+
import tech.ydb.jdbc.YdbConst;
10+
911

1012
public class YdbOperationProperty<T> extends AbstractYdbProperty<T, Void> {
1113
private static final PropertiesCollector<YdbOperationProperty<?>> PROPERTIES = new PropertiesCollector<>();
@@ -78,31 +80,25 @@ public class YdbOperationProperty<T> extends AbstractYdbProperty<T, Void> {
7880

7981
// Some JDBC driver specific options
8082

81-
public static final YdbOperationProperty<Boolean> ENFORCE_SQL_V1 =
82-
new YdbOperationProperty<>("enforceSqlV1",
83-
"Enforce SQL v1 grammar by adding --!syntax_v1 in the beginning of each SQL statement",
83+
public static final YdbOperationProperty<Boolean> CACHE_CONNECTIONS_IN_DRIVER =
84+
new YdbOperationProperty<>("cacheConnectionsInDriver",
85+
"Cache YDB connections in YdbDriver, cached by combination or url and properties",
8486
"true",
8587
Boolean.class,
8688
PropertyConverter.booleanValue());
8789

88-
public static final YdbOperationProperty<Boolean> ENFORCE_VARIABLE_PREFIX =
89-
new YdbOperationProperty<>("enforceVariablePrefix",
90-
"Enforce variable prefixes, add $ symbol to all named variables when absent",
91-
"true",
92-
Boolean.class,
93-
PropertyConverter.booleanValue());
9490

95-
public static final YdbOperationProperty<Boolean> CACHE_CONNECTIONS_IN_DRIVER =
96-
new YdbOperationProperty<>("cacheConnectionsInDriver",
97-
"Cache YDB connections in YdbDriver, cached by combination or url and properties",
98-
"true",
91+
public static final YdbOperationProperty<Boolean> ENFORCE_SQL_V1 =
92+
new YdbOperationProperty<>("enforceSqlV1",
93+
"Enforce SQL v1 grammar by adding --!syntax_v1 in the beginning of each SQL statement",
94+
"false",
9995
Boolean.class,
10096
PropertyConverter.booleanValue());
10197

102-
public static final YdbOperationProperty<Boolean> DETECT_SQL_OPERATIONS =
103-
new YdbOperationProperty<>("detectSqlOperations",
104-
"Detect and execute SQL operation based on SQL keywords",
105-
"true",
98+
public static final YdbOperationProperty<Boolean> DISABLE_DETECT_SQL_OPERATIONS =
99+
new YdbOperationProperty<>("disableDetectSqlOperations",
100+
"Disable detecting SQL operation based on SQL keywords",
101+
"false",
106102
Boolean.class,
107103
PropertyConverter.booleanValue());
108104

@@ -128,6 +124,20 @@ public class YdbOperationProperty<T> extends AbstractYdbProperty<T, Void> {
128124
Boolean.class,
129125
PropertyConverter.booleanValue());
130126

127+
public static final YdbOperationProperty<Boolean> DISABLE_JDBC_PARAMETERS_DECLARE =
128+
new YdbOperationProperty<>("disableJdbcParameterDeclare",
129+
"Disable enforce DECLARE section for JDBC parameters '?'",
130+
"false",
131+
Boolean.class,
132+
PropertyConverter.booleanValue());
133+
134+
public static final YdbOperationProperty<Integer> JDBC_SUPPORT_LEVEL =
135+
new YdbOperationProperty<>("jdbcSupportLevel",
136+
"Disable auto detect JDBC standart parameters '?'",
137+
"" + YdbConst.DEFAULT_JDBC_SUPPORT_LEVEL,
138+
Integer.class,
139+
PropertyConverter.integerValue());
140+
131141
protected YdbOperationProperty(String name,
132142
String description,
133143
@Nullable String defaultValue,

jdbc/src/main/java/tech/ydb/jdbc/settings/YdbProperties.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.ydb.jdbc.settings;
22

3+
34
import java.sql.DriverPropertyInfo;
45
import java.util.ArrayList;
56
import java.util.List;

0 commit comments

Comments
 (0)