Skip to content

Commit 415acf1

Browse files
Merge remote-tracking branch 'origin/main'
2 parents 320ed34 + 327ca08 commit 415acf1

File tree

12 files changed

+152
-58
lines changed

12 files changed

+152
-58
lines changed

hibernate-dialect/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.5.0 ##
2+
3+
- Support for `GenerationType.IDENTITY` with JDBC YDB Driver **2.3.11** and later.
4+
- Support for `Date32`, `Datetime64`, and `Timestamp64` YDB types.
5+
16
## 1.4.1 ##
27

38
- Deleted `InExpressionCountLimit`

hibernate-dialect/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<log4j2.version>2.17.2</log4j2.version>
4343

4444
<ydb.sdk.version>2.3.13</ydb.sdk.version>
45-
<ydb.jdbc.version>2.3.10</ydb.jdbc.version>
45+
<ydb.jdbc.version>2.3.11</ydb.jdbc.version>
4646
</properties>
4747

4848
<licenses>
@@ -145,7 +145,7 @@
145145
<configuration>
146146
<environmentVariables>
147147
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
148-
<YDB_DOCKER_FEATURE_FLAGS>enable_parameterized_decimal</YDB_DOCKER_FEATURE_FLAGS>
148+
<YDB_DOCKER_IMAGE>ydbplatform/local-ydb:trunk</YDB_DOCKER_IMAGE>
149149
</environmentVariables>
150150
</configuration>
151151
</plugin>

hibernate-dialect/src/main/java/tech/ydb/hibernate/dialect/YdbDialect.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package tech.ydb.hibernate.dialect;
22

3+
import java.time.Duration;
4+
import java.time.Instant;
5+
import java.time.LocalDate;
36
import java.time.LocalDateTime;
47
import java.util.List;
58
import java.util.concurrent.ConcurrentHashMap;
@@ -32,6 +35,7 @@
3235
import static org.hibernate.type.SqlTypes.DOUBLE;
3336
import static org.hibernate.type.SqlTypes.FLOAT;
3437
import static org.hibernate.type.SqlTypes.INTEGER;
38+
import static org.hibernate.type.SqlTypes.INTERVAL_SECOND;
3539
import static org.hibernate.type.SqlTypes.JSON;
3640
import static org.hibernate.type.SqlTypes.LONG32NVARCHAR;
3741
import static org.hibernate.type.SqlTypes.LONG32VARBINARY;
@@ -61,7 +65,6 @@
6165
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
6266
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
6367
import tech.ydb.hibernate.dialect.code.YdbJdbcCode;
64-
import static tech.ydb.hibernate.dialect.code.YdbJdbcCode.DECIMAL_SHIFT;
6568
import tech.ydb.hibernate.dialect.exporter.EmptyExporter;
6669
import tech.ydb.hibernate.dialect.exporter.YdbIndexExporter;
6770
import tech.ydb.hibernate.dialect.hint.IndexQueryHintHandler;
@@ -78,8 +81,7 @@
7881
import tech.ydb.hibernate.dialect.types.LocalDateJdbcType;
7982
import tech.ydb.hibernate.dialect.types.LocalDateTimeJavaType;
8083
import tech.ydb.hibernate.dialect.types.LocalDateTimeJdbcType;
81-
import static tech.ydb.hibernate.dialect.types.LocalDateTimeJdbcType.JDBC_TYPE_DATETIME_CODE;
82-
import tech.ydb.hibernate.dialect.types.Uint8JdbcType;
84+
import tech.ydb.hibernate.dialect.types.YdbJdbcType;
8385

