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. SeecreateRowTransformer(SqlQueryContext, JdbcSession)
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. Mappings also takes care of transformation between schema/prism objects and repository objects (row beans or tuples). Any logic specific for the particular type (table) should appear in the related mapping subclass. This applies for filtering, fetching (e.g. additional detail tables) and transforming to midPoint objets. See also Javadoc inSqlQueryContext
for additional info. 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(javax.xml.namespace.QName, com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver<Q, R, ?, ?>)
Mapping for tables is initialized once and requiresSqlRepoContext
. The mapping is accessible by static `get()` method; if multiple mapping instances exist for the same type the method uses suffix to differentiate them.
-
-
Field Summary
-
Fields inherited from class com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping
logger
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
QueryTableMapping(@NotNull String tableName, @NotNull String defaultAliasName, @NotNull Class<S> schemaType, @NotNull Class<Q> queryType, @NotNull SqlRepoContext repositoryContext)
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 Deprecated Methods Modifier and Type Method Description void
addDetailFetchMapper(ItemName itemName, SqlDetailFetchMapper<R,?,?,?> detailFetchMapper)
Deprecated.void
addExtensionColumn(String propertyName, com.querydsl.sql.ColumnMetadata columnMetadata)
Registers extension columns.protected ItemSqlMapper<Q,R>
booleanMapper(Function<Q,com.querydsl.core.types.dsl.BooleanPath> rootToQueryItem)
Returns the mapper creating the boolean filter processor from context.ResultListRowTransformer<S,Q,R>
createRowTransformer(SqlQueryContext<S,Q,R> sqlQueryContext, JdbcSession jdbcSession)
Returns result transformer that by default callstoSchemaObject(Tuple, FlexibleRelationalPathBase, JdbcSession, Collection)
for each result row.Q
defaultAlias()
Returns default alias - use only once per query, e.g.String
defaultAliasName()
Collection<SqlDetailFetchMapper<R,?,?,?>>
detailFetchMappers()
Deprecated.Map<String,com.querydsl.sql.ColumnMetadata>
getExtensionColumns()
ItemSqlMapper<Q,R>
integerMapper(Function<Q,com.querydsl.core.types.dsl.NumberPath<Integer>> rootToQueryItem)
Returns the mapper creating the integer filter processor from context.protected <TQ extends FlexibleRelationalPathBase<TR>,TR>
BiFunction<Q,TQ,com.querydsl.core.types.Predicate>joinOn(BiFunction<Q,TQ,com.querydsl.core.types.Predicate> joinOnPredicateFunction)
Lambda "wrapper" that helps with the type inference (namely the current Q type).ItemSqlMapper<Q,R>
longMapper(Function<Q,com.querydsl.core.types.dsl.NumberPath<Long>> rootToQueryItem)
Returns the mapper creating the long filter processor from context.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 ItemSqlMapper<Q,R>
polyStringMapper(Function<Q,com.querydsl.core.types.dsl.StringPath> origMapping, Function<Q,com.querydsl.core.types.dsl.StringPath> normMapping)
Returns the mapper creating the string filter processor from context.PrismContext
prismContext()
SqlRepoContext
repositoryContext()
@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<Q,R>
stringMapper(Function<Q,com.querydsl.core.types.dsl.StringPath> rootToQueryItem)
Returns the mapper creating the string filter processor from context.String
tableName()
protected <T extends Comparable<T>>
ItemSqlMapper<Q,R>timestampMapper(Function<Q,com.querydsl.core.types.dsl.DateTimePath<T>> rootToQueryItem)
Returns the mapper function creating the timestamp filter processor from context.S
toSchemaObject(@NotNull com.querydsl.core.Tuple tuple, Q entityPath, @NotNull JdbcSession jdbcSession, Collection<SelectorOptions<GetOperationOptions>> options)
Transforms row Tuple containing attributes ofQueryTableMapping
to schema typeQueryTableMapping
.abstract S
toSchemaObject(R row)
Transforms row ofQueryTableMapping
type to schema typeQueryTableMapping
.String
toString()
Collection<SelectorOptions<GetOperationOptions>>
updateGetOptions(Collection<SelectorOptions<GetOperationOptions>> options, @NotNull Collection<? extends ItemDelta<?,?>> modifications)
protected ItemSqlMapper<Q,R>
uuidMapper(Function<Q,UuidPath> rootToQueryItem)
Returns the mapper creating the OID (UUID) filter processor from context.-
Methods inherited from class com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping
addItemMapping, addRelationResolver, getItemMapper, getItemMappings, getRelationResolver, itemDefinition, 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, @NotNull @NotNull SqlRepoContext repositoryContext)
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<Q,R> stringMapper(Function<Q,com.querydsl.core.types.dsl.StringPath> rootToQueryItem)
Returns the mapper creating the string filter processor from context.
-
integerMapper
public ItemSqlMapper<Q,R> integerMapper(Function<Q,com.querydsl.core.types.dsl.NumberPath<Integer>> rootToQueryItem)
Returns the mapper creating the integer filter processor from context.
-
longMapper
public ItemSqlMapper<Q,R> longMapper(Function<Q,com.querydsl.core.types.dsl.NumberPath<Long>> rootToQueryItem)
Returns the mapper creating the long filter processor from context.
-
booleanMapper
protected ItemSqlMapper<Q,R> booleanMapper(Function<Q,com.querydsl.core.types.dsl.BooleanPath> rootToQueryItem)
Returns the mapper creating the boolean filter processor from context.
-
uuidMapper
protected ItemSqlMapper<Q,R> uuidMapper(Function<Q,UuidPath> rootToQueryItem)
Returns the mapper creating the OID (UUID) filter processor from context.
-
timestampMapper
protected <T extends Comparable<T>> ItemSqlMapper<Q,R> timestampMapper(Function<Q,com.querydsl.core.types.dsl.DateTimePath<T>> rootToQueryItem)
Returns the mapper function creating the timestamp filter processor from context.- Type Parameters:
T
- actual data type of the query path storing the timestamp
-
polyStringMapper
protected ItemSqlMapper<Q,R> polyStringMapper(Function<Q,com.querydsl.core.types.dsl.StringPath> origMapping, Function<Q,com.querydsl.core.types.dsl.StringPath> normMapping)
Returns the mapper creating the string filter processor from context.
-
addDetailFetchMapper
@Deprecated public final void addDetailFetchMapper(ItemName itemName, SqlDetailFetchMapper<R,?,?,?> detailFetchMapper)
Deprecated.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. Used only in old-repo audit, we will let it die with that - but don't use in new stuff. UsecreateRowTransformer(SqlQueryContext, JdbcSession)
mechanism instead.- 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
-
joinOn
protected <TQ extends FlexibleRelationalPathBase<TR>,TR> BiFunction<Q,TQ,com.querydsl.core.types.Predicate> joinOn(BiFunction<Q,TQ,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.- Type Parameters:
TQ
- query type for the JOINed (target) tableTR
- row type related to theQueryTableMapping
-
tableName
public String tableName()
-
defaultAliasName
public String defaultAliasName()
-
repositoryContext
public SqlRepoContext repositoryContext()
-
prismContext
public PrismContext prismContext()
-
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.
-
detailFetchMappers
@Deprecated public final Collection<SqlDetailFetchMapper<R,?,?,?>> detailFetchMappers()
Deprecated.Returns collection of all registeredSqlDetailFetchMapper
s. Used only in old-repo audit, we will let it die with that - but don't use in new stuff. UsecreateRowTransformer(SqlQueryContext, JdbcSession)
mechanism instead.
-
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()
-
toSchemaObject
public abstract S toSchemaObject(R row) throws SchemaException
Transforms row ofQueryTableMapping
type to schema typeQueryTableMapping
. If pre-generated bean is used as row it does not include extension (dynamic) columns, which is OK if extension columns are used only for query and their information is still contained in the object somehow else (e.g. full object LOB). Alternative is to dynamically generate the list of select expressions reading directly from theTuple
- seetoSchemaObject(Tuple, FlexibleRelationalPathBase, JdbcSession, Collection)
.- Throws:
SchemaException
-
toSchemaObject
public S toSchemaObject(@NotNull @NotNull com.querydsl.core.Tuple tuple, @NotNull Q entityPath, @NotNull @NotNull JdbcSession jdbcSession, Collection<SelectorOptions<GetOperationOptions>> options) throws SchemaException
Transforms row Tuple containing attributes ofQueryTableMapping
to schema typeQueryTableMapping
. Entity path can be used to access tuple elements. This allows loading also dynamically defined columns (like extensions). This is what is used by default inSqlQueryContext
.- Throws:
SchemaException
-
createRowTransformer
public ResultListRowTransformer<S,Q,R> createRowTransformer(SqlQueryContext<S,Q,R> sqlQueryContext, JdbcSession jdbcSession)
Returns result transformer that by default callstoSchemaObject(Tuple, FlexibleRelationalPathBase, JdbcSession, Collection)
for each result row. This can be overridden, seeResultListRowTransformer
javadoc for details. This is useful for stateful transformers where the whole result can be pre-/post-processed as well.
-
updateGetOptions
public Collection<SelectorOptions<GetOperationOptions>> updateGetOptions(Collection<SelectorOptions<GetOperationOptions>> options, @NotNull @NotNull Collection<? extends ItemDelta<?,?>> modifications)
-
-