Class QueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>,R>
- java.lang.Object
-
- com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping<S,Q,R>
-
- com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping<S,Q,R>
-
- Type Parameters:
S
- schema typeQ
- type of entity pathR
- row type related to theQueryTableMapping
public abstract class QueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>,R> extends QueryModelMapping<S,Q,R>
Common supertype for mapping items/attributes between schema (prism) classes and tables. SeeQueryModelMapping.addItemMapping(QName, ItemSqlMapper)
for details about mapping mechanism. SeeaddDetailFetchMapper(ItemName, SqlDetailFetchMapper)
for more about mapping related to-many detail tables. The main goal of this type is to map object query conditions and ORDER BY to SQL. Transformation between schema/prism objects and repository objects (row beans or tuples) is delegated toSqlTransformer
. Objects of variousQueryTableMapping
subclasses are factories for the transformer. Other important functions of mapping: * It allows creating "aliases" (entity path instances)newAlias(String)
. * It knows how to traverse to other related entities, defined byQueryModelMapping.addRelationResolver(com.evolveum.midpoint.prism.path.ItemName, com.evolveum.midpoint.repo.sqlbase.mapping.item.ItemRelationResolver)
TODO: possible future use is to help with item delta applications (objectModify)
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
QueryTableMapping(@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.SqlTransformer<S,Q,R>
createTransformer(SqlTransformerSupport transformerSupport)
CreatesSqlTransformer
of row bean to schema type, override if provided.Q
defaultAlias()
Returns default alias - use only once per query, e.g.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()
ItemSqlMapper
integerMapper(Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.dsl.NumberPath<Integer>> rootToQueryItem)
Returns the mapper creating the integer filter processor from context.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)
Lambda "wrapper" that helps with the type inference (namely the current Q type).Q
newAlias(String alias)
Creates new alias (entity path instance) with a defined name.protected abstract Q
newAliasInstance(String alias)
Method returning new instance ofEntityPath
- to be implemented by sub-mapping.R
newRowObject()
protected <OQ extends com.querydsl.core.types.EntityPath<OR>,OR,A extends com.querydsl.core.types.Path<?>>
Function<com.querydsl.core.types.EntityPath<?>,A>path(Class<OQ> queryType, Function<OQ,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 extends com.querydsl.core.types.Path<?>>
Function<com.querydsl.core.types.EntityPath<?>,A>path(Function<Q,A> rootToQueryItem)
Lambda "wrapper" that helps with type inference when mapping paths from entity path.@Nullable com.querydsl.core.types.Path<?>
primarySqlPath(ItemName itemName, SqlQueryContext<?,?,?> context)
@NotNull com.querydsl.core.types.Path<?>[]
selectExpressions(Q entity, Collection<SelectorOptions<GetOperationOptions>> options)
By default usesselectExpressionsWithCustomColumns(Q)
and does not use options.@NotNull com.querydsl.core.types.Path<?>[]
selectExpressionsWithCustomColumns(Q entity)
protected ItemSqlMapper
stringMapper(Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.dsl.StringPath> rootToQueryItem)
Returns the mapper creating the string filter processor from context.String
tableName()
protected <T extends Comparable<T>>
ItemSqlMappertimestampMapper(Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.dsl.DateTimePath<T>> rootToQueryItem)
Returns the mapper function creating the timestamp filter processor from context.String
toString()
-
Methods inherited from class com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping
addItemMapping, addNestedMapping, addRelationResolver, getItemMapper, getRelationResolver, itemMapper, queryType, relationResolver, schemaType
-
-
-
-
Constructor Detail
-
QueryTableMapping
protected QueryTableMapping(@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
-
stringMapper
protected ItemSqlMapper stringMapper(Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.dsl.StringPath> rootToQueryItem)
Returns the mapper creating the string filter processor from context.
-
integerMapper
public ItemSqlMapper integerMapper(Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.dsl.NumberPath<Integer>> rootToQueryItem)
Returns the mapper creating the integer filter processor from context.
-
timestampMapper
protected <T extends Comparable<T>> ItemSqlMapper timestampMapper(Function<com.querydsl.core.types.EntityPath<?>,com.querydsl.core.types.dsl.DateTimePath<T>> rootToQueryItem)
Returns the mapper function creating the timestamp filter processor from context.
-
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 extends com.querydsl.core.types.Path<?>> Function<com.querydsl.core.types.EntityPath<?>,A> path(Function<Q,A> rootToQueryItem)
Lambda "wrapper" that helps with type inference when mapping paths from entity path.
-
path
protected <OQ extends com.querydsl.core.types.EntityPath<OR>,OR,A extends com.querydsl.core.types.Path<?>> Function<com.querydsl.core.types.EntityPath<?>,A> path(Class<OQ> queryType, Function<OQ,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)
Lambda "wrapper" that helps with the type inference (namely the current Q type). Returned bi-function returnsON
condition predicate for two entity paths.
-
primarySqlPath
@Nullable public final @Nullable com.querydsl.core.types.Path<?> primarySqlPath(ItemName itemName, SqlQueryContext<?,?,?> context) throws RepositoryException
- Throws:
RepositoryException
-
tableName
public String tableName()
-
defaultAliasName
public String defaultAliasName()
-
newAlias
public Q newAlias(String alias)
Creates new alias (entity path instance) with a defined name. You can also usedefaultAlias()
if one alias in a query is enough. Entity path instance returned by this call is already enhanced by extension columns.
-
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()
Returns default alias - use only once per query, e.g. not for two different joins. Also, don't cache it yourself, always use this method which ensures that the alias has all the extension columns configured properly.
-
createTransformer
public SqlTransformer<S,Q,R> createTransformer(SqlTransformerSupport transformerSupport)
CreatesSqlTransformer
of row bean to schema type, override if provided. TODO: rethink/confirm this create mechanism, currently the SqlTransformerSupport is managed component without any other state and so are transformers, perhaps we can pre-create them or cache (I don't like the sound of that). On the other hand they are really lightweight and short lived helpers too, so it shouldn't be a real GC problem.
-
detailFetchMappers
public final Collection<SqlDetailFetchMapper<R,?,?,?>> detailFetchMappers()
Returns collection of all registeredSqlDetailFetchMapper
s.
-
detailFetchMapper
public final SqlDetailFetchMapper<R,?,?,?> detailFetchMapper(ItemName itemName) throws QueryException
ReturnsSqlDetailFetchMapper
registered for the specifiedItemName
.- Throws:
QueryException
-
addExtensionColumn
public void addExtensionColumn(String propertyName, com.querydsl.sql.ColumnMetadata columnMetadata)
Registers extension columns. At this moment all are treated as strings.
-
selectExpressions
@NotNull public @NotNull com.querydsl.core.types.Path<?>[] selectExpressions(Q entity, Collection<SelectorOptions<GetOperationOptions>> options)
By default usesselectExpressionsWithCustomColumns(Q)
and does not use options. Can be overridden to fulfil other needs, e.g. to select just full object..
-
selectExpressionsWithCustomColumns
@NotNull public @NotNull com.querydsl.core.types.Path<?>[] selectExpressionsWithCustomColumns(Q entity)
-
newRowObject
public R newRowObject()
-
-