8486
/**
8587
* @author Kirill Kurdyukov
@@ -110,7 +112,7 @@ protected String columnType(int sqlTypeCode) {
110112
case DOUBLE -> "Double";
111113
case NUMERIC, DECIMAL -> "Decimal($p, $s)";
112114
case DATE -> "Date";
113-
case JDBC_TYPE_DATETIME_CODE -> "Datetime";
115+
case INTERVAL_SECOND -> "Interval";
114116
case TIME_WITH_TIMEZONE -> "TzDateTime";
115117
case TIMESTAMP, TIMESTAMP_UTC -> "Timestamp";
116118
case TIMESTAMP_WITH_TIMEZONE -> "TzTimestamp";
@@ -137,7 +139,12 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
137139
typeContributions.contributeJdbcType(InstantJdbcType.INSTANCE);
138140

139141
// custom jdbc codec
140-
typeContributions.contributeJdbcType(Uint8JdbcType.INSTANCE);
142+
typeContributions.contributeJdbcType(new YdbJdbcType(YdbJdbcCode.UINT8, Integer.class));
143+
typeContributions.contributeJdbcType(new YdbJdbcType(YdbJdbcCode.DATE_32, LocalDate.class));
144+
typeContributions.contributeJdbcType(new YdbJdbcType(YdbJdbcCode.DATETIME_64, LocalDateTime.class));
145+
typeContributions.contributeJdbcType(new YdbJdbcType(YdbJdbcCode.TIMESTAMP_64, Instant.class));
146+
typeContributions.contributeJdbcType(new YdbJdbcType(YdbJdbcCode.INTERVAL_64, Duration.class));
147+
141148
typeContributions.contributeJavaType(BigDecimalJavaType.INSTANCE_22_9);
142149
typeContributions.contributeJdbcType(new DecimalJdbcType(YdbJdbcCode.DECIMAL_22_9));
143150
typeContributions.contributeJdbcType(new DecimalJdbcType(YdbJdbcCode.DECIMAL_31_9));
@@ -152,8 +159,14 @@ protected void registerColumnTypes(TypeContributions typeContributions, ServiceR
152159
final DdlTypeRegistry ddlTypeRegistry = typeContributions.getTypeConfiguration().getDdlTypeRegistry();
153160

154161
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(UUID, "Uuid", "Uuid", this));
162+
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(INTERVAL_SECOND, "Interval", "Interval", this));
163+
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.INTERVAL, "Interval", "Interval", this));
155164
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.DATETIME, "Datetime", "Datetime", this));
156165
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.UINT8, "Uint8", "Uint8", this));
166+
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.DATE_32, "Date32", "Date32", this));
167+
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.DATETIME_64, "Datetime64", "Datetime64", this));
168+
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.TIMESTAMP_64, "Timestamp64", "Timestamp64", this));
169+
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.INTERVAL_64, "Interval64", "Interval64", this));
157170
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.DECIMAL_22_9, "Decimal(22, 9)", "Decimal(22, 9)", this));
158171
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.DECIMAL_31_9, "Decimal(31, 9)", "Decimal(31, 9)", this));
159172
ddlTypeRegistry.addDescriptor(new DdlTypeImpl(YdbJdbcCode.DECIMAL_35_0, "Decimal(35, 0)", "Decimal(35, 0)", this));
@@ -168,7 +181,7 @@ public JdbcType resolveSqlTypeDescriptor(
168181
int scale,
169182
JdbcTypeRegistry jdbcTypeRegistry) {
170183
if ((jdbcTypeCode == NUMERIC || jdbcTypeCode == DECIMAL) && (precision != 0 || scale != 0)) {
171-
int sqlCode = DECIMAL_SHIFT + (precision << 6) + scale;
184+
int sqlCode = ydbDecimal(precision, scale);
172185

173186
return DECIMAL_JDBC_TYPE_CACHE.computeIfAbsent(sqlCode, DecimalJdbcType::new);
174187
}
@@ -385,4 +398,8 @@ public boolean supportsInsertReturning() {
385398
public boolean supportsInsertReturningGeneratedKeys() {
386399
return true;
387400
}
401+
402+
private static int ydbDecimal(int precision, int scale) {
403+
return 1 << 14 + (precision << 6) + (scale & 0x111111);
404+
}
388405
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package tech.ydb.hibernate.dialect.code;
2+
3+
/**
4+
* That class contain custom YDB type codes
5+
* @see <a href="https://github.com/ydb-platform/ydb-jdbc-driver/blob/3d74021/jdbc/src/main/java/tech/ydb/jdbc/YdbConst.java#L8-L9">JDBC Driver constants</a>
6+
* @see <a href="https://github.com/ydb-platform/ydb-jdbc-driver/blob/3d74021/jdbc/src/main/java/tech/ydb/jdbc/impl/YdbTypes.java#L37-L66">Primitive types</a>
7+
* @see <a href="https://github.com/ydb-platform/ydb-jdbc-driver/blob/3d74021/jdbc/src/main/java/tech/ydb/jdbc/impl/YdbTypes.java#L138-L144">Decimal type</a>
8+
*
9+
* @author Kirill Kurdyukov
10+
*/
11+
final class YdbConst {
12+
public static final int SQL_KIND_PRIMITIVE = 10000;
13+
public static final int SQL_KIND_DECIMAL = 1 << 14; // 16384
14+
15+
private YdbConst() { };
16+
}

