Class QueryModelMapping<S,Q extends FlexibleRelationalPathBase<R>,R>
- java.lang.Object
-
- com.evolveum.midpoint.repo.sql.pure.mapping.QueryModelMapping<S,Q,R>
-
- Type Parameters:
S
- schema typeQ
- type of entity pathR
- row type related to theQueryModelMapping
- Direct Known Subclasses:
QAuditDeltaMapping
,QAuditEventRecordMapping
,QAuditItemMapping
,QAuditPropertyValueMapping
,QAuditRefValueMapping
,QAuditResourceMapping
public abstract class QueryModelMapping<S,Q extends FlexibleRelationalPathBase<R>,R> extends Object
Common supertype for mapping items/attributes between schema (prism) classes and query types. SeeaddItemMapping(ItemName, ItemSqlMapper)
for details about mapping mechanism. SeeaddDetailFetchMapper(ItemName, SqlDetailFetchMapper)
for more about mapping related to-many detail tables.Goal: Map object query conditions and ORDER BY to SQL.
Non-goal: Map objects from Q-type to prism and back. This is done by code, possibly static method from a DTO "assembler" class.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
QueryModelMapping(@NotNull String tableName, @NotNull String defaultAliasName, @NotNull Class<S> schemaType, @NotNull Class<Q> queryType)
Creates metamodel for the table described by designated type (Q-class) related to schema type.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addDetailFetchMapper(ItemName itemName, SqlDetailFetchMapper<R,?,?,?> detailFetchMapper)
Fetcher/mappers for detail tables take care of loading to-many details related to this mapped entity (master).void
addExtensionColumn(String propertyName, com.querydsl.sql.ColumnMetadata columnMetadata)
Registers extension columns.void
addItemMapping(ItemName itemName, ItemSqlMapper itemMapper)
Adds information how item (attribute) from schema type is mapped to query, especially for condition creating purposes.<T extends ObjectFilter>
@NotNull FilterProcessor<T>createItemFilterProcessor(ItemName itemName, SqlPathContext<?,?,?> context)
SqlTransformer<S,Q,R>
createTransformer(PrismContext prismContext, com.querydsl.sql.Configuration querydslConfiguration)
CreatesSqlTransformer
of row bean to schema type, override if provided.Q
defaultAlias()
String
defaultAliasName()
SqlDetailFetchMapper<R,?,?,?>
detailFetchMapper(ItemName itemName)
ReturnsSqlDetailFetchMapper
registered for the specifiedItemName
.Collection<SqlDetailFetchMapper<R,?,?,?>>
detailFetchMappers()
Returns collection of all registeredSqlDetailFetchMapper
s.Map<String,com.querydsl.sql.ColumnMetadata>
getExtensionColumns()
@NotNull ItemSqlMapper
itemMapping(ItemName itemName)
protected <DQ extends com.querydsl.core.types.EntityPath<DR>,DR>
BiFunction<Q,DQ,com.querydsl.core.types.Predicate>joinOn(BiFunction<Q,DQ,com.querydsl.core.types.Predicate> joinOnPredicateFunction)
Helping lambda "wrapper" that helps with the type inference (namely the current Q type).Q
newAlias(String alias)
protected abstract Q
newAliasInstance(String alias)
Method returning new instance ofEntityPath
- to be implemented by sub-mapping.protected <OQ extends com.querydsl.core.types.EntityPath<OR>,OR,A>
Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.Path<?>>path(Class<OQ> queryType, Function<OQ,com.querydsl.core.types.Path<A>> entityToQueryItem)
Lambda "wrapper" but this time with explicit query type (otherwise unused by the method) for paths not starting on the Q parameter used for this mapping instance.protected <A> Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.Path<?>>
path(Function<Q,com.querydsl.core.types.Path<A>> rootToQueryItem)
Lambda "wrapper" that helps with type inference when mapping paths from entity path.@Nullable com.querydsl.core.types.Path<?>
primarySqlPath(ItemName itemName, SqlPathContext<?,?,?> context)
Class<Q>
queryType()
Class<S>
schemaType()
This refers to midPoint schema, not DB schema.@NotNull com.querydsl.core.types.Path<?>[]
selectExpressionsWithCustomColumns(Q entity)
String
tableName()
String
toString()
-
-
-
Constructor Detail
-
QueryModelMapping
protected QueryModelMapping(@NotNull @NotNull String tableName, @NotNull @NotNull String defaultAliasName, @NotNull @NotNull Class<S> schemaType, @NotNull @NotNull Class<Q> queryType)
Creates metamodel for the table described by designated type (Q-class) related to schema type. Allows registration of any number of columns - typically used for static properties (non-extensions).- Parameters:
tableName
- database table namedefaultAliasName
- default alias name, some short abbreviation, must be unique across mapped types
-
-
Method Detail
-
addItemMapping
public final void addItemMapping(ItemName itemName, ItemSqlMapper itemMapper)
Adds information how item (attribute) from schema type is mapped to query, especially for condition creating purposes.The
ItemSqlMapper
works as a factory forFilterProcessor
that can processObjectFilter
related to theItemName
specified as the first parameter. It is not possible to use filter processor directly because at the time of mapping specification we don't have the actual query path representing the entity or the column. These paths are non-static properties of query class instances.The
ItemSqlMapper
also provides so called "primary mapping" to a column for ORDER BY part of the filter. But there can be additional column mappings specified as for some types (e.g. poly-strings) there may be other than 1-to-1 mapping.Construction of the
ItemSqlMapper
is typically simplified by static methods#mapper()
provided on various*ItemFilterProcessor
classes. This works as a "processor factory factory" and makes table mapping specification simpler.- Parameters:
itemName
- item name from schema type (seeF_*
constants on schema types)itemMapper
- mapper wrapping the information about column mappings working also as a factory forFilterProcessor
-
addDetailFetchMapper
public final void addDetailFetchMapper(ItemName itemName, SqlDetailFetchMapper<R,?,?,?> detailFetchMapper)
Fetcher/mappers for detail tables take care of loading to-many details related to this mapped entity (master). One fetcher per detail type/table is registered under the related item name.- Parameters:
itemName
- item name from schema type that is mapped to detail table in the repositorydetailFetchMapper
- fetcher-mapper that handles loading of details- See Also:
SqlDetailFetchMapper
-
path
protected <A> Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.Path<?>> path(Function<Q,com.querydsl.core.types.Path<A>> rootToQueryItem)
Lambda "wrapper" that helps with type inference when mapping paths from entity path. The returned types are ambiguous just as they are used inmapper()
static methods on item filter processors.
-
path
protected <OQ extends com.querydsl.core.types.EntityPath<OR>,OR,A> Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.Path<?>> path(Class<OQ> queryType, Function<OQ,com.querydsl.core.types.Path<A>> entityToQueryItem)
Lambda "wrapper" but this time with explicit query type (otherwise unused by the method) for paths not starting on the Q parameter used for this mapping instance.
-
joinOn
protected <DQ extends com.querydsl.core.types.EntityPath<DR>,DR> BiFunction<Q,DQ,com.querydsl.core.types.Predicate> joinOn(BiFunction<Q,DQ,com.querydsl.core.types.Predicate> joinOnPredicateFunction)
Helping lambda "wrapper" that helps with the type inference (namely the current Q type).
-
createItemFilterProcessor
@NotNull public final <T extends ObjectFilter> @NotNull FilterProcessor<T> createItemFilterProcessor(ItemName itemName, SqlPathContext<?,?,?> context) throws QueryException
- Throws:
QueryException
-
primarySqlPath
@Nullable public final @Nullable com.querydsl.core.types.Path<?> primarySqlPath(ItemName itemName, SqlPathContext<?,?,?> context) throws QueryException
- Throws:
QueryException
-
itemMapping
@NotNull public final @NotNull ItemSqlMapper itemMapping(ItemName itemName) throws QueryException
- Throws:
QueryException
-
tableName
public String tableName()
-
defaultAliasName
public String defaultAliasName()
-
newAliasInstance
protected abstract Q newAliasInstance(String alias)
Method returning new instance ofEntityPath
- to be implemented by sub-mapping. This will create entity path without any extension columns, seenewAlias(java.lang.String)
for that.
-
defaultAlias
public Q defaultAlias()
-
createTransformer
public SqlTransformer<S,Q,R> createTransformer(PrismContext prismContext, com.querydsl.sql.Configuration querydslConfiguration)
CreatesSqlTransformer
of row bean to schema type, override if provided.
-
detailFetchMappers
public final Collection<SqlDetailFetchMapper<R,?,?,?>> detailFetchMappers()
Returns collection of all registeredSqlDetailFetchMapper
s.
-
detailFetchMapper
public final SqlDetailFetchMapper<R,?,?,?> detailFetchMapper(ItemName itemName)
ReturnsSqlDetailFetchMapper
registered for the specifiedItemName
.
-
addExtensionColumn
public void addExtensionColumn(String propertyName, com.querydsl.sql.ColumnMetadata columnMetadata)
Registers extension columns. At this moment all are treated as strings.
-
selectExpressionsWithCustomColumns
@NotNull public @NotNull com.querydsl.core.types.Path<?>[] selectExpressionsWithCustomColumns(Q entity)
-
-