Skip to content

Commit

Permalink
Remove static findRange() and findAll() methods from YqlStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lavrukov committed Dec 4, 2024
1 parent 844386f commit f4dc5d5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f4dc5d5

Please sign in to comment.