hibernate-dialect/src/main/java/tech/ydb/hibernate/dialect/code/YdbJdbcCode.java

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,133 +8,142 @@ public final class YdbJdbcCode {
88
/**
99
* Boolean value.
1010
*/
11-
public static final int BOOL = 10000;
11+
public static final int BOOL = YdbConst.SQL_KIND_PRIMITIVE;
1212

1313
/**
1414
* A signed integer. Acceptable values: from -2^7 to 2^7–1. Not supported for table columns
1515
*/
16-
public static final int INT8 = 10001;
16+
public static final int INT8 = YdbConst.SQL_KIND_PRIMITIVE + 1;
1717

1818
/**
1919
* An unsigned integer. Acceptable values: from 0 to 2^8–1.
2020
*/
21-
public static final int UINT8 = 10002;
21+
public static final int UINT8 = YdbConst.SQL_KIND_PRIMITIVE + 2;
2222

2323
/**
2424
* A signed integer. Acceptable values: from –2^15 to 2^15–1. Not supported for table columns
2525
*/
26-
public static final int INT16 = 10003;
26+
public static final int INT16 = YdbConst.SQL_KIND_PRIMITIVE + 3;
2727

2828
/**
2929
* An unsigned integer. Acceptable values: from 0 to 2^16–1. Not supported for table columns
3030
*/
31-
public static final int UINT16 = 10004;
31+
public static final int UINT16 = YdbConst.SQL_KIND_PRIMITIVE + 4;
3232

3333
/**
3434
* A signed integer. Acceptable values: from –2^31 to 2^31–1.
3535
*/
36-
public static final int INT32 = 10005;
36+
public static final int INT32 = YdbConst.SQL_KIND_PRIMITIVE + 5;
3737

3838
/**
3939
* An unsigned integer. Acceptable values: from 0 to 2^32–1.
4040
*/
41-
public static final int UINT32 = 10006;
41+
public static final int UINT32 = YdbConst.SQL_KIND_PRIMITIVE + 6;
4242

4343
/**
4444
* A signed integer. Acceptable values: from –2^63 to 2^63–1.
4545
*/
46-
public static final int INT64 = 10007;
46+
public static final int INT64 = YdbConst.SQL_KIND_PRIMITIVE + 7;
4747

4848
/**
4949
* An unsigned integer. Acceptable values: from 0 to 2^64–1.
5050
*/
51-
public static final int UINT64 = 10008;
51+
public static final int UINT64 = YdbConst.SQL_KIND_PRIMITIVE + 8;
5252

5353
/**
5454
* A real number with variable precision, 4 bytes in size. Can't be used in the primary key
5555
*/
56-
public static final int FLOAT = 10009;
56+
public static final int FLOAT = YdbConst.SQL_KIND_PRIMITIVE + 9;
5757

5858
/**
5959
* A real number with variable precision, 8 bytes in size. Can't be used in the primary key
6060
*/
61-
public static final int DOUBLE = 10010;
61+
public static final int DOUBLE = YdbConst.SQL_KIND_PRIMITIVE + 10;
6262

6363
/**
6464
* A binary data, synonym for YDB type String
6565
*/
66-
public static final int BYTES = 10011;
66+
public static final int BYTES = YdbConst.SQL_KIND_PRIMITIVE + 11;
6767

6868
/**
6969
* Text encoded in UTF-8, synonym for YDB type Utf8
7070
*/
71-
public static final int TEXT = 10012;
71+
public static final int TEXT = YdbConst.SQL_KIND_PRIMITIVE + 12;
7272

7373
/**
7474
* YSON in a textual or binary representation. Doesn't support matching, can't be used in the primary key
7575
*/
76-
public static final int YSON = 10013;
76+
public static final int YSON = YdbConst.SQL_KIND_PRIMITIVE + 13;
7777

7878
/**
7979
* JSON represented as text. Doesn't support matching, can't be used in the primary key
8080
*/
81-
public static final int JSON = 10014;
81+
public static final int JSON = YdbConst.SQL_KIND_PRIMITIVE + 14;
8282

8383
/**
8484
* Universally unique identifier UUID. Not supported for table columns
8585
*/
86-
public static final int UUID = 10015;
86+
public static final int UUID = YdbConst.SQL_KIND_PRIMITIVE + 15;
8787

8888
/**
8989
* Date, precision to the day
9090
*/
91-
public static final int DATE = 10016;
91+
public static final int DATE = YdbConst.SQL_KIND_PRIMITIVE + 16;
9292

9393
/**
9494
* Date/time, precision to the second
9595
*/
96-
public static final int DATETIME = 10017;
96+
public static final int DATETIME = YdbConst.SQL_KIND_PRIMITIVE + 17;
9797

9898
/**
9999
* Date/time, precision to the microsecond
100100
*/
101-
public static final int TIMESTAMP = 10018;
101+
public static final int TIMESTAMP = YdbConst.SQL_KIND_PRIMITIVE + 18;
102102

103103
/**
104104
* Time interval (signed), precision to microseconds
105105
*/
106-
public static final int INTERVAL = 10019;
106+
public static final int INTERVAL = YdbConst.SQL_KIND_PRIMITIVE + 19;
107107

108108
/**
109109
* Date with time zone label, precision to the day
110110
*/
111-
public static final int TZ_DATE = 10020;
111+
public static final int TZ_DATE = YdbConst.SQL_KIND_PRIMITIVE + 20;
112112

113113
/**
114114
* Date/time with time zone label, precision to the second
115115
*/
116-
public static final int TZ_DATETIME = 10021;
116+
public static final int TZ_DATETIME = YdbConst.SQL_KIND_PRIMITIVE + 21;
117117

118118
/**
119119
* Date/time with time zone label, precision to the microsecond
120120
*/
121-
public static final int TZ_TIMESTAMP = 10022;
121+
public static final int TZ_TIMESTAMP = YdbConst.SQL_KIND_PRIMITIVE + 22;
122122

123123
/**
124124
* JSON in an indexed binary representation. Doesn't support matching, can't be used in the primary key
125125
*/
126-
public static final int JSON_DOCUMENT = 10023;
126+
public static final int JSON_DOCUMENT = YdbConst.SQL_KIND_PRIMITIVE + 23;
127127

128-
public static final int DECIMAL_SHIFT = (1 << 14);
128+
public static final int DATE_32 = YdbConst.SQL_KIND_PRIMITIVE + 25;
129+
130+
public static final int DATETIME_64 = YdbConst.SQL_KIND_PRIMITIVE + 26;
131+
132+
public static final int TIMESTAMP_64 = YdbConst.SQL_KIND_PRIMITIVE + 27;
133+
134+
public static final int INTERVAL_64 = YdbConst.SQL_KIND_PRIMITIVE + 28;
135+
136+
137+
// WARN! Attribute value must be constant!
129138

130139
/**
131-
* <a href="https://github.com/ydb-platform/ydb-jdbc-driver/blob/v2.3.3/jdbc/src/main/java/tech/ydb/jdbc/impl/YdbTypes.java#L37-L66">link</a>
140+
* <a href="https://github.com/ydb-platform/ydb-jdbc-driver/blob/v2.3.3/jdbc/src/main/java/tech/ydb/jdbc/impl/YdbTypes.java#L37-L66">link</a>
132141
*/
133-
public static final int DECIMAL_22_9 = DECIMAL_SHIFT + (22 << 6) + 9;
142+
public static final int DECIMAL_22_9 = YdbConst.SQL_KIND_DECIMAL + (22 << 6) + 9;
134143

135-
public static final int DECIMAL_31_9 = DECIMAL_SHIFT + (31 << 6) + 9;
144+
public static final int DECIMAL_31_9 = YdbConst.SQL_KIND_DECIMAL + (31 << 6) + 9;
136145

137-
public static final int DECIMAL_35_0 = DECIMAL_SHIFT + (35 << 6);
146+
public static final int DECIMAL_35_0 = YdbConst.SQL_KIND_DECIMAL + (35 << 6);
138147

139-
public static final int DECIMAL_35_9 = DECIMAL_SHIFT + (35 << 6) + 9;
148+
public static final int DECIMAL_35_9 = YdbConst.SQL_KIND_DECIMAL + (35 << 6) + 9;
140149
}

