diff --git a/repository-inmemory/src/main/java/tech/ydb/yoj/repository/test/inmemory/InMemoryTable.java b/repository-inmemory/src/main/java/tech/ydb/yoj/repository/test/inmemory/InMemoryTable.java index 3779071e..669bd9b5 100644 --- a/repository-inmemory/src/main/java/tech/ydb/yoj/repository/test/inmemory/InMemoryTable.java +++ b/repository-inmemory/src/main/java/tech/ydb/yoj/repository/test/inmemory/InMemoryTable.java @@ -48,7 +48,7 @@ public InMemoryTable(InMemoryRepositoryTransaction transaction, Class type) { public InMemoryTable(InMemoryRepositoryTransaction transaction, TableDescriptor tableDescriptor) { this.schema = EntitySchema.of(tableDescriptor.entityType()); - this.tableDescriptor = TableDescriptor.from(schema); + this.tableDescriptor = tableDescriptor; this.transaction = transaction; } diff --git a/repository-test/src/main/java/tech/ydb/yoj/repository/test/RepositoryTest.java b/repository-test/src/main/java/tech/ydb/yoj/repository/test/RepositoryTest.java index 527f931e..c84dc4da 100644 --- a/repository-test/src/main/java/tech/ydb/yoj/repository/test/RepositoryTest.java +++ b/repository-test/src/main/java/tech/ydb/yoj/repository/test/RepositoryTest.java @@ -1363,6 +1363,29 @@ public void testUniqueIndex() { assertThrows(EntityAlreadyExistsException.class, () -> db.tx(() -> db.table(UniqueProject.class).save(ue2))); } + @Test + public void testUsingSecondTable() { + String verySameName = "valuableName"; + UniqueProject ue1 = new UniqueProject(new UniqueProject.Id("id1"), verySameName, 1); + db.tx(() -> { + db.table(UniqueProject.class).save(ue1); + db.table(TestEntities.SECOND_UNIQUE_PROJECT_TABLE).save(ue1.withVersion(2)); + }); + UniqueProject firstTableProject = db.tx(() -> db.table(UniqueProject.class).find(ue1.getId())); + UniqueProject secondTableProject = db.tx(() -> db.table(TestEntities.SECOND_UNIQUE_PROJECT_TABLE).find(ue1.getId())); + + assertThat(firstTableProject.getVersion()).isEqualTo(1); + assertThat(secondTableProject.getVersion()).isEqualTo(2); + + db.tx(() -> db.table(UniqueProject.class).delete(ue1.getId())); + + firstTableProject = db.tx(() -> db.table(UniqueProject.class).find(ue1.getId())); + secondTableProject = db.tx(() -> db.table(TestEntities.SECOND_UNIQUE_PROJECT_TABLE).find(ue1.getId())); + + assertThat(firstTableProject).isNull(); + assertThat(secondTableProject.getVersion()).isEqualTo(2); + } + @Test public void doubleTxIsOk() { db.tx(this::findRange); diff --git a/repository-test/src/main/java/tech/ydb/yoj/repository/test/entity/TestEntities.java b/repository-test/src/main/java/tech/ydb/yoj/repository/test/entity/TestEntities.java index 8dc7582b..2d3c8729 100644 --- a/repository-test/src/main/java/tech/ydb/yoj/repository/test/entity/TestEntities.java +++ b/repository-test/src/main/java/tech/ydb/yoj/repository/test/entity/TestEntities.java @@ -3,6 +3,7 @@ import lombok.NonNull; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.Repository; +import tech.ydb.yoj.repository.db.TableDescriptor; import tech.ydb.yoj.repository.test.sample.model.Book; import tech.ydb.yoj.repository.test.sample.model.Bubble; import tech.ydb.yoj.repository.test.sample.model.BytePkEntity; @@ -30,6 +31,10 @@ import java.util.List; public final class TestEntities { + public static final TableDescriptor SECOND_UNIQUE_PROJECT_TABLE = new TableDescriptor<>( + UniqueProject.class, "second_uniq_project_table" + ); + private TestEntities() { } @@ -54,11 +59,20 @@ private TestEntities() { MultiWrappedEntity.class ); + public static final List> ALL_TABLE_DESCRIPTORS = List.of( + SECOND_UNIQUE_PROJECT_TABLE + ); + + @SuppressWarnings("unchecked") public static Repository init(@NonNull Repository repository) { repository.createTablespace(); ALL.forEach(entityClass -> repository.schema(entityClass).create()); + for (TableDescriptor tableDescriptor : ALL_TABLE_DESCRIPTORS) { + repository.schema(tableDescriptor).create(); + } + return repository; } }