Skip to content

Commit 27c637b

Browse files
feat: Decimal (22, 9), (35, 0), (31, 9), (35, 9)
1 parent d97c393 commit 27c637b

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.hibernate.type.descriptor.sql.internal.DdlTypeImpl;
5858
import org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry;
5959
import tech.ydb.hibernate.dialect.code.YdbJdbcCode;
60+
import static tech.ydb.hibernate.dialect.code.YdbJdbcCode.DECIMAL_SHIFT;
6061
import tech.ydb.hibernate.dialect.exporter.EmptyExporter;
6162
import tech.ydb.hibernate.dialect.exporter.YdbIndexExporter;
6263
import tech.ydb.hibernate.dialect.hint.IndexQueryHintHandler;
@@ -71,10 +72,8 @@
7172
import tech.ydb.hibernate.dialect.types.LocalDateJdbcType;
7273
import tech.ydb.hibernate.dialect.types.LocalDateTimeJavaType;
7374
import tech.ydb.hibernate.dialect.types.LocalDateTimeJdbcType;
74-
import tech.ydb.hibernate.dialect.types.Uint8JdbcType;
75-
76-
import static tech.ydb.hibernate.dialect.code.YdbJdbcCode.DECIMAL_SHIFT;
7775
import static tech.ydb.hibernate.dialect.types.LocalDateTimeJdbcType.JDBC_TYPE_DATETIME_CODE;
76+
import tech.ydb.hibernate.dialect.types.Uint8JdbcType;
7877

7978
/**
8079
* @author Kirill Kurdyukov

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ public final class YdbJdbcCode {
127127

128128
public static final int DECIMAL_SHIFT = (1 << 14);
129129

130+
/**
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>
132+
*/
130133
public static final int DECIMAL_22_9 = DECIMAL_SHIFT + (22 << 6) + 9;
131134

132135
public static final int DECIMAL_31_9 = DECIMAL_SHIFT + (31 << 6) + 9;

hibernate-dialect/src/test/java/tech/ydb/hibernate/ydb_jdbc_code/TestEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@Data
1919
@AllArgsConstructor
2020
@NoArgsConstructor
21-
@Table(name = "hibernate_test")
21+
@Table(name = "hibernate_test_bigdecimal")
2222
public class TestEntity {
2323

2424
@Id

hibernate-dialect/src/test/java/tech/ydb/hibernate/ydb_jdbc_code/YdbJdbcCodeTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.math.BigDecimal;
44
import org.hibernate.cfg.AvailableSettings;
5+
import org.hibernate.exception.GenericJDBCException;
56
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertThrows;
68
import org.junit.jupiter.api.Test;
79
import org.junit.jupiter.api.extension.RegisterExtension;
810
import static tech.ydb.hibernate.TestUtils.SESSION_FACTORY;
@@ -46,5 +48,18 @@ primary key (id)
4648

4749
inTransaction(session -> session.persist(testEntity));
4850
inTransaction(session -> assertEquals(testEntity, session.find(TestEntity.class, 1)));
51+
52+
testEntity.setBigDecimal35_0(new BigDecimal(123));
53+
54+
inTransaction(session -> session.merge(testEntity));
55+
inTransaction(session -> assertEquals(testEntity, session.find(TestEntity.class, 1)));
56+
57+
testEntity.setBigDecimal31_9(new BigDecimal("123123456781231234567812312345678123123456781231234567812312345678123123456781231234567812312345678123"));
58+
59+
assertThrows(GenericJDBCException.class, () -> inTransaction(session -> session.merge(testEntity)), "Unable to bind parameter #1 - 123123456781231234567812312345678123123456781231234567812312345678123123456781231234567812312345678123 [Cannot cast to decimal type Decimal(31, 9): [class java.math.BigDecimal: 123123456781231234567812312345678123123456781231234567812312345678123123456781231234567812312345678123] is Infinite] [n/a]");
60+
61+
testEntity.setBigDecimal31_9(new BigDecimal("123451234512345123451234512345123"));
62+
63+
assertThrows(GenericJDBCException.class, () -> inTransaction(session -> session.merge(testEntity)), "Unable to bind parameter #1 - 123451234512345123451234512345123 [Cannot cast to decimal type Decimal(31, 9): [class java.math.BigDecimal: 123123456781231234567812312345678123123456781231234567812312345678123123456781231234567812312345678123] is Infinite] [n/a]");
4964
}
5065
}

0 commit comments

Comments
 (0)