diff --git a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java index ae58f271..5b343ae4 100644 --- a/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java +++ b/repository-ydb-v1/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java @@ -9,6 +9,7 @@ import tech.ydb.yoj.databind.expression.OrderExpression; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.Entity.Id; +import tech.ydb.yoj.repository.db.EntityDescription; import tech.ydb.yoj.repository.db.EntityIdSchema; import tech.ydb.yoj.repository.db.EntitySchema; import tech.ydb.yoj.repository.db.Range; @@ -57,6 +58,7 @@ public class YdbTable> implements Table { private final QueryExecutor executor; @Getter private final Class type; + private final EntityDescription desc; public YdbTable(Class type, QueryExecutor executor) { this.type = type; diff --git a/repository/src/main/java/tech/ydb/yoj/repository/db/EntityDescription.java b/repository/src/main/java/tech/ydb/yoj/repository/db/EntityDescription.java new file mode 100644 index 00000000..058f57a2 --- /dev/null +++ b/repository/src/main/java/tech/ydb/yoj/repository/db/EntityDescription.java @@ -0,0 +1,7 @@ +package tech.ydb.yoj.repository.db; + +public record EntityDescription>( + Class entityCls, + String tableName +) { +} diff --git a/repository/src/main/java/tech/ydb/yoj/repository/db/Repository.java b/repository/src/main/java/tech/ydb/yoj/repository/db/Repository.java index f7b44ca6..02a1485b 100644 --- a/repository/src/main/java/tech/ydb/yoj/repository/db/Repository.java +++ b/repository/src/main/java/tech/ydb/yoj/repository/db/Repository.java @@ -14,6 +14,8 @@ default void checkSchemaCompatibility() { > SchemaOperations schema(Class c); + > SchemaOperations schema(EntityDescription c); + /** * @deprecated For testing purposes only. Will only reliably work for tables that were created or inspected * using calls to {@link #schema(Class)}. diff --git a/repository/src/main/java/tech/ydb/yoj/repository/db/RepositoryTransaction.java b/repository/src/main/java/tech/ydb/yoj/repository/db/RepositoryTransaction.java index 112f9c8c..737d2d59 100644 --- a/repository/src/main/java/tech/ydb/yoj/repository/db/RepositoryTransaction.java +++ b/repository/src/main/java/tech/ydb/yoj/repository/db/RepositoryTransaction.java @@ -10,6 +10,8 @@ public interface RepositoryTransaction { > Table table(Class c); + > Table table(EntityDescription c); + /** * Commits the transaction or throws exception. Note that this method is not expected to be called, if the last * transaction statement has thrown an exception, because it means that transaction didn't 'execute normally'. diff --git a/repository/src/main/java/tech/ydb/yoj/repository/db/cache/FirstLevelCache.java b/repository/src/main/java/tech/ydb/yoj/repository/db/cache/FirstLevelCache.java index fd261331..49305ea2 100644 --- a/repository/src/main/java/tech/ydb/yoj/repository/db/cache/FirstLevelCache.java +++ b/repository/src/main/java/tech/ydb/yoj/repository/db/cache/FirstLevelCache.java @@ -3,6 +3,7 @@ import com.google.common.collect.Maps; import lombok.NonNull; import tech.ydb.yoj.repository.db.Entity; +import tech.ydb.yoj.repository.db.EntityDescription; import java.util.Collections; import java.util.ConcurrentModificationException; @@ -16,15 +17,19 @@ public interface FirstLevelCache { - > E get(@NonNull Entity.Id id, @NonNull Function, E> loader); + > E get( + @NonNull EntityDescription desc, + @NonNull Entity.Id id, + @NonNull Function, E> loader + ); - > Optional peek(@NonNull Entity.Id id); + > Optional peek(@NonNull EntityDescription desc, @NonNull Entity.Id id); /** * Returns a immutable copy of the entities of {@code entityType} type that are in the * transaction L1 cache. */ - > List snapshot(@NonNull Class entityType); + > List snapshot(@NonNull EntityDescription desc); /** * Returns a unmodifiable map containing the entities of {@code entityType} type that are in the @@ -32,13 +37,13 @@ public interface FirstLevelCache { * changes to second affect the first. To avoid an {@link ConcurrentModificationException} exception * when iterating and simultaneous modification of the transaction L1 cache, you may need to make a copy. */ - > Map, E> entities(@NonNull Class entityType); + > Map, E> entities(@NonNull EntityDescription desc); - > void put(@NonNull E e); + > void put(@NonNull EntityDescription desc, @NonNull E e); - > void putEmpty(@NonNull Entity.Id id); + > void putEmpty(@NonNull EntityDescription desc, @NonNull Entity.Id id); - > boolean containsKey(@NonNull Entity.Id id); + > boolean containsKey(@NonNull EntityDescription desc, @NonNull Entity.Id id); static FirstLevelCache empty() { return new FirstLevelCache() { diff --git a/repository/src/main/java/tech/ydb/yoj/repository/db/projection/ProjectionCache.java b/repository/src/main/java/tech/ydb/yoj/repository/db/projection/ProjectionCache.java index b72f1eec..0c3fb981 100644 --- a/repository/src/main/java/tech/ydb/yoj/repository/db/projection/ProjectionCache.java +++ b/repository/src/main/java/tech/ydb/yoj/repository/db/projection/ProjectionCache.java @@ -2,14 +2,15 @@ import tech.ydb.yoj.repository.db.Entity; +import tech.ydb.yoj.repository.db.EntityDescription; import tech.ydb.yoj.repository.db.RepositoryTransaction; public interface ProjectionCache { - void load(Entity entity); + > void load(EntityDescription desc, Entity entity); - void save(Entity entity); + > void save(EntityDescription desc, Entity entity); - void delete(Entity.Id id); + > void delete(EntityDescription desc, Entity.Id id); void applyProjectionChanges(RepositoryTransaction transaction); }