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 82570e3f..36c84736 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 @@ -20,8 +20,6 @@ import tech.ydb.yoj.databind.schema.reflect.StdReflector; import javax.annotation.Nullable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Constructor; import java.lang.reflect.Type; import java.time.Duration; @@ -94,7 +92,7 @@ protected Schema(@NonNull SchemaKey key, @NonNull Reflector reflector) { this.reflectType = reflector.reflectRootType(type); this.schemaKey = key; - this.staticName = type.isAnnotationPresent(Dynamic.class) ? null : namingStrategy.getNameForClass(type); + this.staticName = namingStrategy.getNameForClass(type); this.fields = reflectType.getFields().stream().map(this::newRootJavaField).toList(); recurseFields(this.fields) @@ -278,11 +276,7 @@ public final NamingStrategy getNamingStrategy() { * @return the table name for data binding */ public final String getName() { - return staticName != null ? staticName : getNamingStrategy().getNameForClass(getType()); - } - - public final boolean isDynamic() { - return staticName == null; + return staticName; } public final List flattenFields() { @@ -386,9 +380,7 @@ public final String toString() { schemaName = getClass().getName(); } - return schemaName - + (isDynamic() ? ", dynamic" : " \"" + staticName + "\"") - + " [type=" + getType().getName() + "]"; + return schemaName + " \"" + staticName + "\" [type=" + getType().getName() + "]"; } private static final class DummyCustomValueSubField implements ReflectField { @@ -816,12 +808,4 @@ public static class Changefeed { boolean initialScan; } - - /** - * Annotation for schemas with dynamic names (the {@link NamingStrategy} can return different names - * for different invocations.) - */ - @Retention(RetentionPolicy.RUNTIME) - public @interface Dynamic { - } } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/YdbRepository.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/YdbRepository.java index 869e9870..dcfe87ed 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/YdbRepository.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/YdbRepository.java @@ -255,11 +255,16 @@ public > SchemaOperations schema(Class c) { @Override public void create() { String tableName = schema.getName(); - getSchemaOperations().createTable(tableName, schema.flattenFields(), schema.flattenId(), - extractHint(), schema.getGlobalIndexes(), schema.getTtlModifier(), schema.getChangefeeds()); - if (!schema.isDynamic()) { - entityClassesByTableName.put(tableName, c); - } + getSchemaOperations().createTable( + tableName, + schema.flattenFields(), + schema.flattenId(), + extractHint(), + schema.getGlobalIndexes(), + schema.getTtlModifier(), + schema.getChangefeeds() + ); + entityClassesByTableName.put(tableName, c); } private YdbTableHint extractHint() { @@ -283,12 +288,10 @@ public void drop() { public boolean exists() { String tableName = schema.getName(); boolean exists = getSchemaOperations().hasTable(tableName); - if (!schema.isDynamic()) { - if (exists) { - entityClassesByTableName.put(tableName, c); - } else { - entityClassesByTableName.remove(tableName); - } + if (exists) { + entityClassesByTableName.put(tableName, c); + } else { + entityClassesByTableName.remove(tableName); } return exists; }