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 type
Q - type of entity path
R - row type related to the QueryTableMapping
Direct Known Subclasses:
SqaleTableMapping

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. See QueryModelMapping.addItemMapping(QName, ItemSqlMapper) for details about mapping mechanism. See createRowTransformer(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 in SqlQueryContext 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 by QueryModelMapping.addRelationResolver(javax.xml.namespace.QName, com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver<Q, R, ?, ?>) Mapping for tables is initialized once and requires SqlRepoContext. The mapping is accessible by static `get()` method; if multiple mapping instances exist for the same type the method uses suffix to differentiate them.
  • Constructor Details

    • 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 name
      defaultAliasName - default alias name, some short abbreviation, must be unique across mapped types
  • Method Details

    • 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. Use createRowTransformer(SqlQueryContext, JdbcSession) mechanism instead.
      Parameters:
      itemName - item name from schema type that is mapped to detail table in the repository
      detailFetchMapper - fetcher-mapper that handles loading of details
      See Also:
    • 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 returns ON condition predicate for two entity paths.
      Type Parameters:
      TQ - query type for the JOINed (target) table
      TR - row type related to the QueryTableMapping
    • 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 use defaultAlias() 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 of EntityPath - to be implemented by sub-mapping. This will create entity path without any extension columns, see newAlias(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 registered SqlDetailFetchMappers. Used only in old-repo audit, we will let it die with that - but don't use in new stuff. Use createRowTransformer(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.
    • getExtensionColumns

      public Map<String,com.querydsl.sql.ColumnMetadata> getExtensionColumns()
    • selectExpressions

      @NotNull public @NotNull com.querydsl.core.types.Path<?>[] selectExpressions(Q entity, Collection<SelectorOptions<GetOperationOptions>> options)
      By default, uses selectExpressionsWithCustomColumns(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 of QueryTableMapping type to schema type QueryTableMapping. 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 the Tuple - see toSchemaObject(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 of QueryTableMapping to schema type QueryTableMapping. 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 in SqlQueryContext.
      Throws:
      SchemaException
    • createRowTransformer

      public ResultListRowTransformer<S,Q,R> createRowTransformer(SqlQueryContext<S,Q,R> sqlQueryContext, JdbcSession jdbcSession)
      Returns result transformer that by default calls toSchemaObject(Tuple, FlexibleRelationalPathBase, JdbcSession, Collection) for each result row. This can be overridden, see ResultListRowTransformer 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)
    • toString

      public String toString()
      Overrides:
      toString in class Object