From f51eb59326786919ee513ea34e9937f383f41de6 Mon Sep 17 00:00:00 2001 From: Alexander Lavrukov <lavrukov@yandex-team.ru> Date: Wed, 4 Dec 2024 14:24:28 +0300 Subject: [PATCH] Remove static findRange() and findAll() methods from YqlStatement --- .../ydb/statement/FindAllYqlStatement.java | 4 -- .../ydb/statement/FindRangeStatement.java | 6 +-- .../statement/MultipleVarsYqlStatement.java | 13 ----- .../ydb/statement/PredicateStatement.java | 12 +---- .../ydb/statement/UpdateInStatement.java | 11 +---- .../ydb/statement/YqlStatement.java | 47 ------------------- .../yoj/repository/ydb/table/YdbTable.java | 21 ++++++--- 7 files changed, 18 insertions(+), 96 deletions(-) diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindAllYqlStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindAllYqlStatement.java index 40abc721..de530d53 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindAllYqlStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindAllYqlStatement.java @@ -11,10 +11,6 @@ public FindAllYqlStatement(@NonNull EntitySchema<ENTITY> schema, @NonNull Schema super(schema, resultSchema); } - public FindAllYqlStatement(@NonNull EntitySchema<ENTITY> schema, @NonNull Schema<RESULT> resultSchema, String tableName) { - super(schema, resultSchema, tableName); - } - @Override public String getQuery(String tablespace) { return declarations() diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindRangeStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindRangeStatement.java index f05dc623..a187bad1 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindRangeStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/FindRangeStatement.java @@ -24,11 +24,7 @@ public class FindRangeStatement<ENTITY extends Entity<ENTITY>, ID extends Entity private final List<YqlStatementParam> params; public FindRangeStatement(EntitySchema<ENTITY> schema, Schema<RESULT> outSchema, Range<ID> range) { - this(schema, outSchema, range, schema.getName()); - } - - public FindRangeStatement(EntitySchema<ENTITY> schema, Schema<RESULT> outSchema, Range<ID> range, String tableName) { - super(schema, outSchema, tableName); + super(schema, outSchema); this.params = Stream.of(RangeBound.values()) .flatMap(b -> toParams(b.map(range).keySet(), b)) .collect(toList()); 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 3c8ce045..ae5cf373 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 @@ -1,6 +1,5 @@ package tech.ydb.yoj.repository.ydb.statement; -import lombok.NonNull; import tech.ydb.proto.ValueProtos; import tech.ydb.yoj.databind.schema.Schema; import tech.ydb.yoj.repository.db.Entity; @@ -26,10 +25,6 @@ public MultipleVarsYqlStatement(EntitySchema<ENTITY> schema, Schema<RESULT> resu super(schema, resultSchema); } - public MultipleVarsYqlStatement(EntitySchema<ENTITY> schema, Schema<RESULT> resultSchema, String tableName) { - super(schema, resultSchema, tableName); - } - @Override protected String declarations() { String fieldPattern = escape("%s") + ":%s%s"; @@ -97,14 +92,6 @@ protected String toDebugParams(PARAMS params) { public abstract static class Simple<PARAMS, ENTITY extends Entity<ENTITY>> extends MultipleVarsYqlStatement<PARAMS, ENTITY, ENTITY> { - public Simple(@NonNull Class<ENTITY> type) { - super(EntitySchema.of(type), EntitySchema.of(type)); - } - - public Simple(@NonNull Class<ENTITY> type, String tableName) { - super(EntitySchema.of(type), EntitySchema.of(type), tableName); - } - public Simple(EntitySchema<ENTITY> schema) { super(schema, schema); } diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/PredicateStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/PredicateStatement.java index 8f4709fb..b5573cb5 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/PredicateStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/PredicateStatement.java @@ -39,17 +39,7 @@ public PredicateStatement( @NonNull PARAMS params, @NonNull Function<PARAMS, YqlPredicate> getPredicate ) { - this(schema, outSchema, params, getPredicate, schema.getName()); - } - - public PredicateStatement( - @NonNull EntitySchema<ENTITY> schema, - @NonNull Schema<RESULT> outSchema, - @NonNull PARAMS params, - @NonNull Function<PARAMS, YqlPredicate> getPredicate, - String tableName - ) { - super(schema, outSchema, tableName); + super(schema, outSchema); this.getPredicate = getPredicate; YqlPredicate pred = getPredicate.apply(params); diff --git a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateInStatement.java b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateInStatement.java index 9248fa46..15a07f58 100644 --- a/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateInStatement.java +++ b/repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/statement/UpdateInStatement.java @@ -37,16 +37,7 @@ public UpdateInStatement( Schema<RESULT> resultSchema, UpdateInStatementInput<T> in ) { - this(schema, resultSchema, in, schema.getName()); - } - - public UpdateInStatement( - EntitySchema<T> schema, - Schema<RESULT> resultSchema, - UpdateInStatementInput<T> in, - String tableName - ) { - super(schema, resultSchema, tableName); + super(schema, resultSchema); this.keyFields = collectKeyFields(in.ids); this.values = new HashMap<>(in.values.size()); 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 84063d99..361d7ed5 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 @@ -8,9 +8,6 @@ import tech.ydb.yoj.repository.db.Entity; import tech.ydb.yoj.repository.db.EntityIdSchema; import tech.ydb.yoj.repository.db.EntitySchema; -import tech.ydb.yoj.repository.db.Range; -import tech.ydb.yoj.repository.db.Table.View; -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.YqlStatementPart; @@ -53,50 +50,6 @@ public YqlStatement(@NonNull EntitySchema<ENTITY> schema, @NonNull Schema<RESULT this.tableName = tableName; } - public static <ENTITY extends Entity<ENTITY>, ID extends Entity.Id<ENTITY>> Statement<Range<ID>, ENTITY> findRange( - Class<ENTITY> type, - Range<ID> range - ) { - EntitySchema<ENTITY> schema = EntitySchema.of(type); - return new FindRangeStatement<>(schema, schema, range); - } - - public static <ENTITY extends Entity<ENTITY>, VIEW extends View, ID extends Entity.Id<ENTITY>> Statement<Range<ID>, VIEW> findRange( - Class<ENTITY> type, - Class<VIEW> viewType, - Range<ID> range - ) { - return new FindRangeStatement<>(EntitySchema.of(type), ViewSchema.of(viewType), range); - } - - public static <PARAMS, ENTITY extends Entity<ENTITY>> Statement<PARAMS, ENTITY> findAll( - Class<ENTITY> type - ) { - EntitySchema<ENTITY> schema = EntitySchema.of(type); - return findAll(schema, schema); - } - - public static <PARAMS, ENTITY extends Entity<ENTITY>, VIEW extends View> Statement<PARAMS, VIEW> findAll( - Class<ENTITY> type, - Class<VIEW> viewType - ) { - return findAll(EntitySchema.of(type), ViewSchema.of(viewType)); - } - - private static <PARAMS, ENTITY extends Entity<ENTITY>, RESULT> Statement<PARAMS, RESULT> findAll( - EntitySchema<ENTITY> schema, - Schema<RESULT> outSchema - ) { - return new FindAllYqlStatement<>(schema, outSchema); - } - - public static <ENTITY extends Entity<ENTITY>, ID extends Entity.Id<ENTITY>> Statement<Range<ID>, ID> findIds( - Class<ENTITY> type, - Range<ID> range - ) { - return new FindRangeStatement<>(EntitySchema.of(type), EntityIdSchema.ofEntity(type), range); - } - @Override public void storeToCache(PARAMS params, List<RESULT> result, RepositoryCache cache) { if (result == null) { 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 2ee45be2..ed8afec7 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 @@ -27,7 +27,9 @@ 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.FindAllYqlStatement; import tech.ydb.yoj.repository.ydb.statement.FindInStatement; +import tech.ydb.yoj.repository.ydb.statement.FindRangeStatement; import tech.ydb.yoj.repository.ydb.statement.FindStatement; import tech.ydb.yoj.repository.ydb.statement.FindYqlStatement; import tech.ydb.yoj.repository.ydb.statement.InsertYqlStatement; @@ -36,7 +38,6 @@ 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; import tech.ydb.yoj.repository.ydb.yql.YqlOrderBy; @@ -93,7 +94,8 @@ private static <E> List<E> toList(E first, E... rest) { @Override public List<T> findAll() { - return postLoad(executor.execute(YqlStatement.findAll(type), null)); + var statement = new FindAllYqlStatement<>(schema, schema); + return postLoad(executor.execute(statement, null)); } /** @@ -183,7 +185,9 @@ protected List<ID> find(YqlStatementPart<?> part, YqlStatementPart<?>... otherPa @Override public <V extends View> List<V> findAll(Class<V> viewType) { - return executor.execute(YqlStatement.findAll(type, viewType), null); + ViewSchema<V> viewSchema = ViewSchema.of(viewType); + var statement = new FindAllYqlStatement<>(schema, viewSchema); + return executor.execute(statement, null); } @Override @@ -248,12 +252,15 @@ public <V extends View> V find(Class<V> viewType, Entity.Id<T> id) { @Override public <ID extends Entity.Id<T>> List<T> find(Range<ID> range) { - return postLoad(executor.execute(YqlStatement.findRange(type, range), range)); + var statement = new FindRangeStatement<>(schema, schema, range); + return postLoad(executor.execute(statement, range)); } @Override public <V extends View, ID extends Entity.Id<T>> List<V> find(Class<V> viewType, Range<ID> range) { - return executor.execute(YqlStatement.findRange(type, viewType, range), range); + ViewSchema<V> viewSchema = ViewSchema.of(viewType); + var statement = new FindRangeStatement<>(schema, viewSchema, range); + return executor.execute(statement, range); } @Override @@ -422,7 +429,9 @@ private <ID extends Entity.Id<T>> List<ID> findIds(Collection<? extends YqlState @Override public <ID extends Entity.Id<T>> List<ID> findIds(Range<ID> range) { - return executor.execute(YqlStatement.findIds(type, range), range); + EntityIdSchema<ID> idSchema = EntityIdSchema.ofEntity(type); + var statement = new FindRangeStatement<>(schema, idSchema, range); + return executor.execute(statement, range); } @Override