From 0a72816ccb8c4156e0f181056fb8b046ef5a631b Mon Sep 17 00:00:00 2001 From: Alexander Lavrukov Date: Thu, 5 Dec 2024 00:01:52 +0300 Subject: [PATCH] Remove static count(), delete() and deleteAll() methods from YqlStatement (#104) Co-authored-by: Alexander Lavrukov --- .../ydb/merge/ByEntityYqlQueriesMerger.java | 7 ++- .../ydb/statement/CountAllStatement.java | 28 +++-------- .../ydb/statement/DeleteAllStatement.java | 11 ++-- .../ydb/statement/DeleteByIdStatement.java | 9 ++-- .../ydb/statement/FindStatement.java | 3 +- .../ydb/statement/InsertYqlStatement.java | 9 ++-- .../statement/MultipleVarsYqlStatement.java | 4 ++ .../ydb/statement/UpdateByIdStatement.java | 8 +-- .../ydb/statement/UpsertYqlStatement.java | 9 ++-- .../ydb/statement/YqlStatement.java | 50 ------------------- .../yoj/repository/ydb/table/YdbTable.java | 21 +++++--- .../yoj/repository/ydb/yql/YqlPredicate.java | 7 +++ .../ydb/YdbRepositoryCacheTest.java | 4 +- .../ydb/merge/QueriesMergerTest.java | 13 +++-- .../statement/DeleteByIdStatementTest.java | 3 +- .../ydb/statement/InsertYqlStatementTest.java | 3 +- .../ydb/statement/UpsertYqlStatementTest.java | 3 +- 17 files changed, 68 insertions(+), 124 deletions(-) diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/merge/ByEntityYqlQueriesMerger.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/merge/ByEntityYqlQueriesMerger.java index 438b2f01..eab4279c 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/merge/ByEntityYqlQueriesMerger.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/merge/ByEntityYqlQueriesMerger.java @@ -6,11 +6,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import tech.ydb.yoj.repository.db.Entity; +import tech.ydb.yoj.repository.db.EntitySchema; import tech.ydb.yoj.repository.db.cache.RepositoryCache; import tech.ydb.yoj.repository.db.exception.EntityAlreadyExistsException; import tech.ydb.yoj.repository.ydb.YdbRepository; import tech.ydb.yoj.repository.ydb.exception.YdbRepositoryException; +import tech.ydb.yoj.repository.ydb.statement.DeleteByIdStatement; import tech.ydb.yoj.repository.ydb.statement.Statement; +import tech.ydb.yoj.repository.ydb.statement.UpsertYqlStatement; import tech.ydb.yoj.repository.ydb.statement.YqlStatement; import java.util.ArrayList; @@ -158,12 +161,12 @@ private MergingState doTransition(MergingState state, Statement.QueryType nextQu @SuppressWarnings("unchecked") private static YdbRepository.Query convertInsertToUpsert(YdbRepository.Query query) { - return new YdbRepository.Query<>(YqlStatement.save(getEntityClass(query)), query.getValues().get(0)); + return new YdbRepository.Query<>(new UpsertYqlStatement<>(EntitySchema.of(getEntityClass(query))), query.getValues().get(0)); } @SuppressWarnings("unchecked") private static YdbRepository.Query convertInsertToDelete(YdbRepository.Query query) { - return new YdbRepository.Query<>(YqlStatement.delete(getEntityClass(query)), getEntityId(query)); + return new YdbRepository.Query<>(new DeleteByIdStatement<>(EntitySchema.of(getEntityClass(query))), getEntityId(query)); } private static Entity.Id getEntityId(YdbRepository.Query query) { diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/CountAllStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/CountAllStatement.java index 1fdb8236..a054e0bb 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/CountAllStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/CountAllStatement.java @@ -1,38 +1,22 @@ package tech.ydb.yoj.repository.ydb.statement; -import tech.ydb.yoj.databind.schema.Schema; +import tech.ydb.yoj.databind.schema.ObjectSchema; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.EntitySchema; import tech.ydb.yoj.repository.ydb.yql.YqlPredicate; import tech.ydb.yoj.repository.ydb.yql.YqlStatementPart; import java.util.Collection; -import java.util.function.Function; +import java.util.List; import static java.util.Comparator.comparing; import static java.util.stream.Collectors.joining; -class CountAllStatement> extends PredicateStatement>, ENTITY, Count> { - private final Collection> parts; +public class CountAllStatement> extends PredicateStatement>, ENTITY, Count> { + private final List> parts; - public CountAllStatement( - EntitySchema schema, - Schema resultSchema, - Collection> parts, - Function>, YqlPredicate> predicateFrom - ) { - super(schema, resultSchema, parts, predicateFrom); - this.parts = parts; - } - - public CountAllStatement( - EntitySchema schema, - Schema resultSchema, - Collection> parts, - Function>, YqlPredicate> predicateFrom, - String tableName - ) { - super(schema, resultSchema, parts, predicateFrom, tableName); + public CountAllStatement(EntitySchema schema, List> parts) { + super(schema, ObjectSchema.of(Count.class), parts, YqlPredicate::from); this.parts = parts; } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteAllStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteAllStatement.java index 1a3f57ed..3552ccfc 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteAllStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteAllStatement.java @@ -1,16 +1,11 @@ package tech.ydb.yoj.repository.ydb.statement; -import lombok.NonNull; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.EntitySchema; -class DeleteAllStatement> extends YqlStatement { - public DeleteAllStatement(@NonNull Class type) { - super(EntitySchema.of(type), EntitySchema.of(type)); - } - - public DeleteAllStatement(@NonNull EntitySchema schema, String tableName) { - super(schema, schema, tableName); +public class DeleteAllStatement> extends YqlStatement { + public DeleteAllStatement(EntitySchema schema) { + super(schema, schema); } @Override diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatement.java index 9e5b6772..bbec2595 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatement.java @@ -1,17 +1,14 @@ package tech.ydb.yoj.repository.ydb.statement; import tech.ydb.yoj.repository.db.Entity; +import tech.ydb.yoj.repository.db.EntitySchema; import java.util.Map; import java.util.function.Function; public class DeleteByIdStatement> extends MultipleVarsYqlStatement.Simple { - DeleteByIdStatement(Class type) { - super(type); - } - - DeleteByIdStatement(Class type, String tableName) { - super(type, tableName); + public DeleteByIdStatement(EntitySchema schema) { + super(schema); } @Override diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java index 2dd1df3a..c26ab3b3 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindStatement.java @@ -5,6 +5,7 @@ import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.EntitySchema; import tech.ydb.yoj.repository.ydb.yql.YqlOrderBy; +import tech.ydb.yoj.repository.ydb.yql.YqlPredicate; import tech.ydb.yoj.repository.ydb.yql.YqlStatementPart; import java.util.ArrayList; @@ -40,7 +41,7 @@ private FindStatement( @NonNull List> parts, boolean distinct ) { - super(schema, outSchema, parts, YqlStatement::predicateFrom); + super(schema, outSchema, parts, YqlPredicate::from); this.distinct = distinct; this.parts = parts; } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatement.java index c3907e7b..c9f25d9a 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatement.java @@ -1,17 +1,14 @@ package tech.ydb.yoj.repository.ydb.statement; import tech.ydb.yoj.repository.db.Entity; +import tech.ydb.yoj.repository.db.EntitySchema; import java.util.Map; import java.util.function.Function; public class InsertYqlStatement> extends MultipleVarsYqlStatement.Simple { - public InsertYqlStatement(Class type) { - super(type); - } - - public InsertYqlStatement(Class type, String tableName) { - super(type, tableName); + public InsertYqlStatement(EntitySchema schema) { + super(schema); } @Override diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/MultipleVarsYqlStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/MultipleVarsYqlStatement.java index 2c3e076c..3c8ce045 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/MultipleVarsYqlStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/MultipleVarsYqlStatement.java @@ -104,5 +104,9 @@ public Simple(@NonNull Class type) { public Simple(@NonNull Class type, String tableName) { super(EntitySchema.of(type), EntitySchema.of(type), tableName); } + + public Simple(EntitySchema schema) { + super(schema, schema); + } } } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateByIdStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateByIdStatement.java index ba318e7e..8c1646cb 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateByIdStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateByIdStatement.java @@ -24,12 +24,8 @@ public final class UpdateByIdStatement, ID extends private final Set idParams; - public UpdateByIdStatement(Class type, UpdateModel.ById model) { - this(type, model, EntitySchema.of(type).getName()); - } - - public UpdateByIdStatement(Class type, UpdateModel.ById model, String tableName) { - super(EntitySchema.of(type), EntitySchema.of(type), tableName); + public UpdateByIdStatement(EntitySchema schema, UpdateModel.ById model) { + super(schema, schema); this.idParams = schema.flattenId().stream() .map(c -> YqlStatementParam.required(YqlType.of(c), c.getName())) .collect(toUnmodifiableSet()); diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatement.java index 6e117295..b2eceeb5 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatement.java @@ -1,17 +1,14 @@ package tech.ydb.yoj.repository.ydb.statement; import tech.ydb.yoj.repository.db.Entity; +import tech.ydb.yoj.repository.db.EntitySchema; import java.util.Map; import java.util.function.Function; public class UpsertYqlStatement> extends MultipleVarsYqlStatement.Simple { - public UpsertYqlStatement(Class type) { - super(type); - } - - public UpsertYqlStatement(Class type, String tableName) { - super(type, tableName); + public UpsertYqlStatement(EntitySchema schema) { + super(schema); } @Override diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/YqlStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/YqlStatement.java index db8e2f3f..84063d99 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/YqlStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/YqlStatement.java @@ -4,7 +4,6 @@ import com.google.protobuf.NullValue; import lombok.NonNull; import tech.ydb.proto.ValueProtos; -import tech.ydb.yoj.databind.schema.ObjectSchema; import tech.ydb.yoj.databind.schema.Schema; import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.EntityIdSchema; @@ -14,7 +13,6 @@ import tech.ydb.yoj.repository.db.ViewSchema; import tech.ydb.yoj.repository.db.cache.RepositoryCache; import tech.ydb.yoj.repository.ydb.yql.YqlOrderBy; -import tech.ydb.yoj.repository.ydb.yql.YqlPredicate; import tech.ydb.yoj.repository.ydb.yql.YqlStatementPart; import tech.ydb.yoj.repository.ydb.yql.YqlType; @@ -55,25 +53,6 @@ public YqlStatement(@NonNull EntitySchema schema, @NonNull Schema> Statement insert( - Class type - ) { - return new InsertYqlStatement<>(type); - } - - public static , ID extends Entity.Id> Statement, ?> update( - Class type, - UpdateModel.ById model - ) { - return new UpdateByIdStatement<>(type, model); - } - - public static > Statement save( - Class type - ) { - return new UpsertYqlStatement<>(type); - } - public static , ID extends Entity.Id> Statement, ENTITY> findRange( Class type, Range range @@ -138,27 +117,6 @@ public String getDeclaration(String name, String type) { return String.format("DECLARE %s AS %s;\n", name, type); } - public static > Statement>, Count> count( - Class entityType, - Collection> parts - ) { - return count(EntitySchema.of(entityType), parts); - } - - private static > Statement>, Count> count( - EntitySchema schema, - Collection> parts - ) { - return new CountAllStatement<>(schema, ObjectSchema.of(Count.class), parts, YqlStatement::predicateFrom); - } - - protected static YqlPredicate predicateFrom(Collection> parts) { - return parts.stream() - .filter(p -> p instanceof YqlPredicate) - .map(YqlPredicate.class::cast) - .reduce(YqlPredicate.alwaysTrue(), (p1, p2) -> p1.and(p2)); - } - protected static Stream> mergeParts(Stream> origParts) { return origParts .collect(groupingBy(YqlStatementPart::getType)) @@ -175,14 +133,6 @@ private static List> combine(List>) first.combine((List) items.subList(1, items.size())); } - public static > Statement deleteAll(Class type) { - return new DeleteAllStatement<>(type); - } - - public static > Statement delete(Class type) { - return new DeleteByIdStatement<>(type); - } - @Override public boolean isPreparable() { return true; diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java index c577327a..2ee45be2 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java @@ -24,12 +24,18 @@ import tech.ydb.yoj.repository.ydb.bulk.BulkMapperImpl; import tech.ydb.yoj.repository.ydb.readtable.EntityIdKeyMapper; import tech.ydb.yoj.repository.ydb.readtable.ReadTableMapper; +import tech.ydb.yoj.repository.ydb.statement.CountAllStatement; +import tech.ydb.yoj.repository.ydb.statement.DeleteAllStatement; +import tech.ydb.yoj.repository.ydb.statement.DeleteByIdStatement; import tech.ydb.yoj.repository.ydb.statement.FindInStatement; import tech.ydb.yoj.repository.ydb.statement.FindStatement; import tech.ydb.yoj.repository.ydb.statement.FindYqlStatement; +import tech.ydb.yoj.repository.ydb.statement.InsertYqlStatement; import tech.ydb.yoj.repository.ydb.statement.Statement; +import tech.ydb.yoj.repository.ydb.statement.UpdateByIdStatement; import tech.ydb.yoj.repository.ydb.statement.UpdateInStatement; import tech.ydb.yoj.repository.ydb.statement.UpdateModel; +import tech.ydb.yoj.repository.ydb.statement.UpsertYqlStatement; import tech.ydb.yoj.repository.ydb.statement.YqlStatement; import tech.ydb.yoj.repository.ydb.yql.YqlLimit; import tech.ydb.yoj.repository.ydb.yql.YqlListingQuery; @@ -182,7 +188,7 @@ public List findAll(Class viewType) { @Override public void deleteAll() { - executor.pendingExecute(YqlStatement.deleteAll(type), null); + executor.pendingExecute(new DeleteAllStatement<>(schema), null); } @Override @@ -390,7 +396,8 @@ public static > List... parts) { List> partsList = asList(parts); - return executor.execute(YqlStatement.count(type, partsList), partsList).get(0).getCount(); + var statement = new CountAllStatement<>(schema, partsList); + return executor.execute(statement, partsList).get(0).getCount(); } public List find(Class viewType, YqlStatementPart part, YqlStatementPart... otherParts) { @@ -432,13 +439,13 @@ public > List findIds(Set partialIds) { @Override public void update(Entity.Id id, Changeset changeset) { UpdateModel.ById> model = new UpdateModel.ById<>(id, changeset.toMap()); - executor.pendingExecute(YqlStatement.update(type, model), model); + executor.pendingExecute(new UpdateByIdStatement<>(schema, model), model); } @Override public T insert(T t) { T entityToSave = t.preSave(); - executor.pendingExecute(YqlStatement.insert(type), entityToSave); + executor.pendingExecute(new InsertYqlStatement<>(schema), entityToSave); executor.getTransactionLocal().firstLevelCache().put(entityToSave); executor.getTransactionLocal().projectionCache().save(entityToSave); return t; @@ -447,7 +454,7 @@ public T insert(T t) { @Override public T save(T t) { T entityToSave = t.preSave(); - executor.pendingExecute(YqlStatement.save(type), entityToSave); + executor.pendingExecute(new UpsertYqlStatement<>(schema), entityToSave); executor.getTransactionLocal().firstLevelCache().put(entityToSave); executor.getTransactionLocal().projectionCache().save(entityToSave); return t; @@ -455,7 +462,7 @@ public T save(T t) { @Override public void delete(Entity.Id id) { - executor.pendingExecute(YqlStatement.delete(type), id); + executor.pendingExecute(new DeleteByIdStatement<>(schema), id); executor.getTransactionLocal().firstLevelCache().putEmpty(id); executor.getTransactionLocal().projectionCache().delete(id); } @@ -477,7 +484,7 @@ public > void migrate(ID id) { } T rawEntity = foundRaw.get(0); T entityToSave = rawEntity.postLoad().preSave(); - executor.pendingExecute(YqlStatement.save(type), entityToSave); + executor.pendingExecute(new UpsertYqlStatement<>(schema), entityToSave); executor.getTransactionLocal().projectionCache().save(entityToSave); } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPredicate.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPredicate.java index 6383d3db..ccd62cdd 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPredicate.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/yql/YqlPredicate.java @@ -76,6 +76,13 @@ public static void setUseLegacyRel(boolean value) { YqlPredicate.useLegacyRel.set(value); } + public static YqlPredicate from(Collection> parts) { + return parts.stream() + .filter(p -> p instanceof YqlPredicate) + .map(YqlPredicate.class::cast) + .reduce(YqlPredicate.alwaysTrue(), (p1, p2) -> p1.and(p2)); + } + public static FieldPredicateBuilder where(@NonNull String fieldPath) { return new FieldPredicateBuilder(fieldPath, UnaryOperator.identity()); } diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YdbRepositoryCacheTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YdbRepositoryCacheTest.java index 1b9474fc..25393589 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YdbRepositoryCacheTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/YdbRepositoryCacheTest.java @@ -24,7 +24,7 @@ import tech.ydb.yoj.repository.ydb.client.YdbConverter; import tech.ydb.yoj.repository.ydb.statement.FindYqlStatement; import tech.ydb.yoj.repository.ydb.statement.MultipleVarsYqlStatement; -import tech.ydb.yoj.repository.ydb.statement.YqlStatement; +import tech.ydb.yoj.repository.ydb.statement.UpsertYqlStatement; import java.util.ArrayList; import java.util.HashSet; @@ -324,7 +324,7 @@ private List createComplexesList() { private CompletableFuture> convertEntity(List complexes) { ValueProtos.ResultSet.Builder builder = ValueProtos.ResultSet.newBuilder(); complexes.stream() - .map(complex -> YqlStatement.save(Complex.class).toQueryParameters(complex)) + .map(complex -> new UpsertYqlStatement<>(EntitySchema.of(Complex.class)).toQueryParameters(complex)) .map(map -> YdbConverter.convertToParams(map).values().get(MultipleVarsYqlStatement.listName)) .peek(value -> { if (builder.getColumnsCount() == 0) { diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/merge/QueriesMergerTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/merge/QueriesMergerTest.java index f6fa46e0..e02e9a13 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/merge/QueriesMergerTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/merge/QueriesMergerTest.java @@ -9,9 +9,12 @@ import tech.ydb.yoj.repository.test.sample.model.Primitive; import tech.ydb.yoj.repository.test.sample.model.Project; import tech.ydb.yoj.repository.ydb.YdbRepository; +import tech.ydb.yoj.repository.ydb.statement.DeleteAllStatement; +import tech.ydb.yoj.repository.ydb.statement.DeleteByIdStatement; import tech.ydb.yoj.repository.ydb.statement.FindYqlStatement; +import tech.ydb.yoj.repository.ydb.statement.InsertYqlStatement; import tech.ydb.yoj.repository.ydb.statement.Statement; -import tech.ydb.yoj.repository.ydb.statement.YqlStatement; +import tech.ydb.yoj.repository.ydb.statement.UpsertYqlStatement; import java.util.ArrayList; import java.util.Collections; @@ -141,17 +144,17 @@ private QueriesMerger createMerger() { } private > YdbRepository.Query deleteAll(Class clazz) { - return new YdbRepository.Query<>(YqlStatement.deleteAll(clazz), null); + return new YdbRepository.Query<>(new DeleteAllStatement<>(EntitySchema.of(clazz)), null); } @SuppressWarnings("unchecked") private > YdbRepository.Query upsert(T p) { - return new YdbRepository.Query<>(YqlStatement.save((Class) p.getClass()), p); + return new YdbRepository.Query<>(new UpsertYqlStatement<>(EntitySchema.of((Class) p.getClass())), p); } @SuppressWarnings("unchecked") private > YdbRepository.Query insert(T p) { - return new YdbRepository.Query<>(YqlStatement.insert((Class) p.getClass()), p); + return new YdbRepository.Query<>(new InsertYqlStatement<>(EntitySchema.of((Class) p.getClass())), p); } @SuppressWarnings("unchecked") @@ -163,7 +166,7 @@ private > YdbRepository.Query find(T p) { @SuppressWarnings("unchecked") private > YdbRepository.Query delete(T p) { - return new YdbRepository.Query<>(YqlStatement.delete((Class) p.getClass()), p.getId()); + return new YdbRepository.Query<>(new DeleteByIdStatement<>(EntitySchema.of((Class) p.getClass())), p.getId()); } private ArrayList getProjects() { diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatementTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatementTest.java index d9390c32..701d7a33 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatementTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/DeleteByIdStatementTest.java @@ -1,6 +1,7 @@ package tech.ydb.yoj.repository.ydb.statement; import org.junit.Test; +import tech.ydb.yoj.repository.db.EntitySchema; import static org.assertj.core.api.Assertions.assertThat; @@ -24,7 +25,7 @@ public void testDelete() { txManager.tx(() -> { var db = getTestDb(); - var deleteStatement = new DeleteByIdStatement<>(TestEntity.class); + var deleteStatement = new DeleteByIdStatement<>(EntitySchema.of(TestEntity.class)); db.pendingExecute(deleteStatement, ENTITY_1.getId()); db.pendingExecute(deleteStatement, ENTITY_3.getId()); diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatementTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatementTest.java index 8c2666bb..15b927e1 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatementTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/InsertYqlStatementTest.java @@ -1,6 +1,7 @@ package tech.ydb.yoj.repository.ydb.statement; import org.junit.Test; +import tech.ydb.yoj.repository.db.EntitySchema; import static org.assertj.core.api.Assertions.assertThat; @@ -18,7 +19,7 @@ public void testInsert() { txManager.tx(() -> { var db = getTestDb(); - var deleteStatement = new InsertYqlStatement<>(TestEntity.class); + var deleteStatement = new InsertYqlStatement<>(EntitySchema.of(TestEntity.class)); db.pendingExecute(deleteStatement, ENTITY_2); db.pendingExecute(deleteStatement, ENTITY_3); diff --git a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatementTest.java b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatementTest.java index d6202740..db922faa 100644 --- a/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatementTest.java +++ b/repository-ydb-v2/src/test/java/tech/ydb/yoj/repository/ydb/statement/UpsertYqlStatementTest.java @@ -1,6 +1,7 @@ package tech.ydb.yoj.repository.ydb.statement; import org.junit.Test; +import tech.ydb.yoj.repository.db.EntitySchema; import static org.assertj.core.api.Assertions.assertThat; @@ -18,7 +19,7 @@ public void testUpsert() { txManager.tx(() -> { var db = getTestDb(); - var deleteStatement = new UpsertYqlStatement<>(TestEntity.class); + var deleteStatement = new UpsertYqlStatement<>(EntitySchema.of(TestEntity.class)); db.pendingExecute(deleteStatement, ENTITY_1_1); db.pendingExecute(deleteStatement, ENTITY_2);