Skip to content

Commit

Permalink
db-type-enum: column.getDbType() -> DbType
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lavrukov committed Feb 15, 2024
1 parent 045fe60 commit 277e2ac
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
12 changes: 6 additions & 6 deletions databind/src/main/java/tech/ydb/yoj/databind/DbType.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Database column types supported by YDB.
*/
public enum DbType {
DEFAULT(""),
DEFAULT(null),
/**
* Boolean value.
*/
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void annotatedFieldDbTypeTest() {
Schema<UInt32> schema = newSchema(UInt32.class);
assertThat(schema.flattenFields().stream()
.map(Schema.JavaField::getDbType))
.map(DbType::typeString)
.containsOnly("UINT32");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 277e2ac

Please sign in to comment.