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:
DeleteAllStatement,FindAllYqlStatement,FindRangeStatement,FindYqlStatement,MultipleVarsYqlStatement,PredicateStatement,UpdateByIdStatement,UpdateInStatement
-
Nested Class Summary
Nested classes/interfaces inherited from interface tech.ydb.yoj.repository.ydb.statement.Statement
Statement.QueryType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Collector<tech.ydb.proto.ValueProtos.Value.Builder,tech.ydb.proto.ValueProtos.Value.Builder, tech.ydb.proto.ValueProtos.Value.Builder> protected static final YqlOrderByprotected final ResultSetReader<RESULT>protected final tech.ydb.yoj.repository.db.EntitySchema<ENTITY>protected final tech.ydb.yoj.repository.db.TableDescriptor<ENTITY> -
Constructor Summary
ConstructorsConstructorDescriptionYqlStatement(tech.ydb.yoj.repository.db.EntitySchema<ENTITY> schema, Schema<RESULT> resultSchema) Deprecated, for removal: This API element is subject to removal in a future version.YqlStatement(tech.ydb.yoj.repository.db.TableDescriptor<ENTITY> tableDescriptor, tech.ydb.yoj.repository.db.EntitySchema<ENTITY> schema, Schema<RESULT> resultSchema) -
Method Summary
Modifier and TypeMethodDescriptionprotected tech.ydb.proto.ValueProtos.TypedValuecreateTQueryParameter(YqlType type, Object o, boolean optional) protected Stringbooleanprotected StringgetDeclaration(String name, String type) protected Collection<YqlStatementParam>protected tech.ydb.proto.ValueProtos.Type.BuildergetYqlType(YqlType yqlType, boolean optional) protected tech.ydb.proto.ValueProtos.Value.BuildergetYqlValue(YqlType type, Object value) inthashCode()booleanTells 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.protected static Stream<? extends YqlStatementPart<?>>mergeParts(Collection<? extends YqlStatementPart<?>> origParts) Tries to combine/simplify the specifiedstatement parts into a potentially smaller number of statement parts, e.g., joining multipleYqlPredicates into a singleANDclause (AndPredicate).protected static Stream<? extends YqlStatementPart<?>>mergeParts(Stream<? extends YqlStatementPart<?>> origParts) Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated and will be removed in YOJ 3.0.0.protected Stringprotected StringoutNames()readResult(List<tech.ydb.proto.ValueProtos.Column> columns, tech.ydb.proto.ValueProtos.Value value) Converts YDB result set into the query result.protected StringresolveParamNames(String yql) Resolves?placeholders to respective statement parameters' names, and{entity.java.field}placeholders to DB field names.voidstoreToCache(PARAMS params, List<RESULT> result, tech.ydb.yoj.repository.db.cache.RepositoryCache cache) Writes the query result to first-level cache.protected StringtoQueryParameters(PARAMS params) Returns the query's parameter values as YDB protobuf structures.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface tech.ydb.yoj.repository.ydb.statement.Statement
getQuery, getQueryType, readFromCache, toDebugString
-
Field Details
-
itemsCollector
protected static final Collector<tech.ydb.proto.ValueProtos.Value.Builder,tech.ydb.proto.ValueProtos.Value.Builder, itemsCollectortech.ydb.proto.ValueProtos.Value.Builder> -
ORDER_BY_ID_ASCENDING
-
schema
-
resultSchema
-
resultSetReader
-
tableDescriptor
-
-
Constructor Details
-
YqlStatement
@Deprecated(forRemoval=true) public YqlStatement(tech.ydb.yoj.repository.db.EntitySchema<ENTITY> schema, Schema<RESULT> resultSchema) Deprecated, for removal: This API element is subject to removal in a future version.Use constructor withTableDescriptorfor selecting correct entity table -
YqlStatement
-
-
Method Details
-
storeToCache
public void storeToCache(PARAMS params, List<RESULT> result, tech.ydb.yoj.repository.db.cache.RepositoryCache cache) Description copied from interface:StatementWrites the query result to first-level cache.- Specified by:
storeToCachein interfaceStatement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> - Parameters:
params- parameter values Might benulldepending on the statement type, e.g. for DELETE statements.result- result to save; ifnull, nothing will be saved to cachecache- first-level cache
-
getDeclaration
-
mergeParts
@Deprecated(forRemoval=true) protected static Stream<? extends YqlStatementPart<?>> mergeParts(Stream<? extends YqlStatementPart<?>> origParts) Deprecated, for removal: This API element is subject to removal in a future version.This method is deprecated and will be removed in YOJ 3.0.0. Please usemergeParts(Collection)instead.Tries to combine/simplify the specifiedstatement parts into a potentially smaller number of statement parts, e.g., joining multipleYqlPredicates into a singleANDclause (AndPredicate).
Note that this method does not attempt to sort statement parts bypriorityor perform any YQL code generation at all.Warning: A closed/consumed or a partially consumed
Streamcould have potentially been passed to this method. But in all cases that we know of (both standard and customYqlStatements), this method was always fed a fresh stream, obtained by callingsomeCollection.stream(). This method is now replaced by the less error-pronemergeParts(Collection). -
mergeParts
protected static Stream<? extends YqlStatementPart<?>> mergeParts(Collection<? extends YqlStatementPart<?>> origParts) Tries to combine/simplify the specifiedstatement parts into a potentially smaller number of statement parts, e.g., joining multipleYqlPredicates into a singleANDclause (AndPredicate).
Note that this method does not attempt to sort statement parts bypriorityor perform any YQL code generation at all.- Parameters:
origParts- original collection ofstatement parts- Returns:
- a fresh stream containing potentially combined
statement parts
-
isPreparable
public boolean isPreparable()Description copied from interface:StatementTells 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:
isPreparablein interfaceStatement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> - Returns:
trueif the statement should be prepared;falseotherwise
-
toQueryParameters
Description copied from interface:StatementReturns the query's parameter values as YDB protobuf structures.- Specified by:
toQueryParametersin interfaceStatement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> - Parameters:
params- parameter values Might benulldepending on the statement type, e.g. for DELETE statements.- Returns:
- map: parameter name -> value as protobuf
-
createTQueryParameter
-
getYqlType
-
getYqlValue
-
readResult
public RESULT readResult(List<tech.ydb.proto.ValueProtos.Column> columns, tech.ydb.proto.ValueProtos.Value value) Description copied from interface:StatementConverts YDB result set into the query result.- Specified by:
readResultin interfaceStatement<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> - Parameters:
columns- result set as a YDB protobuf structurevalue- result set as a YDB protobuf structure- Returns:
- query result
-
toString
-
equals
-
hashCode
public int hashCode() -
getInSchemaType
-
getParams
-
declarations
-
outNames
-
nameEqVars
-
table
-
escape
-
resolveParamNames
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
-
TableDescriptorfor selecting correct entity table