From 277e2acfc0a398bfc4cb179655fa1c8a684d1807 Mon Sep 17 00:00:00 2001 From: Alexander Lavrukov Date: Thu, 15 Feb 2024 19:53:37 +0300 Subject: [PATCH] db-type-enum: column.getDbType() -> DbType --- .../src/main/java/tech/ydb/yoj/databind/DbType.java | 12 ++++++------ .../java/tech/ydb/yoj/databind/schema/Schema.java | 8 ++++---- .../ydb/yoj/databind/schema/naming/ColumnTest.java | 1 + .../ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java | 7 +++++-- .../ydb/yoj/repository/ydb/yql/YqlPrimitiveType.java | 7 +++++-- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/databind/src/main/java/tech/ydb/yoj/databind/DbType.java b/databind/src/main/java/tech/ydb/yoj/databind/DbType.java index bf970979..b3634d40 100644 --- a/databind/src/main/java/tech/ydb/yoj/databind/DbType.java +++ b/databind/src/main/java/tech/ydb/yoj/databind/DbType.java @@ -4,7 +4,7 @@ * Database column types supported by YDB. */ public enum DbType { - DEFAULT(""), + DEFAULT(null), /** * Boolean value. */ @@ -86,13 +86,13 @@ public enum DbType { */ JSON_DOCUMENT("JSON_DOCUMENT"); - private final String dbType; + private final String type; - DbType(String dbType) { - this.dbType = dbType; + DbType(String type) { + this.type = type; } - public String getDbType() { - return dbType; + public String typeString() { + return type; } } 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 46530de9..bbe2a918 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 @@ -422,12 +422,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() != DbType.DEFAULT) { - return annotation.dbType().getDbType(); + 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 5f05ff39..3c8ca23c 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 @@ -57,6 +57,7 @@ public void annotatedFieldDbTypeTest() { Schema schema = newSchema(UInt32.class); assertThat(schema.flattenFields().stream() .map(Schema.JavaField::getDbType)) + .map(DbType::typeString) .containsOnly("UINT32"); } 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 c6233458..cf47cf35 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 @@ -12,6 +12,7 @@ import lombok.NonNull; import lombok.Value; import lombok.With; +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; @@ -341,8 +342,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/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 48724498..02016429 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 @@ -12,6 +12,7 @@ import tech.ydb.proto.ValueProtos.Type.PrimitiveTypeId; import tech.ydb.proto.ValueProtos.Value.ValueCase; import tech.ydb.table.values.proto.ProtoValue; +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; @@ -341,8 +342,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()); }