Skip to content

Commit bf9af1c

Browse files
authored
Merge pull request #44 from ydb-platform/release_v2.0.6
Release v2.0.6
2 parents b492829 + 13b5159 commit bf9af1c

File tree

13 files changed

+125
-135
lines changed

13 files changed

+125
-135
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.0.6 ##
2+
3+
* Upgraded Java SDK version
4+
* Fixed Int6/Int16 auto detecting
5+
* Fixed standard transaction levels
6+
17
## 2.0.5 ##
28

39
* Extended usage of standard JDBC exception classes

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ Specify the YDB JDBC driver in the dependencies:
2525
<dependency>
2626
<groupId>tech.ydb.jdbc</groupId>
2727
<artifactId>ydb-jdbc-driver</artifactId>
28-
<version>2.0.5</version>
28+
<version>2.0.6</version>
2929
</dependency>
3030

3131
<!-- Shaded version with included dependencies -->
3232
<dependency>
3333
<groupId>tech.ydb.jdbc</groupId>
3434
<artifactId>ydb-jdbc-driver-shaded</artifactId>
35-
<version>2.0.5</version>
35+
<version>2.0.6</version>
3636
</dependency>
3737
</dependencies>
3838
```

jdbc-shaded/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>tech.ydb.jdbc</groupId>
88
<artifactId>ydb-jdbc-driver-parent</artifactId>
9-
<version>2.0.5</version>
9+
<version>2.0.6</version>
1010
</parent>
1111

1212
<artifactId>ydb-jdbc-driver-shaded</artifactId>

jdbc/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>tech.ydb.jdbc</groupId>
88
<artifactId>ydb-jdbc-driver-parent</artifactId>
9-
<version>2.0.5</version>
9+
<version>2.0.6</version>
1010
</parent>
1111

1212
<artifactId>ydb-jdbc-driver</artifactId>

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

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

3-
import java.sql.Connection;
4-
53
public final class YdbConst {
64

75
// SQL types
@@ -107,33 +105,25 @@ public final class YdbConst {
107105
public static final String MISSING_REQUIRED_VALUE = "Missing required value for parameter: ";
108106
public static final String INVALID_PARAMETER_TYPE = "Cannot cast parameter [%s] from [%s] to [%s]";
109107

110-
// Transaction levels
111-
// See details in https://cloud.yandex.ru/docs/ydb/concepts/transactions
112-
113-
// Please note:
114-
// Serializable transaction (RW) always uses "for-share" row-level locks before filter stage!
108+
// Custom transaction levels
109+
// See details in https://ydb.tech/docs/en/concepts/transactions#modes
115110

116-
/**
117-
* All transactions are serialized one-by-one. If the DB detects a write collision among
118-
* several concurrent transactions, only the first one is committed.
119-
* This is the strongest level. And the only level at which data changes are possible.
120-
*/
121-
public static final int TRANSACTION_SERIALIZABLE_READ_WRITE = Connection.TRANSACTION_SERIALIZABLE;
122111
/**
123112
* The most recent consistent state of the database. Read only.
124113
*/
125-
public static final int ONLINE_CONSISTENT_READ_ONLY = Connection.TRANSACTION_REPEATABLE_READ;
114+
public static final int ONLINE_CONSISTENT_READ_ONLY = 16;
126115
/**
127116
* The most recent inconsistent state of the database. Read only.
128117
* A phantom read may occurs when, in the course of a transaction, some new rows are added
129118
* by another transaction to the records being read. This is the weakest level.
130119
*/
131-
public static final int ONLINE_INCONSISTENT_READ_ONLY = Connection.TRANSACTION_READ_COMMITTED;
120+
public static final int ONLINE_INCONSISTENT_READ_ONLY = ONLINE_CONSISTENT_READ_ONLY + 1;
121+
132122
/**
133123
* An <em>almost</em> recent consistent state of the database. Read only.
134124
* This level is faster then {@code ONLINE_CONSISTENT_READ_ONLY}, but may return stale data.
135125
*/
136-
public static final int STALE_CONSISTENT_READ_ONLY = 3; // TODO: verify if we can do that
126+
public static final int STALE_CONSISTENT_READ_ONLY = 32;
137127

138128
// Processing queries
139129
public static final String EXPLAIN_COLUMN_AST = "AST";

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

Lines changed: 79 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.ydb.jdbc.context;
22

3+
import java.sql.Connection;
34
import java.sql.SQLException;
45
import java.sql.SQLFeatureNotSupportedException;
56

@@ -12,68 +13,90 @@
1213
* @author Aleksandr Gorshenin
1314
*/
1415
public class YdbTxState {
16+
private final int transactionLevel;
17+
private final boolean isReadOnly;
18+
private final boolean isAutoCommit;
19+
1520
private final TxControl<?> txControl;
16-
protected final int transactionLevel;
1721

18-
protected YdbTxState(TxControl<?> tx, int level) {
19-
this.txControl = tx;
22+
protected YdbTxState(TxControl<?> txControl, int level, boolean isReadOnly, boolean isAutoCommit) {
2023
this.transactionLevel = level;
24+
this.isReadOnly = isReadOnly;
25+
this.isAutoCommit = isAutoCommit;
26+
this.txControl = txControl;
27+
}
28+
29+
protected YdbTxState(TxControl<?> txControl, YdbTxState other) {
30+
this.transactionLevel = other.transactionLevel;
31+
this.isReadOnly = other.isReadOnly;
32+
this.isAutoCommit = other.isAutoCommit;
33+
this.txControl = txControl;
2134
}
2235

2336
@Override
2437
public String toString() {
25-
return "NoTx" + transactionLevel;
38+
return "NoTx";
2639
}
2740

2841
public String txID() {
2942
return null;
3043
}
3144

45+
public boolean isInsideTransaction() {
46+
return false;
47+
}
48+
3249
public TxControl<?> txControl() {
3350
return txControl;
3451
}
3552

3653
public boolean isAutoCommit() {
37-
return txControl.isCommitTx();
54+
return isAutoCommit;
3855
}
3956

4057
public boolean isReadOnly() {
41-
return transactionLevel != YdbConst.TRANSACTION_SERIALIZABLE_READ_WRITE;
58+
return isReadOnly;
4259
}
4360

44-
public boolean isInsideTransaction() {
45-
return false;
46-
}
47-
48-
public int transactionLevel() throws SQLException {
61+
public int transactionLevel() {
4962
return transactionLevel;
5063
}
5164

5265
public YdbTxState withAutoCommit(boolean newAutoCommit) throws SQLException {
53-
if (newAutoCommit == isAutoCommit()) {
66+
if (newAutoCommit == isAutoCommit) {
5467
return this;
5568
}
56-
return create(transactionLevel(), newAutoCommit);
69+
70+
if (isInsideTransaction()) {
71+
throw new SQLFeatureNotSupportedException(YdbConst.CHANGE_ISOLATION_INSIDE_TX);
72+
}
73+
74+
return emptyTx(transactionLevel, isReadOnly, newAutoCommit);
5775
}
5876

59-
public YdbTxState withReadOnly(boolean readOnly) throws SQLException {
60-
if (readOnly == isReadOnly()) {
77+
public YdbTxState withReadOnly(boolean newReadOnly) throws SQLException {
78+
if (newReadOnly == isReadOnly()) {
6179
return this;
6280
}
6381

64-
if (readOnly) {
65-
return create(YdbConst.ONLINE_CONSISTENT_READ_ONLY, isAutoCommit());
66-
} else {
67-
return create(YdbConst.TRANSACTION_SERIALIZABLE_READ_WRITE, isAutoCommit());
82+
if (isInsideTransaction()) {
83+
throw new SQLFeatureNotSupportedException(YdbConst.READONLY_INSIDE_TRANSACTION);
6884
}
85+
86+
return emptyTx(transactionLevel, newReadOnly, isAutoCommit);
6987
}
7088

7189
public YdbTxState withTransactionLevel(int newTransactionLevel) throws SQLException {
72-
if (newTransactionLevel == transactionLevel()) {
90+
if (newTransactionLevel == transactionLevel) {
7391
return this;
7492
}
7593

76-
return create(newTransactionLevel, isAutoCommit());
94+
if (isInsideTransaction()) {
95+
throw new SQLFeatureNotSupportedException(YdbConst.CHANGE_ISOLATION_INSIDE_TX);
96+
}
97+
98+
boolean newReadOnly = isReadOnly || newTransactionLevel != Connection.TRANSACTION_SERIALIZABLE;
99+
return emptyTx(newTransactionLevel, newReadOnly, isAutoCommit);
77100
}
78101

79102
public YdbTxState withCommit(Session session) {
@@ -93,7 +116,7 @@ public YdbTxState withKeepAlive(Session session) {
93116

94117
public YdbTxState withDataQuery(Session session, String txID) {
95118
if (txID != null && !txID.isEmpty()) {
96-
return new TransactionInProgress(txID, session, isAutoCommit());
119+
return new TransactionInProgress(txID, session, this);
97120
}
98121

99122
session.close();
@@ -104,88 +127,59 @@ public Session getSession(YdbContext ctx, YdbExecutor executor) throws SQLExcept
104127
return executor.createSession(ctx);
105128
}
106129

107-
public static YdbTxState create(int level, boolean autoCommit) throws SQLException {
108-
return create(null, null, level, autoCommit);
109-
}
130+
private static TxControl<?> txControl(int level, boolean isReadOnly, boolean isAutoCommit) throws SQLException {
131+
if (!isReadOnly) {
132+
// YDB support only one RW mode
133+
if (level != Connection.TRANSACTION_SERIALIZABLE) {
134+
throw new SQLException(YdbConst.UNSUPPORTED_TRANSACTION_LEVEL + level);
135+
}
136+
137+
return TxControl.serializableRw().setCommitTx(isAutoCommit);
138+
}
110139

111-
private static YdbTxState create(Session session, String txId, int level, boolean autoCommit)
112-
throws SQLException {
113140
switch (level) {
114-
case YdbConst.TRANSACTION_SERIALIZABLE_READ_WRITE:
115-
if (txId != null) {
116-
return new TransactionInProgress(txId, session, autoCommit);
117-
} else {
118-
if (autoCommit) {
119-
return new YdbTxState(TxControl.serializableRw(), level);
120-
} else {
121-
return new EmptyTransaction();
122-
}
123-
}
141+
case Connection.TRANSACTION_SERIALIZABLE:
142+
return TxControl.snapshotRo().setCommitTx(isAutoCommit);
124143
case YdbConst.ONLINE_CONSISTENT_READ_ONLY:
125-
return new YdbTxState(TxControl.onlineRo(), level);
126-
case YdbConst.STALE_CONSISTENT_READ_ONLY:
127-
return new YdbTxState(TxControl.staleRo(), level);
144+
return TxControl.onlineRo().setAllowInconsistentReads(false).setCommitTx(isAutoCommit);
128145
case YdbConst.ONLINE_INCONSISTENT_READ_ONLY:
129-
return new YdbTxState(TxControl.onlineRo().setAllowInconsistentReads(true), level);
146+
return TxControl.onlineRo().setAllowInconsistentReads(true).setCommitTx(isAutoCommit);
147+
case YdbConst.STALE_CONSISTENT_READ_ONLY:
148+
return TxControl.staleRo().setCommitTx(isAutoCommit);
130149
default:
131150
throw new SQLException(YdbConst.UNSUPPORTED_TRANSACTION_LEVEL + level);
132151
}
133152
}
134153

135-
private static class EmptyTransaction extends YdbTxState {
136-
EmptyTransaction() {
137-
super(TxControl.serializableRw().setCommitTx(false), YdbConst.TRANSACTION_SERIALIZABLE_READ_WRITE);
138-
}
139-
140-
@Override
141-
public String toString() {
142-
return "EmptyTx" + transactionLevel;
143-
}
144-
145-
@Override
146-
public YdbTxState withDataQuery(Session session, String txID) {
147-
if (txID != null && !txID.isEmpty()) {
148-
return new TransactionInProgress(txID, session, isAutoCommit());
149-
}
154+
private static YdbTxState emptyTx(int level, boolean isReadOnly, boolean isAutoCommit) throws SQLException {
155+
TxControl<?> tx = txControl(level, isReadOnly, isAutoCommit);
156+
return new YdbTxState(tx, level, isReadOnly, isAutoCommit);
157+
}
150158

151-
session.close();
152-
return this;
153-
}
159+
public static YdbTxState create(int level, boolean isAutoCommit) throws SQLException {
160+
return emptyTx(level, level != Connection.TRANSACTION_SERIALIZABLE, isAutoCommit);
154161
}
155162

156163
private static class TransactionInProgress extends YdbTxState {
157-
private final String id;
164+
private final String txID;
158165
private final Session session;
166+
private final YdbTxState previos;
159167

160-
TransactionInProgress(String id, Session session, boolean autoCommit) {
161-
super(TxControl.id(id).setCommitTx(autoCommit), YdbConst.TRANSACTION_SERIALIZABLE_READ_WRITE);
162-
this.id = id;
168+
TransactionInProgress(String id, Session session, YdbTxState previosState) {
169+
super(TxControl.id(id).setCommitTx(previosState.isAutoCommit), previosState);
170+
this.txID = id;
163171
this.session = session;
172+
this.previos = previosState;
164173
}
165174

166175
@Override
167176
public String toString() {
168-
return "InTx" + transactionLevel + "[" + id + "]";
177+
return "InTx" + transactionLevel() + "[" + txID + "]";
169178
}
170179

171180
@Override
172181
public String txID() {
173-
return id;
174-
}
175-
176-
@Override
177-
public YdbTxState withAutoCommit(boolean newAutoCommit) throws SQLException {
178-
throw new SQLFeatureNotSupportedException(YdbConst.CHANGE_ISOLATION_INSIDE_TX);
179-
}
180-
181-
@Override
182-
public YdbTxState withTransactionLevel(int newTransactionLevel) throws SQLException {
183-
throw new SQLFeatureNotSupportedException(YdbConst.CHANGE_ISOLATION_INSIDE_TX);
184-
}
185-
186-
@Override
187-
public YdbTxState withReadOnly(boolean readOnly) throws SQLException {
188-
throw new SQLFeatureNotSupportedException(YdbConst.READONLY_INSIDE_TRANSACTION);
182+
return txID;
189183
}
190184

191185
@Override
@@ -201,13 +195,13 @@ public Session getSession(YdbContext ctx, YdbExecutor executor) throws SQLExcept
201195
@Override
202196
public YdbTxState withCommit(Session session) {
203197
session.close();
204-
return new EmptyTransaction();
198+
return previos;
205199
}
206200

207201
@Override
208202
public YdbTxState withRollback(Session session) {
209203
session.close();
210-
return new EmptyTransaction();
204+
return previos;
211205
}
212206

213207
@Override
@@ -222,15 +216,15 @@ public YdbTxState withDataQuery(Session session, String txID) {
222216
session.close();
223217
}
224218
this.session.close();
225-
return new EmptyTransaction();
219+
return previos;
226220
}
227221

228-
if (this.id.equals(txID)) {
222+
if (txID.equals(txID())) {
229223
if (this.session == session) {
230224
return this;
231225
}
232226
this.session.close();
233-
return new TransactionInProgress(txID, session, isAutoCommit());
227+
return new TransactionInProgress(txID, session, previos);
234228
}
235229

236230
session.close();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package tech.ydb.jdbc.impl;
22

3+
import java.sql.Connection;
34
import java.sql.ResultSet;
45
import java.sql.RowIdLifetime;
56
import java.sql.SQLException;
@@ -616,7 +617,7 @@ public int getMaxUserNameLength() {
616617

617618
@Override
618619
public int getDefaultTransactionIsolation() {
619-
return YdbConst.TRANSACTION_SERIALIZABLE_READ_WRITE;
620+
return Connection.TRANSACTION_SERIALIZABLE;
620621
}
621622

622623
@Override
@@ -627,7 +628,7 @@ public boolean supportsTransactions() {
627628
@Override
628629
public boolean supportsTransactionIsolationLevel(int level) {
629630
switch (level) {
630-
case YdbConst.TRANSACTION_SERIALIZABLE_READ_WRITE:
631+
case Connection.TRANSACTION_SERIALIZABLE:
631632
case YdbConst.ONLINE_CONSISTENT_READ_ONLY:
632633
case YdbConst.ONLINE_INCONSISTENT_READ_ONLY:
633634
case YdbConst.STALE_CONSISTENT_READ_ONLY:

0 commit comments

Comments
 (0)