hibernate-dialect/src/main/java/tech/ydb/hibernate/dialect/types/LocalDateTimeJdbcType.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
import org.hibernate.type.descriptor.jdbc.BasicBinder;
1313
import org.hibernate.type.descriptor.jdbc.TimestampJdbcType;
1414
import org.hibernate.type.spi.TypeConfiguration;
15+
import tech.ydb.hibernate.dialect.code.YdbJdbcCode;
1516

1617
/**
1718
* @author Kirill Kurdyukov
1819
*/
1920
public class LocalDateTimeJdbcType extends TimestampJdbcType {
20-
public static final int JDBC_TYPE_DATETIME_CODE = 10017;
21+
2122
public static final LocalDateTimeJdbcType INSTANCE = new LocalDateTimeJdbcType();
2223

2324
@Override
@@ -27,12 +28,12 @@ public String toString() {
2728

2829
@Override
2930
public int getJdbcTypeCode() {
30-
return JDBC_TYPE_DATETIME_CODE;
31+
return YdbJdbcCode.DATETIME;
3132
}
3233

3334
@Override
3435
public String getFriendlyName() {
35-
return "DATETIME";
36+
return "Datetime";
3637
}
3738

3839
@Override
@@ -53,14 +54,14 @@ public <X> ValueBinder<X> getBinder(final JavaType<X> javaType) {
5354
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
5455
final LocalDateTime localDateTime = javaType.unwrap(value, LocalDateTime.class, options);
5556

56-
st.setObject(index, localDateTime, JDBC_TYPE_DATETIME_CODE);
57+
st.setObject(index, localDateTime, YdbJdbcCode.DATETIME);
5758
}
5859

5960
@Override
6061
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
6162
final LocalDateTime localDateTime = javaType.unwrap(value, LocalDateTime.class, options);
6263

63-
st.setObject(name, localDateTime, JDBC_TYPE_DATETIME_CODE);
64+
st.setObject(name, localDateTime, YdbJdbcCode.DATETIME);
6465
}
6566
};
6667
}

0 commit comments

Comments
 (0)