Skip to content

Commit

Permalink
remove Dynamic annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lavrukov committed Dec 2, 2024
1 parent f8860f0 commit af982cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
22 changes: 3 additions & 19 deletions databind/src/main/java/tech/ydb/yoj/databind/schema/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +92,7 @@ protected Schema(@NonNull SchemaKey<T> 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)
Expand Down Expand Up @@ -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<JavaField> flattenFields() {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,16 @@ public <T extends Entity<T>> SchemaOperations<T> schema(Class<T> 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() {
Expand All @@ -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;
}
Expand Down

0 comments on commit af982cd

Please sign in to comment.