Class YqlStatement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>,RESULT>

java.lang.Object
tech.ydb.yoj.repository.ydb.statement.YqlStatement<PARAMS,ENTITY,RESULT>
All Implemented Interfaces:
Statement<PARAMS,RESULT>
Direct Known Subclasses:
FindAllYqlStatement, FindRangeStatement, MultipleVarsYqlStatement, PredicateStatement, UpdateInStatement, YqlStatement.Simple

public abstract class YqlStatement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>,RESULT> extends Object implements Statement<PARAMS,RESULT>
  • Field Details

    • itemsCollector

      protected static final Collector<tech.ydb.proto.ValueProtos.Value.Builder,tech.ydb.proto.ValueProtos.Value.Builder,tech.ydb.proto.ValueProtos.Value.Builder> itemsCollector
    • ORDER_BY_ID_ASCENDING

      protected static final YqlOrderBy ORDER_BY_ID_ASCENDING
    • schema

      protected final tech.ydb.yoj.repository.db.EntitySchema<ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> schema
    • resultSchema

      protected final Schema<RESULT> resultSchema
    • resultSetReader

      protected final ResultSetReader<RESULT> resultSetReader
    • tableName

      protected final String tableName
  • Constructor Details

    • YqlStatement

      public YqlStatement(@NonNull @NonNull tech.ydb.yoj.repository.db.EntitySchema<ENTITY> schema, @NonNull @NonNull Schema<RESULT> resultSchema)
    • YqlStatement

      public YqlStatement(@NonNull @NonNull tech.ydb.yoj.repository.db.EntitySchema<ENTITY> schema, @NonNull @NonNull Schema<RESULT> resultSchema, @NonNull @NonNull String tableName)
  • Method Details

    • insert

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<PARAMS,ENTITY> insert(Class<ENTITY> type)
    • update

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, ID extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> Statement<UpdateModel.ById<ID>,?> update(Class<ENTITY> type, UpdateModel.ById<ID> model)
    • save

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<PARAMS,ENTITY> save(Class<ENTITY> type)
    • find

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<PARAMS,ENTITY> find(Class<ENTITY> type)
    • find

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, VIEW extends tech.ydb.yoj.repository.db.Table.View> Statement<PARAMS,VIEW> find(Class<ENTITY> type, Class<VIEW> viewType)
    • findRange

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, ID extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> Statement<tech.ydb.yoj.repository.db.Range<ID>,ENTITY> findRange(Class<ENTITY> type, tech.ydb.yoj.repository.db.Range<ID> range)
    • findRange

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, VIEW extends tech.ydb.yoj.repository.db.Table.View, ID extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> Statement<tech.ydb.yoj.repository.db.Range<ID>,VIEW> findRange(Class<ENTITY> type, Class<VIEW> viewType, tech.ydb.yoj.repository.db.Range<ID> range)
    • findIdsIn

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, ID extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> Statement<PARAMS,ID> findIdsIn(Class<ENTITY> type, Iterable<ID> ids, FilterExpression<ENTITY> filter, OrderExpression<ENTITY> orderBy, Integer limit)
    • findIn

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<PARAMS,ENTITY> findIn(Class<ENTITY> type, Iterable<? extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> ids, FilterExpression<ENTITY> filter, OrderExpression<ENTITY> orderBy, Integer limit)
    • findIn

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, VIEW extends tech.ydb.yoj.repository.db.Table.View> Statement<PARAMS,VIEW> findIn(Class<ENTITY> type, Class<VIEW> viewType, Iterable<? extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> ids, FilterExpression<ENTITY> filter, OrderExpression<ENTITY> orderBy, Integer limit)
    • findIn

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, K> Statement<PARAMS,ENTITY> findIn(Class<ENTITY> type, String indexName, Iterable<K> keys, FilterExpression<ENTITY> filter, OrderExpression<ENTITY> orderBy, Integer limit)
    • findIn

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, VIEW extends tech.ydb.yoj.repository.db.Table.View, K> Statement<PARAMS,VIEW> findIn(Class<ENTITY> type, Class<VIEW> viewType, String indexName, Iterable<K> keys, FilterExpression<ENTITY> filter, OrderExpression<ENTITY> orderBy, Integer limit)
    • findAll

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<PARAMS,ENTITY> findAll(Class<ENTITY> type)
    • findAll

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, VIEW extends tech.ydb.yoj.repository.db.Table.View> Statement<PARAMS,VIEW> findAll(Class<ENTITY> type, Class<VIEW> viewType)
    • find

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<Collection<? extends YqlStatementPart<?>>,ENTITY> find(Class<ENTITY> type, Collection<? extends YqlStatementPart<?>> parts)
    • find

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, VIEW extends tech.ydb.yoj.repository.db.Table.View> Statement<Collection<? extends YqlStatementPart<?>>,VIEW> find(Class<ENTITY> type, Class<VIEW> viewType, Collection<? extends YqlStatementPart<?>> parts)
    • find

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, VIEW extends tech.ydb.yoj.repository.db.Table.View> Statement<Collection<? extends YqlStatementPart<?>>,VIEW> find(Class<ENTITY> type, Class<VIEW> viewType, boolean distinct, Collection<? extends YqlStatementPart<?>> parts)
    • findIds

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, ID extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> Statement<Collection<? extends YqlStatementPart<?>>,ID> findIds(Class<ENTITY> type, Collection<? extends YqlStatementPart<?>> parts)
    • findIds

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>, ID extends tech.ydb.yoj.repository.db.Entity.Id<ENTITY>> Statement<tech.ydb.yoj.repository.db.Range<ID>,ID> findIds(Class<ENTITY> type, tech.ydb.yoj.repository.db.Range<ID> range)
    • storeToCache

      public void storeToCache(PARAMS params, List<RESULT> result, tech.ydb.yoj.repository.db.cache.RepositoryCache cache)
      Description copied from interface: Statement
      Writes the query result to first-level cache.
      Specified by:
      storeToCache in interface Statement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>>
      Parameters:
      params - parameter values Might be null depending on the statement type, e.g. for DELETE statements.
      result - result to save; if null, nothing will be saved to cache
      cache - first-level cache
    • getDeclaration

      public String getDeclaration(String name, String type)
    • count

      public static <ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<Collection<? extends YqlStatementPart<?>>,Count> count(Class<ENTITY> entityType, Collection<? extends YqlStatementPart<?>> parts)
    • predicateFrom

      protected static YqlPredicate predicateFrom(Collection<? extends YqlStatementPart<?>> parts)
    • mergeParts

      protected static Stream<? extends YqlStatementPart<?>> mergeParts(Stream<? extends YqlStatementPart<?>> origParts)
    • deleteAll

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<PARAMS,ENTITY> deleteAll(Class<ENTITY> type)
    • delete

      public static <PARAMS, ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Statement<PARAMS,ENTITY> delete(Class<ENTITY> type)
    • isPreparable

      public boolean isPreparable()
      Description copied from interface: Statement
      Tells whether the statement should be prepared, that is, parsed once and then cached for subsequent queries during the same session.
      Prepared statements offer better query performance, but consume additional memory.

      You should not blindly prepare all statements, especially non-parameterized ones; so by default this method returns false.

      Specified by:
      isPreparable in interface Statement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>>
      Returns:
      true if the statement should be prepared; false otherwise
    • toQueryParameters

      public Map<String,tech.ydb.proto.ValueProtos.TypedValue> toQueryParameters(PARAMS params)
      Description copied from interface: Statement
      Returns the query's parameter values as YDB protobuf structures.
      Specified by:
      toQueryParameters in interface Statement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>>
      Parameters:
      params - parameter values Might be null depending on the statement type, e.g. for DELETE statements.
      Returns:
      map: parameter name -> value as protobuf
    • createTQueryParameter

      protected tech.ydb.proto.ValueProtos.TypedValue createTQueryParameter(YqlType type, Object o, boolean optional)
    • getYqlType

      protected tech.ydb.proto.ValueProtos.Type.Builder getYqlType(YqlType yqlType, boolean optional)
    • getYqlValue

      protected tech.ydb.proto.ValueProtos.Value.Builder getYqlValue(YqlType type, Object value)
    • readResult

      public RESULT readResult(List<tech.ydb.proto.ValueProtos.Column> columns, tech.ydb.proto.ValueProtos.Value value)
      Description copied from interface: Statement
      Converts YDB result set into the query result.
      Specified by:
      readResult in interface Statement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>>
      Parameters:
      columns - result set as a YDB protobuf structure
      value - result set as a YDB protobuf structure
      Returns:
      query result
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getInSchemaType

      public Class<ENTITY> getInSchemaType()
    • getTableName

      @NonNull public @NonNull String getTableName()
    • getParams

      protected Collection<YqlStatementParam> getParams()
    • declarations

      protected String declarations()
    • outNames

      protected String outNames()
    • nameEqVars

      protected String nameEqVars()
    • table

      protected String table(String tablespace)
    • escape

      protected String escape(String value)
    • resolveParamNames

      protected String resolveParamNames(String yql)
      Resolves ? placeholders to respective statement parameters' names, and {entity.java.field} placeholders to DB field names.
      Parameters:
      yql - YQL with parameter and field name placeholders (? and {field.name}, respectively)
      Returns:
      YQL with real parameter names