Class SqlQueryContext<S,Q extends FlexibleRelationalPathBase<R>,R>
- java.lang.Object
-
- com.evolveum.midpoint.repo.sqlbase.SqlQueryContext<S,Q,R>
-
- Type Parameters:
S
- schema type, used by encapsulated mappingQ
- type of entity pathR
- row type related to theSqlQueryContext
- All Implemented Interfaces:
FilterProcessor<ObjectFilter>
public abstract class SqlQueryContext<S,Q extends FlexibleRelationalPathBase<R>,R> extends Object implements FilterProcessor<ObjectFilter>
Context information about SQL query. Works as a kind of accumulator where information are added as the object query is interpreted. It is also used as an entry point forFilterProcessor
processing for this query. And finally, it also executes the query, because this way it is more practical to contain all the needed parametrized types without using Class-type parameters.This object does not handle SQL connections or transaction in any way, any connection needed is provided from the outside.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PAGE_SIZE
Default page size if pagination is requested, that is offset is set, but maxSize is not.protected Q
entityPath
protected QueryTableMapping<S,Q,R>
entityPathMapping
static int
MAX_ID_IN_FOR_TO_MANY_FETCH
Number of values (identifiers) used in the IN clause to-many fetching selects.static long
NO_PAGINATION_LIMIT
If no other limit is used for query this limit will be used for sanity reasons.protected boolean
notFilterUsed
protected Collection<SelectorOptions<GetOperationOptions>>
options
protected com.querydsl.sql.SQLQuery<?>
sqlQuery
protected SqlRepoContext
sqlRepoContext
protected SqlTransformerSupport
transformerSupport
-
Constructor Summary
Constructors Modifier Constructor Description protected
SqlQueryContext(Q entityPath, QueryTableMapping<S,Q,R> mapping, SqlRepoContext sqlRepoContext, SqlTransformerSupport transformerSupport, com.querydsl.sql.SQLQuery<?> query)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CanonicalItemPath
createCanonicalItemPath(@NotNull ItemPath itemPath)
FilterProcessor<InOidFilter>
createInOidFilter(SqlQueryContext<?,?,?> context)
protected abstract SqlTransformer<S,Q,R>
createTransformer()
Creates transformer for theentityPathMapping
.protected abstract <DQ extends FlexibleRelationalPathBase<DR>,DR>
SqlQueryContext<?,DQ,DR>deriveNew(DQ newPath, QueryTableMapping<?,DQ,DR> newMapping)
int
executeCount(Connection conn)
PageOf<com.querydsl.core.Tuple>
executeQuery(Connection conn)
Returns page of results with each row represented by a Tuple containingSqlQueryContext
and then individual paths for extension columns, seeextensionColumns
inQueryTableMapping
.boolean
isNotFilterUsed()
<DQ extends FlexibleRelationalPathBase<DR>,DR>
SqlQueryContext<?,DQ,DR>leftJoin(@NotNull QueryTableMapping<?,DQ,DR> targetMapping, @NotNull BiFunction<Q,DQ,com.querydsl.core.types.Predicate> joinOnPredicateFunction)
Adds new LEFT JOIN to the query and returnsSqlQueryContext
for this join path.<DQ extends FlexibleRelationalPathBase<DR>,DR>
SqlQueryContext<?,DQ,DR>leftJoin(@NotNull Class<DQ> joinType, @NotNull BiFunction<Q,DQ,com.querydsl.core.types.Predicate> joinOnPredicateFunction)
Adds new LEFT JOIN to the query and returnsSqlQueryContext
for this join path.QueryTableMapping<S,Q,R>
mapping()
void
markNotFilterUsage()
@NotNull QName
normalizeRelation(QName qName)
Q
path()
Returns entity path of this context.<T extends FlexibleRelationalPathBase<?>>
Tpath(Class<T> pathType)
PrismContext
prismContext()
com.querydsl.core.types.Predicate
process(ObjectFilter filter)
void
processObjectPaging(ObjectPaging paging)
This takes care ofObjectPaging
which includes ordering.void
processOptions(Collection<SelectorOptions<GetOperationOptions>> options)
<T> Class<? extends T>
qNameToSchemaClass(@NotNull QName qName)
Q
root()
<T extends FlexibleRelationalPathBase<?>>
Troot(Class<T> rootType)
com.querydsl.sql.SQLQuery<?>
sqlQuery()
Returns wrapped query if usage of Querydsl API is more convenient.SqlRepoContext
sqlRepoContext()
PageOf<S>
transformToSchemaType(PageOf<com.querydsl.core.Tuple> result)
Transforms result page with (bean + extension columns) tuple to schema type.String
uniqueAliasName(String baseAliasName)
-
-
-
Field Detail
-
DEFAULT_PAGE_SIZE
public static final int DEFAULT_PAGE_SIZE
Default page size if pagination is requested, that is offset is set, but maxSize is not.- See Also:
- Constant Field Values
-
NO_PAGINATION_LIMIT
public static final long NO_PAGINATION_LIMIT
If no other limit is used for query this limit will be used for sanity reasons.- See Also:
- Constant Field Values
-
MAX_ID_IN_FOR_TO_MANY_FETCH
public static final int MAX_ID_IN_FOR_TO_MANY_FETCH
Number of values (identifiers) used in the IN clause to-many fetching selects. This works effectively as factor of how bad N+1 select is, it's at most N/this-limit+1 bad. For obvious reasons, this works only for non-composite PKs (IDs) on the master entity.- See Also:
- Constant Field Values
-
sqlQuery
protected final com.querydsl.sql.SQLQuery<?> sqlQuery
-
entityPath
protected final Q extends FlexibleRelationalPathBase<R> entityPath
-
entityPathMapping
protected final QueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>,R> entityPathMapping
-
sqlRepoContext
protected final SqlRepoContext sqlRepoContext
-
transformerSupport
protected final SqlTransformerSupport transformerSupport
-
notFilterUsed
protected boolean notFilterUsed
-
options
protected Collection<SelectorOptions<GetOperationOptions>> options
-
-
Constructor Detail
-
SqlQueryContext
protected SqlQueryContext(Q entityPath, QueryTableMapping<S,Q,R> mapping, SqlRepoContext sqlRepoContext, SqlTransformerSupport transformerSupport, com.querydsl.sql.SQLQuery<?> query)
-
-
Method Detail
-
root
public Q root()
-
root
public <T extends FlexibleRelationalPathBase<?>> T root(Class<T> rootType)
-
process
public com.querydsl.core.types.Predicate process(ObjectFilter filter) throws RepositoryException
- Specified by:
process
in interfaceFilterProcessor<S>
- Throws:
RepositoryException
-
processObjectPaging
public void processObjectPaging(ObjectPaging paging) throws RepositoryException
This takes care ofObjectPaging
which includes ordering.- Throws:
RepositoryException
-
executeQuery
public PageOf<com.querydsl.core.Tuple> executeQuery(Connection conn) throws QueryException
Returns page of results with each row represented by a Tuple containingSqlQueryContext
and then individual paths for extension columns, seeextensionColumns
inQueryTableMapping
.- Throws:
QueryException
-
executeCount
public int executeCount(Connection conn)
-
leftJoin
public <DQ extends FlexibleRelationalPathBase<DR>,DR> SqlQueryContext<?,DQ,DR> leftJoin(@NotNull @NotNull Class<DQ> joinType, @NotNull @NotNull BiFunction<Q,DQ,com.querydsl.core.types.Predicate> joinOnPredicateFunction)
Adds new LEFT JOIN to the query and returnsSqlQueryContext
for this join path.- Type Parameters:
DQ
- query type for the JOINed tableDR
- row type related to theSqlQueryContext
- Parameters:
joinType
- entity path type for the JOINjoinOnPredicateFunction
- bi-function producing ON predicate for the JOIN
-
leftJoin
public <DQ extends FlexibleRelationalPathBase<DR>,DR> SqlQueryContext<?,DQ,DR> leftJoin(@NotNull @NotNull QueryTableMapping<?,DQ,DR> targetMapping, @NotNull @NotNull BiFunction<Q,DQ,com.querydsl.core.types.Predicate> joinOnPredicateFunction)
Adds new LEFT JOIN to the query and returnsSqlQueryContext
for this join path.- Type Parameters:
DQ
- query type for the JOINed tableDR
- row type related to theSqlQueryContext
- Parameters:
targetMapping
- mapping for the JOIN target query typejoinOnPredicateFunction
- bi-function producing ON predicate for the JOIN
-
deriveNew
protected abstract <DQ extends FlexibleRelationalPathBase<DR>,DR> SqlQueryContext<?,DQ,DR> deriveNew(DQ newPath, QueryTableMapping<?,DQ,DR> newMapping)
-
processOptions
public void processOptions(Collection<SelectorOptions<GetOperationOptions>> options)
-
transformToSchemaType
public PageOf<S> transformToSchemaType(PageOf<com.querydsl.core.Tuple> result) throws SchemaException, QueryException
Transforms result page with (bean + extension columns) tuple to schema type.- Throws:
SchemaException
QueryException
-
createTransformer
protected abstract SqlTransformer<S,Q,R> createTransformer()
Creates transformer for theentityPathMapping
. Made abstract, because the way how to create the transformer can differ on the type of context that is needed to do it (typically providing various components).
-
sqlQuery
public com.querydsl.sql.SQLQuery<?> sqlQuery()
Returns wrapped query if usage of Querydsl API is more convenient.
-
path
public Q path()
Returns entity path of this context.
-
path
public <T extends FlexibleRelationalPathBase<?>> T path(Class<T> pathType)
-
mapping
public QueryTableMapping<S,Q,R> mapping()
-
markNotFilterUsage
public void markNotFilterUsage()
-
isNotFilterUsed
public boolean isNotFilterUsed()
-
sqlRepoContext
public SqlRepoContext sqlRepoContext()
-
prismContext
public PrismContext prismContext()
-
createCanonicalItemPath
public CanonicalItemPath createCanonicalItemPath(@NotNull @NotNull ItemPath itemPath)
-
createInOidFilter
public FilterProcessor<InOidFilter> createInOidFilter(SqlQueryContext<?,?,?> context)
-
-