Skip to content

Commit

Permalink
ydb-platform#32 Support multiple tables under one entity (Review comm…
Browse files Browse the repository at this point in the history
…ents)
  • Loading branch information
Sergei Galiamichev committed Dec 23, 2024
1 parent 6c30f74 commit 40ab237
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import tech.ydb.yoj.repository.db.IsolationLevel;
import tech.ydb.yoj.repository.db.RepositoryTransaction;
import tech.ydb.yoj.repository.db.Table;
import tech.ydb.yoj.repository.db.TableDescriptor;
import tech.ydb.yoj.repository.db.TxOptions;
import tech.ydb.yoj.repository.db.bulk.BulkParams;
import tech.ydb.yoj.repository.db.cache.RepositoryCache;
Expand Down Expand Up @@ -126,8 +127,8 @@ public <T extends Entity<T>> Table<T> table(Class<T> c) {
*/
@Override
@ExperimentalApi(issue = "https://github.com/ydb-platform/yoj-project/issues/32")
public <T extends Entity<T>> Table<T> table(@NonNull Class<T> clazz, @NonNull String tableName) {
return new YdbTable<>(clazz, tableName, this);
public <T extends Entity<T>> Table<T> table(@NonNull TableDescriptor<T> descriptor) {
return new YdbTable<>(descriptor, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public final class YdbSchemaCompatibilityChecker {
private final List<String> canExecuteMessages = new ArrayList<>();
private final List<String> incompatibleMessages = new ArrayList<>();

public YdbSchemaCompatibilityChecker(Map<String, Class<? extends Entity>> entities, YdbRepository repository) {
this(entities, repository, Config.DEFAULT);
public YdbSchemaCompatibilityChecker(YdbRepository repository, List<TableDescriptor<? extends Entity>> entities) {
this(repository, entities, Config.DEFAULT);
}

public YdbSchemaCompatibilityChecker(List<Class<? extends Entity>> entities, YdbRepository repository) {
Expand All @@ -67,8 +67,8 @@ public YdbSchemaCompatibilityChecker(List<Class<? extends Entity>> entities, Ydb
this.repositoryConfig = this.repository.getConfig();
}

public YdbSchemaCompatibilityChecker(Map<String, Class<? extends Entity>> entities, YdbRepository repository, Config config) {
this.entities = toDescriptors(entities);
public YdbSchemaCompatibilityChecker(YdbRepository repository, List<TableDescriptor<? extends Entity>> entities, Config config) {
this.entities = entities;
this.config = config;
this.repository = repository;
this.repositoryConfig = this.repository.getConfig();
Expand Down Expand Up @@ -484,12 +484,6 @@ private static List<TableDescriptor<? extends Entity>> toDescriptors(List<Class<
return descriptors;
}

private static List<TableDescriptor<? extends Entity>> toDescriptors(Map<String, Class<? extends Entity>> entities) {
List<TableDescriptor<? extends Entity>> descriptors = new ArrayList<>();
entities.forEach((n, e) -> descriptors.add(TableDescriptor.from(EntitySchema.of(e), n)));
return descriptors;
}

@Value
@Builder
@With
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ public YdbTable(Class<T> type, QueryExecutor executor) {
this.tableDescriptor = TableDescriptor.from(schema);
}

public YdbTable(Class<T> type, String name, QueryExecutor executor) {
this.type = type;
public YdbTable(TableDescriptor<T> descriptor, QueryExecutor executor) {
this.type = descriptor.entityType();
this.executor = new CheckingQueryExecutor(executor);
this.schema = EntitySchema.of(type);
this.tableDescriptor = TableDescriptor.from(schema, name);
this.tableDescriptor = descriptor;
}

protected YdbTable(QueryExecutor executor) {
Expand Down
5 changes: 3 additions & 2 deletions repository/src/main/java/tech/ydb/yoj/repository/BaseDb.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tech.ydb.yoj.ExperimentalApi;
import tech.ydb.yoj.repository.db.Entity;
import tech.ydb.yoj.repository.db.Table;
import tech.ydb.yoj.repository.db.TableDescriptor;
import tech.ydb.yoj.repository.db.Tx;
import tech.ydb.yoj.util.lang.Proxies;

Expand All @@ -14,7 +15,7 @@ static <T> T current(Class<T> type) {
<T extends Entity<T>> Table<T> table(Class<T> c);

@ExperimentalApi(issue = "https://github.com/ydb-platform/yoj-project/issues/32")
default <T extends Entity<T>> Table<T> table(Class<T> c, String name) {
return table(c);
default <T extends Entity<T>> Table<T> table(TableDescriptor<T> descriptor) {
return table(descriptor.entityType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected AbstractDelegatingTable() {

@ExperimentalApi(issue = "https://github.com/ydb-platform/yoj-project/issues/32")
protected AbstractDelegatingTable(@NonNull String tableName) {
this.target = BaseDb.current(BaseDb.class).table(resolveEntityType(), tableName);
this.target = BaseDb.current(BaseDb.class).table(TableDescriptor.from(EntitySchema.of(resolveEntityType()), tableName));
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 40ab237

Please sign in to comment.