diff --git a/bom/pom.xml b/bom/pom.xml index 882a13c3..45547bd7 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -6,7 +6,7 @@ tech.ydb.yoj yoj-bom - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT pom YOJ - Bill of Materials diff --git a/databind/pom.xml b/databind/pom.xml index a53ccccd..8077db47 100644 --- a/databind/pom.xml +++ b/databind/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/repository-ydb-common/src/main/java/tech/ydb/yoj/repository/ydb/DbType.java b/databind/src/main/java/tech/ydb/yoj/databind/DbType.java similarity index 62% rename from repository-ydb-common/src/main/java/tech/ydb/yoj/repository/ydb/DbType.java rename to databind/src/main/java/tech/ydb/yoj/databind/DbType.java index 9036bcde..b3634d40 100644 --- a/repository-ydb-common/src/main/java/tech/ydb/yoj/repository/ydb/DbType.java +++ b/databind/src/main/java/tech/ydb/yoj/databind/DbType.java @@ -1,87 +1,98 @@ -package tech.ydb.yoj.repository.ydb; +package tech.ydb.yoj.databind; /** * Database column types supported by YDB. */ -public interface DbType { +public enum DbType { + DEFAULT(null), /** * Boolean value. */ - String BOOL = "BOOL"; + BOOL("BOOL"), /** * Byte value. */ - String UINT8 = "UINT8"; + UINT8("UINT8"), /** * Integer value. */ - String INT32 = "INT32"; + INT32("INT32"), /** * Integer value stored in the db as Uint32. */ - String UINT32 = "UINT32"; + UINT32("UINT32"), /** * Long value. */ - String INT64 = "INT64"; + INT64("INT64"), /** * Long value stored in the db as Uint64. */ - String UINT64 = "UINT64"; + UINT64("UINT64"), /** * Float value. */ - String FLOAT = "FLOAT"; + FLOAT("FLOAT"), /** * Double value. */ - String DOUBLE = "DOUBLE"; + DOUBLE("DOUBLE"), /** * Date value, accurate to the day. */ - String DATE = "DATE"; + DATE("DATE"), /** * Timestamp value, accurate to second. */ - String DATETIME = "DATETIME"; + DATETIME("DATETIME"), /** * Timestamp value, accurate to microsecond. */ - String TIMESTAMP = "TIMESTAMP"; + TIMESTAMP("TIMESTAMP"), /** * Interval value, accurate to microsecond. */ - String INTERVAL = "INTERVAL"; + INTERVAL("INTERVAL"), /** * Binary data. */ - String STRING = "STRING"; + STRING("STRING"), /** * UTF-8 encoded string. */ - String UTF8 = "UTF8"; + UTF8("UTF8"), /** * JSON value, stored as a UTF-8 encoded string. */ - String JSON = "JSON"; + JSON("JSON"), /** * JSON value, stored in an indexed representation permitting efficient query operations of the values inside the * JSON value itself. */ - String JSON_DOCUMENT = "JSON_DOCUMENT"; + JSON_DOCUMENT("JSON_DOCUMENT"); + + private final String type; + + DbType(String type) { + this.type = type; + } + + public String typeString() { + return type; + } } diff --git a/databind/src/main/java/tech/ydb/yoj/databind/schema/Column.java b/databind/src/main/java/tech/ydb/yoj/databind/schema/Column.java index 4d1b25b4..d9dd6165 100644 --- a/databind/src/main/java/tech/ydb/yoj/databind/schema/Column.java +++ b/databind/src/main/java/tech/ydb/yoj/databind/schema/Column.java @@ -1,5 +1,6 @@ package tech.ydb.yoj.databind.schema; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import java.lang.annotation.Retention; @@ -15,7 +16,7 @@ *

Usage Example: *

  * // DB column will have name 'DESC' and DB-specific type 'UTF8'
- * @Column(name = "DESC", dbType = "UTF8")
+ * @Column(name = "DESC", dbType = DbType.UTF8)
  * String description;
  *
  * // Subobject's serialized representation will be written to a single BIG_SUBOBJ column
@@ -42,7 +43,7 @@
      * The type of the DB column.
* Defaults to automatically inferred from the field type. */ - String dbType() default ""; + DbType dbType() default DbType.DEFAULT; /** * Qualifier for refining type representation of the DB column.
diff --git a/databind/src/main/java/tech/ydb/yoj/databind/schema/Schema.java b/databind/src/main/java/tech/ydb/yoj/databind/schema/Schema.java index 05a5191f..2e496382 100644 --- a/databind/src/main/java/tech/ydb/yoj/databind/schema/Schema.java +++ b/databind/src/main/java/tech/ydb/yoj/databind/schema/Schema.java @@ -8,6 +8,7 @@ import lombok.SneakyThrows; import lombok.Value; import lombok.With; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import tech.ydb.yoj.databind.schema.configuration.SchemaRegistry.SchemaKey; import tech.ydb.yoj.databind.schema.naming.NamingStrategy; @@ -435,12 +436,12 @@ private JavaField(JavaField javaField, JavaField parent) { * @return the DB column type for data binding if specified, {@code null} otherwise * @see Column */ - public String getDbType() { + public DbType getDbType() { Column annotation = field.getColumn(); - if (annotation != null && !annotation.dbType().isEmpty()) { + if (annotation != null) { return annotation.dbType(); } - return null; + return DbType.DEFAULT; } /** diff --git a/databind/src/test/java/tech/ydb/yoj/databind/schema/naming/ColumnTest.java b/databind/src/test/java/tech/ydb/yoj/databind/schema/naming/ColumnTest.java index 02072d3f..227439f0 100644 --- a/databind/src/test/java/tech/ydb/yoj/databind/schema/naming/ColumnTest.java +++ b/databind/src/test/java/tech/ydb/yoj/databind/schema/naming/ColumnTest.java @@ -4,6 +4,7 @@ import lombok.Value; import org.junit.Before; import org.junit.Test; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.ObjectSchema; import tech.ydb.yoj.databind.schema.Schema; @@ -11,8 +12,6 @@ import tech.ydb.yoj.databind.schema.configuration.SchemaRegistry.SchemaKey; import tech.ydb.yoj.databind.schema.reflect.Reflector; -import java.util.Objects; - import static org.assertj.core.api.Assertions.assertThat; public class ColumnTest { @@ -48,7 +47,8 @@ public void plainFieldTypeTest() { Schema schema = newSchema(Plain.class); assertThat(schema.flattenFields().stream() .map(Schema.JavaField::getDbType) - .filter(Objects::nonNull)).isEmpty(); + .filter(dbType -> dbType != DbType.DEFAULT) + ).isEmpty(); } @Test @@ -56,7 +56,8 @@ public void annotatedFieldDbTypeTest() { Schema schema = newSchema(UInt32.class); assertThat(schema.flattenFields().stream() .map(Schema.JavaField::getDbType)) - .containsOnly("UInt32"); + .map(DbType::typeString) + .containsOnly("UINT32"); } @Test @@ -112,7 +113,7 @@ private static class ColumnNameClashes { @Column Id id; - @Column(name = "id", dbType = "UTF8") + @Column(name = "id", dbType = DbType.UTF8) String value; @Value @@ -127,7 +128,7 @@ private static class JavaFieldClashes { @Column Id id; - @Column(name = "value", dbType = "UTF8") + @Column(name = "value", dbType = DbType.UTF8) String value; @Value @@ -171,7 +172,7 @@ private static final class Id { @Value private static final class UInt32 { - @Column(dbType = "UInt32", dbTypeQualifier = "Days") + @Column(dbType = DbType.UINT32, dbTypeQualifier = "Days") int value; } } diff --git a/json-jackson-v2/pom.xml b/json-jackson-v2/pom.xml index 57aa49db..3858567d 100644 --- a/json-jackson-v2/pom.xml +++ b/json-jackson-v2/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index c8bcbead..0768f76a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT pom YDB ORM for Java (YOJ) diff --git a/repository-inmemory/pom.xml b/repository-inmemory/pom.xml index 527412f5..6e01a6f1 100644 --- a/repository-inmemory/pom.xml +++ b/repository-inmemory/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/repository-test/pom.xml b/repository-test/pom.xml index d6f2af52..82be05f1 100644 --- a/repository-test/pom.xml +++ b/repository-test/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/ChangefeedEntity.java b/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/ChangefeedEntity.java index 674d5c1b..8775a00a 100644 --- a/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/ChangefeedEntity.java +++ b/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/ChangefeedEntity.java @@ -1,6 +1,7 @@ package tech.ydb.yoj.repository.test.sample.model; import lombok.Value; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Changefeed; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.repository.db.Entity; @@ -21,7 +22,7 @@ public class ChangefeedEntity implements Entity { Id id; - @Column(dbType = "UTF8") + @Column(dbType = DbType.UTF8) String stringField; @Value diff --git a/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TtlEntity.java b/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TtlEntity.java index 3d56a20e..dff37c6a 100644 --- a/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TtlEntity.java +++ b/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TtlEntity.java @@ -1,6 +1,7 @@ package tech.ydb.yoj.repository.test.sample.model; import lombok.Value; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.TTL; import tech.ydb.yoj.repository.db.Entity; @@ -12,7 +13,7 @@ public class TtlEntity implements Entity { Id id; - @Column(dbType = "TIMESTAMP") + @Column(dbType = DbType.TIMESTAMP) Instant createdAt; @Value diff --git a/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TypeFreak.java b/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TypeFreak.java index d95d7381..43a4162c 100644 --- a/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TypeFreak.java +++ b/repository-test/src/main/java/tech/ydb/yoj/repository/test/sample/model/TypeFreak.java @@ -4,6 +4,7 @@ import lombok.NonNull; import lombok.Value; import lombok.With; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.Table; @@ -20,7 +21,7 @@ public class TypeFreak implements Entity { boolean primitiveBoolean; byte primitiveByte; - @Column(dbType = "UINT8") + @Column(dbType = DbType.UINT8) byte primitiveByteUint8; short primitiveShort; int primitiveInt; @@ -29,7 +30,7 @@ public class TypeFreak implements Entity { double primitiveDouble; Boolean boxedBoolean; Byte boxedByte; - @Column(dbType = "UINT8") + @Column(dbType = DbType.UINT8) Byte boxedByteUint8; Short boxedShort; Integer boxedInteger; @@ -37,20 +38,20 @@ public class TypeFreak implements Entity { Float boxedFloat; Double boxedDouble; - @Column(dbType = "UTF8") + @Column(dbType = DbType.UTF8) String utf8String; String string; byte[] bytes; Status status; - @Column(dbType = "UTF8") + @Column(dbType = DbType.UTF8) Status utf8Status; @With Embedded embedded; - @Column(flatten = false, dbType = "UTF8") + @Column(flatten = false, dbType = DbType.UTF8) Embedded utf8embedded; - @Column(flatten = false, dbType = "STRING") + @Column(flatten = false, dbType = DbType.STRING) Embedded stringEmbedded; - @Column(flatten = false, dbType = "JSON_DOCUMENT") + @Column(flatten = false, dbType = DbType.JSON_DOCUMENT) Embedded jsonDocumentEmbedded; @Column(flatten = false) Embedded jsonEmbedded; @@ -61,11 +62,11 @@ public class TypeFreak implements Entity { List list2; Set list3; Map map1; - @Column(dbType = "UTF8") + @Column(dbType = DbType.UTF8) Map utf8map; - @Column(dbType = "STRING") + @Column(dbType = DbType.STRING) Map stringMap; - @Column(dbType = "JSON_DOCUMENT") + @Column(dbType = DbType.JSON_DOCUMENT) Map jsonDocumentMap; StringValueWrapper stringValueWrapper; diff --git a/repository-ydb-common/pom.xml b/repository-ydb-common/pom.xml index 82f92b65..89a85b2f 100644 --- a/repository-ydb-common/pom.xml +++ b/repository-ydb-common/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/repository-ydb-v1/pom.xml b/repository-ydb-v1/pom.xml index c365a36a..14130eb0 100644 --- a/repository-ydb-v1/pom.xml +++ b/repository-ydb-v1/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java index ba133049..a024756d 100644 --- a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java +++ b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java @@ -72,81 +72,50 @@ private static Type typeToSDK(ValueProtos.Type type) { } private static PrimitiveType convertProtoPrimitiveTypeToSDK(ValueProtos.Type type) { - switch (type.getTypeId()) { - case JSON: - return PrimitiveType.json(); - case JSON_DOCUMENT: - return PrimitiveType.jsonDocument(); - case BOOL: - return PrimitiveType.bool(); - case INT8: - return PrimitiveType.int8(); - case UINT8: - return PrimitiveType.uint8(); - case INT32: - return PrimitiveType.int32(); - case UINT32: - return PrimitiveType.uint32(); - case INT64: - return PrimitiveType.int64(); - case UINT64: - return PrimitiveType.uint64(); - case FLOAT: - return PrimitiveType.float32(); - case DOUBLE: - return PrimitiveType.float64(); - case STRING: - return PrimitiveType.string(); - case UTF8: - return PrimitiveType.utf8(); - case TIMESTAMP: - return PrimitiveType.timestamp(); - case INTERVAL: - return PrimitiveType.interval(); - default: - throw new IllegalArgumentException(type.getTypeId().name()); - } + return switch (type.getTypeId()) { + case JSON -> PrimitiveType.json(); + case JSON_DOCUMENT -> PrimitiveType.jsonDocument(); + case BOOL -> PrimitiveType.bool(); + case INT8 -> PrimitiveType.int8(); + case UINT8 -> PrimitiveType.uint8(); + case INT32 -> PrimitiveType.int32(); + case UINT32 -> PrimitiveType.uint32(); + case INT64 -> PrimitiveType.int64(); + case UINT64 -> PrimitiveType.uint64(); + case FLOAT -> PrimitiveType.float32(); + case DOUBLE -> PrimitiveType.float64(); + case STRING -> PrimitiveType.string(); + case UTF8 -> PrimitiveType.utf8(); + case TIMESTAMP -> PrimitiveType.timestamp(); + case INTERVAL -> PrimitiveType.interval(); + default -> throw new IllegalArgumentException(type.getTypeId().name()); + }; } private static ValueProtos.Value convertProtoPrimitiveValueToSDK(ValueProtos.Type type, ValueProtos.Value value) { - switch (type.getTypeId()) { - case JSON: - return ProtoValue.json(value.getTextValue()); - case JSON_DOCUMENT: - return ProtoValue.jsonDocument(value.getTextValue()); - case BOOL: - return ProtoValue.bool(value.getBoolValue()); - case INT8: - return ProtoValue.int8((byte) value.getInt32Value()); - case UINT8: - return ProtoValue.uint8((byte) value.getUint32Value()); - case INT32: - return ProtoValue.int32(value.getInt32Value()); - case UINT32: - return ProtoValue.uint32(value.getUint32Value()); - case INT64: - return ProtoValue.int64(value.getInt64Value()); - case UINT64: - return ProtoValue.uint64(value.getUint64Value()); - case FLOAT: - return ProtoValue.float32(value.getFloatValue()); - case DOUBLE: - return ProtoValue.float64(value.getDoubleValue()); - case STRING: + return switch (type.getTypeId()) { + case JSON -> ProtoValue.json(value.getTextValue()); + case JSON_DOCUMENT -> ProtoValue.jsonDocument(value.getTextValue()); + case BOOL -> ProtoValue.bool(value.getBoolValue()); + case INT8 -> ProtoValue.int8((byte) value.getInt32Value()); + case UINT8 -> ProtoValue.uint8((byte) value.getUint32Value()); + case INT32 -> ProtoValue.int32(value.getInt32Value()); + case UINT32 -> ProtoValue.uint32(value.getUint32Value()); + case INT64 -> ProtoValue.int64(value.getInt64Value()); + case UINT64 -> ProtoValue.uint64(value.getUint64Value()); + case FLOAT -> ProtoValue.float32(value.getFloatValue()); + case DOUBLE -> ProtoValue.float64(value.getDoubleValue()); + case STRING -> { if (value.getValueCase() == ValueProtos.Value.ValueCase.BYTES_VALUE) { - return ProtoValue.bytes(value.getBytesValue()); - } else { - return ProtoValue.string(value.getTextValue(), StandardCharsets.UTF_8); + yield ProtoValue.bytes(value.getBytesValue()); } - case UTF8: - return ProtoValue.text(value.getTextValue()); - case TIMESTAMP: - return ProtoValue.timestamp(value.getUint64Value()); - case INTERVAL: - return ProtoValue.interval(value.getInt64Value()); - default: - throw new IllegalArgumentException(type.getTypeId() + ": " + value.toString()); - } + yield ProtoValue.string(value.getTextValue(), StandardCharsets.UTF_8); + } + case UTF8 -> ProtoValue.text(value.getTextValue()); + case TIMESTAMP -> ProtoValue.timestamp(value.getUint64Value()); + case INTERVAL -> ProtoValue.interval(value.getInt64Value()); + default -> throw new IllegalArgumentException(type.getTypeId() + ": " + value.toString()); + }; } private static ValueProtos.Value convertProtoDictValueToSDK(ValueProtos.Type type, ValueProtos.Value value) { @@ -257,42 +226,24 @@ public static ValueProtos.Value.Builder convertValueToProto(ValueReader column) } return builder; } - switch (type.getTypeId()) { - case JSON: - return builder.setTextValue(column.getJson()); - case JSON_DOCUMENT: - return builder.setTextValue(column.getJsonDocument()); - case BOOL: - return builder.setBoolValue(column.getBool()); - case INT8: - case INT16: - case INT32: - return builder.setInt32Value(column.getInt32()); - case UINT8: - return builder.setUint32Value(column.getUint8()); - case UINT16: - return builder.setUint32Value(column.getUint16()); - case UINT32: - return builder.setUint32Value((int) column.getUint32()); - case INT64: - return builder.setInt64Value(column.getInt64()); - case UINT64: - return builder.setUint64Value(column.getUint64()); - case FLOAT: - return builder.setFloatValue(column.getFloat32()); - case DOUBLE: - return builder.setDoubleValue(column.getFloat64()); - case STRING: - return builder.setBytesValue(UnsafeByteOperations.unsafeWrap(column.getString())); - case UTF8: - return builder.setTextValue(column.getUtf8()); - case TIMESTAMP: - return builder.setUint64Value(column.getValue().toPb().getUint64Value()); - case INTERVAL: - return builder.setInt64Value(column.getValue().toPb().getInt64Value()); - default: - throw new IllegalArgumentException(column.getType().toPb().getTypeId() + ": " + column.toString()); - } + return switch (type.getTypeId()) { + case JSON -> builder.setTextValue(column.getJson()); + case JSON_DOCUMENT -> builder.setTextValue(column.getJsonDocument()); + case BOOL -> builder.setBoolValue(column.getBool()); + case INT8, INT16, INT32 -> builder.setInt32Value(column.getInt32()); + case UINT8 -> builder.setUint32Value(column.getUint8()); + case UINT16 -> builder.setUint32Value(column.getUint16()); + case UINT32 -> builder.setUint32Value((int) column.getUint32()); + case INT64 -> builder.setInt64Value(column.getInt64()); + case UINT64 -> builder.setUint64Value(column.getUint64()); + case FLOAT -> builder.setFloatValue(column.getFloat32()); + case DOUBLE -> builder.setDoubleValue(column.getFloat64()); + case STRING -> builder.setBytesValue(UnsafeByteOperations.unsafeWrap(column.getString())); + case UTF8 -> builder.setTextValue(column.getUtf8()); + case TIMESTAMP -> builder.setUint64Value(column.getValue().toPb().getUint64Value()); + case INTERVAL -> builder.setInt64Value(column.getValue().toPb().getInt64Value()); + default -> throw new IllegalArgumentException(column.getType().toPb().getTypeId() + ": " + column); + }; } public static Params convertToParams(Map queryParameters) { diff --git a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java index c1400244..45bc8f3a 100644 --- a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java +++ b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java @@ -11,9 +11,9 @@ import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.EntitySchema; -import tech.ydb.yoj.repository.ydb.DbType; import tech.ydb.yoj.repository.ydb.YdbConfig; import tech.ydb.yoj.repository.ydb.YdbRepository; import tech.ydb.yoj.repository.ydb.client.YdbPaths; @@ -29,7 +29,6 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Collectors; import static java.util.function.Predicate.not; import static java.util.stream.Collectors.joining; @@ -273,22 +272,27 @@ private static String builderDDLColumns(YdbSchemaOperations.Table table) { } private static String typeToDDL(String type) { - return switch (type) { - case DbType.BOOL -> "PrimitiveType.bool()"; - case DbType.UINT8 -> "PrimitiveType.uint8()"; - case DbType.INT32 -> "PrimitiveType.int32()"; - case DbType.UINT32 -> "PrimitiveType.uint32()"; - case DbType.INT64 -> "PrimitiveType.int64()"; - case DbType.UINT64 -> "PrimitiveType.uint64()"; - case DbType.FLOAT -> "PrimitiveType.float32()"; - case DbType.DOUBLE -> "PrimitiveType.float64()"; - case DbType.DATE -> "PrimitiveType.date()"; - case DbType.DATETIME -> "PrimitiveType.datetime()"; - case DbType.TIMESTAMP -> "PrimitiveType.timestamp()"; - case DbType.STRING -> "PrimitiveType.string()"; - case DbType.UTF8 -> "PrimitiveType.utf8()"; - case DbType.JSON -> "PrimitiveType.json()"; - default -> throw new IllegalArgumentException("Unknown db type: " + type); + if (type == null) { + throw new IllegalArgumentException("Unknown db type: " + type); + } + return switch (DbType.valueOf(type)) { + case DEFAULT -> throw new IllegalArgumentException("Unknown db type: " + type); + case BOOL -> "PrimitiveType.bool()"; + case UINT8 -> "PrimitiveType.uint8()"; + case INT32 -> "PrimitiveType.int32()"; + case UINT32 -> "PrimitiveType.uint32()"; + case INT64 -> "PrimitiveType.int64()"; + case UINT64 -> "PrimitiveType.uint64()"; + case FLOAT -> "PrimitiveType.float32()"; + case DOUBLE -> "PrimitiveType.float64()"; + case DATE -> "PrimitiveType.date()"; + case DATETIME -> "PrimitiveType.datetime()"; + case TIMESTAMP -> "PrimitiveType.timestamp()"; + case INTERVAL -> "PrimitiveType.interval()"; + case STRING -> "PrimitiveType.string()"; + case UTF8 -> "PrimitiveType.utf8()"; + case JSON -> "PrimitiveType.json()"; + case JSON_DOCUMENT -> "PrimitiveType.jsonDocument()"; }; } @@ -312,11 +316,11 @@ private static String indexes(YdbSchemaOperations.Table table) { } return ",\n" + indexes.stream() .map(idx -> "\tINDEX `" + idx.getName() + "` GLOBAL ON (" + indexColumns(idx.getColumns()) + ")") - .collect(Collectors.joining(",\n")) + "\n"; + .collect(joining(",\n")) + "\n"; } private static String indexColumns(List columns) { - return columns.stream().map(c -> "`" + c + "`").collect(Collectors.joining(",")); + return columns.stream().map(c -> "`" + c + "`").collect(joining(",")); } private void makeMigrationTableInstruction(YdbSchemaOperations.Table from, YdbSchemaOperations.Table to) { diff --git a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java index c4c6ec6c..4088303f 100644 --- a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java +++ b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java @@ -1,10 +1,11 @@ package tech.ydb.yoj.repository.ydb.statement; import lombok.Value; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; @Value public class Count { - @Column(dbType = "UINT64") + @Column(dbType = DbType.UINT64) long count; } diff --git a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java index 85a580cf..9e2b5bac 100644 --- a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java +++ b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java @@ -13,6 +13,7 @@ import lombok.Value; import lombok.With; import tech.ydb.yoj.databind.ByteArray; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.Schema.JavaField; @@ -345,8 +346,10 @@ public static YqlPrimitiveType of(Type javaType) { */ @NonNull public static YqlPrimitiveType of(JavaField column) { - String columnType = column.getDbType(); - PrimitiveTypeId yqlType = (columnType == null) ? null : convertToYqlType(columnType); + PrimitiveTypeId yqlType = null; + if (column.getDbType() != DbType.DEFAULT) { + yqlType = convertToYqlType(column.getDbType().typeString()); + } return resolveYqlType(column.getType(), column.getValueType(), yqlType, column.getDbTypeQualifier()); } diff --git a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java index bae302a9..ad564a67 100644 --- a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java +++ b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java @@ -7,6 +7,7 @@ import lombok.Value; import org.junit.Assert; import org.junit.Test; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.GlobalIndex; diff --git a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java index e72cb639..f6bd9687 100644 --- a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java +++ b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java @@ -2,6 +2,7 @@ import lombok.Value; import lombok.With; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.ydb.client.YdbTableHint; @@ -17,7 +18,7 @@ public class HintUniform implements Entity { @Value public static class Id implements Entity.Id { - @Column(dbType = "UINT32") + @Column(dbType = DbType.UINT32) long value; } } diff --git a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java index 3e7b0923..9fe7bade 100644 --- a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java +++ b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java @@ -5,6 +5,7 @@ import lombok.Builder; import lombok.NonNull; import lombok.Value; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.Table; import tech.ydb.yoj.repository.BaseDb; @@ -15,7 +16,6 @@ import tech.ydb.yoj.repository.db.TxManager; import tech.ydb.yoj.repository.db.TxOptions; import tech.ydb.yoj.repository.test.RepositoryTestSupport; -import tech.ydb.yoj.repository.ydb.DbType; import tech.ydb.yoj.repository.ydb.TestYdbConfig; import tech.ydb.yoj.repository.ydb.YdbRepository; import tech.ydb.yoj.repository.ydb.YdbRepositoryTransaction; diff --git a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java index e063734f..ab916bbb 100644 --- a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java +++ b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java @@ -4,6 +4,7 @@ import lombok.NonNull; import lombok.Value; import org.junit.Test; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.expression.OrderExpression; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.GlobalIndex; @@ -12,7 +13,6 @@ import tech.ydb.yoj.repository.db.EntitySchema; import tech.ydb.yoj.repository.db.Table; import tech.ydb.yoj.repository.db.ViewSchema; -import tech.ydb.yoj.repository.ydb.DbType; import java.util.List; import java.util.Map; diff --git a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java index a7779191..5d6aefa6 100644 --- a/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java +++ b/repository-ydb-v1/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java @@ -10,13 +10,13 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.Schema; import tech.ydb.yoj.repository.DbTypeQualifier; import tech.ydb.yoj.repository.db.common.CommonConverters; import tech.ydb.yoj.repository.db.json.JacksonJsonConverter; -import tech.ydb.yoj.repository.ydb.DbType; import java.lang.reflect.Type; import java.time.Duration; diff --git a/repository-ydb-v2/pom.xml b/repository-ydb-v2/pom.xml index fd562df2..462ced3c 100644 --- a/repository-ydb-v2/pom.xml +++ b/repository-ydb-v2/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java index c331800c..fa7fd17b 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/client/YdbConverter.java @@ -72,81 +72,50 @@ private static Type typeToSDK(ValueProtos.Type type) { } static PrimitiveType convertProtoPrimitiveTypeToSDK(ValueProtos.Type type) { - switch (type.getTypeId()) { - case JSON: - return PrimitiveType.Json; - case JSON_DOCUMENT: - return PrimitiveType.JsonDocument; - case BOOL: - return PrimitiveType.Bool; - case INT8: - return PrimitiveType.Int8; - case UINT8: - return PrimitiveType.Uint8; - case INT32: - return PrimitiveType.Int32; - case UINT32: - return PrimitiveType.Uint32; - case INT64: - return PrimitiveType.Int64; - case UINT64: - return PrimitiveType.Uint64; - case FLOAT: - return PrimitiveType.Float; - case DOUBLE: - return PrimitiveType.Double; - case STRING: - return PrimitiveType.Bytes; - case UTF8: - return PrimitiveType.Text; - case TIMESTAMP: - return PrimitiveType.Timestamp; - case INTERVAL: - return PrimitiveType.Interval; - default: - throw new IllegalArgumentException(type.getTypeId().name()); - } + return switch (type.getTypeId()) { + case JSON -> PrimitiveType.Json; + case JSON_DOCUMENT -> PrimitiveType.JsonDocument; + case BOOL -> PrimitiveType.Bool; + case INT8 -> PrimitiveType.Int8; + case UINT8 -> PrimitiveType.Uint8; + case INT32 -> PrimitiveType.Int32; + case UINT32 -> PrimitiveType.Uint32; + case INT64 -> PrimitiveType.Int64; + case UINT64 -> PrimitiveType.Uint64; + case FLOAT -> PrimitiveType.Float; + case DOUBLE -> PrimitiveType.Double; + case STRING -> PrimitiveType.Bytes; + case UTF8 -> PrimitiveType.Text; + case TIMESTAMP -> PrimitiveType.Timestamp; + case INTERVAL -> PrimitiveType.Interval; + default -> throw new IllegalArgumentException(type.getTypeId().name()); + }; } private static ValueProtos.Value convertProtoPrimitiveValueToSDK(ValueProtos.Type type, ValueProtos.Value value) { - switch (type.getTypeId()) { - case JSON: - return ProtoValue.fromJson(value.getTextValue()); - case JSON_DOCUMENT: - return ProtoValue.fromJsonDocument(value.getTextValue()); - case BOOL: - return ProtoValue.fromBool(value.getBoolValue()); - case INT8: - return ProtoValue.fromInt8((byte) value.getInt32Value()); - case UINT8: - return ProtoValue.fromUint8((byte) value.getUint32Value()); - case INT32: - return ProtoValue.fromInt32(value.getInt32Value()); - case UINT32: - return ProtoValue.fromUint32(value.getUint32Value()); - case INT64: - return ProtoValue.fromInt64(value.getInt64Value()); - case UINT64: - return ProtoValue.fromUint64(value.getUint64Value()); - case FLOAT: - return ProtoValue.fromFloat(value.getFloatValue()); - case DOUBLE: - return ProtoValue.fromDouble(value.getDoubleValue()); - case STRING: + return switch (type.getTypeId()) { + case JSON -> ProtoValue.fromJson(value.getTextValue()); + case JSON_DOCUMENT -> ProtoValue.fromJsonDocument(value.getTextValue()); + case BOOL -> ProtoValue.fromBool(value.getBoolValue()); + case INT8 -> ProtoValue.fromInt8((byte) value.getInt32Value()); + case UINT8 -> ProtoValue.fromUint8((byte) value.getUint32Value()); + case INT32 -> ProtoValue.fromInt32(value.getInt32Value()); + case UINT32 -> ProtoValue.fromUint32(value.getUint32Value()); + case INT64 -> ProtoValue.fromInt64(value.getInt64Value()); + case UINT64 -> ProtoValue.fromUint64(value.getUint64Value()); + case FLOAT -> ProtoValue.fromFloat(value.getFloatValue()); + case DOUBLE -> ProtoValue.fromDouble(value.getDoubleValue()); + case STRING -> { if (value.getValueCase() == ValueProtos.Value.ValueCase.BYTES_VALUE) { - return ProtoValue.fromBytes(value.getBytesValue()); - } else { - return ProtoValue.fromStringAsBytes(value.getTextValue(), StandardCharsets.UTF_8); + yield ProtoValue.fromBytes(value.getBytesValue()); } - case UTF8: - return ProtoValue.fromText(value.getTextValue()); - case TIMESTAMP: - return ProtoValue.fromTimestamp(value.getUint64Value()); - case INTERVAL: - return ProtoValue.fromInterval(value.getInt64Value()); - default: - throw new IllegalArgumentException(type.getTypeId() + ": " + value.toString()); - } + yield ProtoValue.fromStringAsBytes(value.getTextValue(), StandardCharsets.UTF_8); + } + case UTF8 -> ProtoValue.fromText(value.getTextValue()); + case TIMESTAMP -> ProtoValue.fromTimestamp(value.getUint64Value()); + case INTERVAL -> ProtoValue.fromInterval(value.getInt64Value()); + default -> throw new IllegalArgumentException(type.getTypeId() + ": " + value.toString()); + }; } private static ValueProtos.Value convertProtoDictValueToSDK(ValueProtos.Type type, ValueProtos.Value value) { @@ -257,42 +226,24 @@ public static ValueProtos.Value.Builder convertValueToProto(ValueReader column) } return builder; } - switch (type.getTypeId()) { - case JSON: - return builder.setTextValue(column.getJson()); - case JSON_DOCUMENT: - return builder.setTextValue(column.getJsonDocument()); - case BOOL: - return builder.setBoolValue(column.getBool()); - case INT8: - case INT16: - case INT32: - return builder.setInt32Value(column.getInt32()); - case UINT8: - return builder.setUint32Value(column.getUint8()); - case UINT16: - return builder.setUint32Value(column.getUint16()); - case UINT32: - return builder.setUint32Value((int) column.getUint32()); - case INT64: - return builder.setInt64Value(column.getInt64()); - case UINT64: - return builder.setUint64Value(column.getUint64()); - case FLOAT: - return builder.setFloatValue(column.getFloat()); - case DOUBLE: - return builder.setDoubleValue(column.getDouble()); - case STRING: - return builder.setBytesValue(UnsafeByteOperations.unsafeWrap(column.getBytes())); - case UTF8: - return builder.setTextValue(column.getText()); - case TIMESTAMP: - return builder.setUint64Value(column.getValue().toPb().getUint64Value()); - case INTERVAL: - return builder.setInt64Value(column.getValue().toPb().getInt64Value()); - default: - throw new IllegalArgumentException(column.getType().toPb().getTypeId() + ": " + column.toString()); - } + return switch (type.getTypeId()) { + case JSON -> builder.setTextValue(column.getJson()); + case JSON_DOCUMENT -> builder.setTextValue(column.getJsonDocument()); + case BOOL -> builder.setBoolValue(column.getBool()); + case INT8, INT16, INT32 -> builder.setInt32Value(column.getInt32()); + case UINT8 -> builder.setUint32Value(column.getUint8()); + case UINT16 -> builder.setUint32Value(column.getUint16()); + case UINT32 -> builder.setUint32Value((int) column.getUint32()); + case INT64 -> builder.setInt64Value(column.getInt64()); + case UINT64 -> builder.setUint64Value(column.getUint64()); + case FLOAT -> builder.setFloatValue(column.getFloat()); + case DOUBLE -> builder.setDoubleValue(column.getDouble()); + case STRING -> builder.setBytesValue(UnsafeByteOperations.unsafeWrap(column.getBytes())); + case UTF8 -> builder.setTextValue(column.getText()); + case TIMESTAMP -> builder.setUint64Value(column.getValue().toPb().getUint64Value()); + case INTERVAL -> builder.setInt64Value(column.getValue().toPb().getInt64Value()); + default -> throw new IllegalArgumentException(column.getType().toPb().getTypeId() + ": " + column); + }; } public static Params convertToParams(Map queryParameters) { diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java index 05b2510c..0f02c747 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/compatibility/YdbSchemaCompatibilityChecker.java @@ -11,9 +11,9 @@ import org.apache.commons.text.StringEscapeUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.EntitySchema; -import tech.ydb.yoj.repository.ydb.DbType; import tech.ydb.yoj.repository.ydb.YdbConfig; import tech.ydb.yoj.repository.ydb.YdbRepository; import tech.ydb.yoj.repository.ydb.client.YdbPaths; @@ -286,22 +286,27 @@ private static String builderDDLColumns(YdbSchemaOperations.Table table) { } private static String typeToDDL(String type) { - return switch (type) { - case DbType.BOOL -> "PrimitiveType.bool()"; - case DbType.UINT8 -> "PrimitiveType.uint8()"; - case DbType.INT32 -> "PrimitiveType.int32()"; - case DbType.UINT32 -> "PrimitiveType.uint32()"; - case DbType.INT64 -> "PrimitiveType.int64()"; - case DbType.UINT64 -> "PrimitiveType.uint64()"; - case DbType.FLOAT -> "PrimitiveType.float32()"; - case DbType.DOUBLE -> "PrimitiveType.float64()"; - case DbType.DATE -> "PrimitiveType.date()"; - case DbType.DATETIME -> "PrimitiveType.datetime()"; - case DbType.TIMESTAMP -> "PrimitiveType.timestamp()"; - case DbType.STRING -> "PrimitiveType.string()"; - case DbType.UTF8 -> "PrimitiveType.utf8()"; - case DbType.JSON -> "PrimitiveType.json()"; - default -> throw new IllegalArgumentException("Unknown db type: " + type); + if (type == null) { + throw new IllegalArgumentException("Unknown db type: " + type); + } + return switch (DbType.valueOf(type)) { + case DEFAULT -> throw new IllegalArgumentException("Unknown db type: " + type); + case BOOL -> "PrimitiveType.bool()"; + case UINT8 -> "PrimitiveType.uint8()"; + case INT32 -> "PrimitiveType.int32()"; + case UINT32 -> "PrimitiveType.uint32()"; + case INT64 -> "PrimitiveType.int64()"; + case UINT64 -> "PrimitiveType.uint64()"; + case FLOAT -> "PrimitiveType.float32()"; + case DOUBLE -> "PrimitiveType.float64()"; + case DATE -> "PrimitiveType.date()"; + case DATETIME -> "PrimitiveType.datetime()"; + case TIMESTAMP -> "PrimitiveType.timestamp()"; + case INTERVAL -> "PrimitiveType.interval()"; + case STRING -> "PrimitiveType.string()"; + case UTF8 -> "PrimitiveType.utf8()"; + case JSON -> "PrimitiveType.json()"; + case JSON_DOCUMENT -> "PrimitiveType.jsonDocument()"; }; } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java index c4c6ec6c..4088303f 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/Count.java @@ -1,10 +1,11 @@ package tech.ydb.yoj.repository.ydb.statement; import lombok.Value; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; @Value public class Count { - @Column(dbType = "UINT64") + @Column(dbType = DbType.UINT64) long count; } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java index e9fd567c..de249b8f 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java @@ -13,6 +13,7 @@ import tech.ydb.proto.ValueProtos.Value.ValueCase; import tech.ydb.table.values.proto.ProtoValue; import tech.ydb.yoj.databind.ByteArray; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.Schema.JavaField; @@ -345,8 +346,10 @@ public static YqlPrimitiveType of(Type javaType) { */ @NonNull public static YqlPrimitiveType of(JavaField column) { - String columnType = column.getDbType(); - PrimitiveTypeId yqlType = (columnType == null) ? null : convertToYqlType(columnType); + PrimitiveTypeId yqlType = null; + if (column.getDbType() != DbType.DEFAULT) { + yqlType = convertToYqlType(column.getDbType().typeString()); + } return resolveYqlType(column.getType(), column.getValueType(), yqlType, column.getDbTypeQualifier()); } diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java index d89ae35d..1b434c61 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YqlTypeTest.java @@ -6,6 +6,7 @@ import org.junit.Assert; import org.junit.Test; import tech.ydb.proto.ValueProtos; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.GlobalIndex; diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityChangeTtl.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityChangeTtl.java index d1ab293a..63c3cf6c 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityChangeTtl.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityChangeTtl.java @@ -1,6 +1,7 @@ package tech.ydb.yoj.repository.ydb.model; import lombok.Value; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.TTL; import tech.ydb.yoj.databind.schema.Table; @@ -14,7 +15,7 @@ public class EntityChangeTtl implements Entity { EntityChangeTtl.Id id; - @Column(dbType = "TIMESTAMP") + @Column(dbType = DbType.TIMESTAMP) Instant createdAt; @Value diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityDropTtl.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityDropTtl.java index ddc9c41b..f024b385 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityDropTtl.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/model/EntityDropTtl.java @@ -1,6 +1,7 @@ package tech.ydb.yoj.repository.ydb.model; import lombok.Value; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.Table; import tech.ydb.yoj.repository.db.Entity; @@ -12,7 +13,7 @@ public class EntityDropTtl implements Entity { Id id; - @Column(dbType = "TIMESTAMP") + @Column(dbType = DbType.TIMESTAMP) Instant createdAt; @Value diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java index e72cb639..f6bd9687 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/sample/model/HintUniform.java @@ -2,6 +2,7 @@ import lombok.Value; import lombok.With; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.ydb.client.YdbTableHint; @@ -17,7 +18,7 @@ public class HintUniform implements Entity { @Value public static class Id implements Entity.Id { - @Column(dbType = "UINT32") + @Column(dbType = DbType.UINT32) long value; } } diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java index a8af1cf9..16ce9ee7 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/AbstractMultipleVarsYqlStatementTest.java @@ -7,6 +7,7 @@ import lombok.Value; import org.junit.ClassRule; import tech.ydb.test.junit4.GrpcTransportRule; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.Table; import tech.ydb.yoj.repository.BaseDb; @@ -17,7 +18,6 @@ import tech.ydb.yoj.repository.db.TxManager; import tech.ydb.yoj.repository.db.TxOptions; import tech.ydb.yoj.repository.test.RepositoryTestSupport; -import tech.ydb.yoj.repository.ydb.DbType; import tech.ydb.yoj.repository.ydb.YdbConfig; import tech.ydb.yoj.repository.ydb.YdbRepository; import tech.ydb.yoj.repository.ydb.YdbRepositoryTransaction; diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java index 15d7aed6..a1c1437f 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/FindInStatementIntegrationTest.java @@ -5,6 +5,7 @@ import org.junit.Test; import tech.ydb.proto.ValueProtos; import tech.ydb.yoj.databind.expression.OrderExpression; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.GlobalIndex; import tech.ydb.yoj.databind.schema.Schema; @@ -12,7 +13,6 @@ import tech.ydb.yoj.repository.db.EntitySchema; import tech.ydb.yoj.repository.db.Table; import tech.ydb.yoj.repository.db.ViewSchema; -import tech.ydb.yoj.repository.ydb.DbType; import java.util.List; import java.util.Map; diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java index d7708ebe..e32c41fa 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/yql/YqlTypeAllTypesTest.java @@ -10,13 +10,13 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.FieldValueType; import tech.ydb.yoj.databind.schema.Column; import tech.ydb.yoj.databind.schema.Schema; import tech.ydb.yoj.repository.DbTypeQualifier; import tech.ydb.yoj.repository.db.common.CommonConverters; import tech.ydb.yoj.repository.db.json.JacksonJsonConverter; -import tech.ydb.yoj.repository.ydb.DbType; import java.lang.reflect.Type; import java.time.Duration; diff --git a/repository/pom.xml b/repository/pom.xml index fcdf2e96..691d5c6a 100644 --- a/repository/pom.xml +++ b/repository/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml diff --git a/repository/src/test/java/tech/ydb/yoj/repository/db/PojoEntitySchemaTest.java b/repository/src/test/java/tech/ydb/yoj/repository/db/PojoEntitySchemaTest.java index c4075518..6fdd44ea 100644 --- a/repository/src/test/java/tech/ydb/yoj/repository/db/PojoEntitySchemaTest.java +++ b/repository/src/test/java/tech/ydb/yoj/repository/db/PojoEntitySchemaTest.java @@ -2,6 +2,7 @@ import lombok.Value; import org.junit.Test; +import tech.ydb.yoj.databind.DbType; import tech.ydb.yoj.databind.schema.Column; import static org.assertj.core.api.Assertions.assertThat; @@ -101,7 +102,7 @@ private static final class ColumnNameClashes implements Entity id() { record EntityIncorrectSpecifyInterface(CorrectEntity.Id id) implements RecordEntity { } - record ColumnNameClashes(@Column Id id, @Column(name = "id", dbType = "UTF8") String value) implements RecordEntity { + record ColumnNameClashes(@Column Id id, @Column(name = "id", dbType = DbType.UTF8) String value) implements RecordEntity { record Id(@Column long uid) implements Entity.Id { } } diff --git a/util/pom.xml b/util/pom.xml index c07318e2..e905ab6b 100644 --- a/util/pom.xml +++ b/util/pom.xml @@ -10,7 +10,7 @@ tech.ydb.yoj yoj-parent - 1.1.4-SNAPSHOT + 2.0.0-SNAPSHOT ../pom.xml