Class SqaleTableMapping<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>
com.evolveum.midpoint.repo.sqale.mapping.SqaleTableMapping<S,Q,R>
- Type Parameters:
S- schema typeQ- type of entity pathR- row type related to theSqaleTableMapping
- All Implemented Interfaces:
SqaleMappingMixin<S,Q, R>
- Direct Known Subclasses:
QAuditDeltaMapping,QAuditEventRecordMapping,QAuditRefValueMapping,QContainerMapping,QObjectMapping,QReferenceMapping
public abstract class SqaleTableMapping<S,Q extends FlexibleRelationalPathBase<R>,R>
extends QueryTableMapping<S,Q,R>
implements SqaleMappingMixin<S,Q,R>
Mapping superclass with common functions for
QObject and non-objects (e.g. containers).
See javadoc in QueryTableMapping for more.
Mappings are typically initialized using static `init*(repositoryContext)` methods, various
suffixes are used for these reasons:
* To differentiate various instances for the same mapping type, e.g. various references
stored in separate tables.
* To avoid return type clash of the `init` methods in the hierarchy.
Even though they are static and technically independent, Java meddles too much.
* And finally, to avoid accidental use of static method from the superclass (this should not
be even a thing!).
For object mappings the reuse is not that important and mapping is simply reinitialized.
For container and ref mappings the same instance can be reused from various subclasses
of object mapping and reuse is desired.
Initialization method does not check only `null` but also forces reinitialization if different
`repositoryContext` is provided; this is only used for testing purposes.
Mappings are not built to be run with multiple repository contexts in the same runtime.
[IMPORTANT]
====
The mappings are created in the constructors and subtypes depend on their supertypes and objects
depend on their parts (container/ref tables).
This does not create any confusion and `init` methods can be called multiple times from
various objects, whatever comes first initializes the mapping and the rest reuses it.
*But cross-references can cause recursive initialization and stack overflow* and must be solved
differently, either after all the mappings are initialized or the mappings must be provided
indirectly/lazily, e.g. using Supplier, etc.
====- See Also:
-
Field Summary
Fields inherited from class com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping
logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSqaleTableMapping(@NotNull String tableName, @NotNull String defaultAliasName, @NotNull Class<S> schemaType, @NotNull Class<Q> queryType, @NotNull SqaleRepoContext repositoryContext) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExtensionMapping(@NotNull ItemName itemName, @NotNull MExtItemHolderType holderType, @NotNull Function<Q, JsonbPath> rootToPath) Adds extension container mapping, mainly the resolver for the extension container path.protected ItemSqlMapper<Q,R> binaryMapper(Function<Q, com.querydsl.core.types.dsl.ArrayPath<byte[], Byte>> rootToQueryItem) protected ItemSqlMapper<Q,R> booleanMapper(Function<Q, com.querydsl.core.types.dsl.BooleanPath> rootToQueryItem) Returns the mapper creating the boolean filter/delta processors from context.<C extends Containerable>
byte[]createFullObject(C container) Creates serialized (byte array) form of an object or a container.createRowTransformer(SqlQueryContext<S, Q, R> sqlQueryContext, JdbcSession jdbcSession) Returns result transformer that by default callsQueryTableMapping.toSchemaObject(Tuple, FlexibleRelationalPathBase, JdbcSession, Collection)for each result row.<E extends Enum<E>>
ItemSqlMapper<Q,R> enumMapper(@NotNull Function<Q, com.querydsl.core.types.dsl.EnumPath<E>> rootToQueryItem) Returns the mapper creating the enum filter/delta processors from context.protected PathSetprotected voidinsert(R row, JdbcSession jdbcSession) Convenient insert shortcut when the row is fully populated.integerMapper(Function<Q, com.querydsl.core.types.dsl.NumberPath<Integer>> rootToQueryItem) Returns the mapper creating the integer filter/delta processors from context.protected ItemSqlMapper<Q,R> multiPolyStringMapper(@NotNull Function<Q, JsonbPath> rootToQueryItem) Returns the mapper creating poly-string multi-value filter/delta processors from context.protected ItemSqlMapper<Q,R> multiStringMapper(Function<Q, com.querydsl.core.types.dsl.ArrayPath<String[], String>> rootToQueryItem) Returns the mapper creating string multi-value filter/delta processors from context.protected ItemSqlMapper<Q,R> multiUriMapper(Function<Q, com.querydsl.core.types.dsl.ArrayPath<Integer[], Integer>> rootToQueryItem) Returns the mapper creating cached URI multi-value filter/delta processors from context.protected <VT,ST> ItemSqlMapper<Q, R> multiValueMapper(Function<Q, com.querydsl.core.types.dsl.ArrayPath<ST[], ST>> rootToQueryItem, Class<ST> elementType, String dbType, @Nullable Function<VT, ST> queryConversionFunction, @Nullable Function<VT, ST> updateConversionFunction) Returns the mapper creating general array-stored multi-value filter/delta processors.protected static booleanneedsInitialization(SqaleTableMapping<?, ?, ?> instance, SqaleRepoContext repositoryContext) protected @Nullable ObjectReferenceTypeobjectReference(@Nullable UUID oid, MObjectType repoObjectType, Integer relationId) ReturnsObjectReferenceTypewith specified oid, proper type based onMObjectTypeand, optionally, target name/description.protected @Nullable ObjectReferenceTypeobjectReference(@Nullable UUID oid, MObjectType repoObjectType, String targetName) Object reference with target name.protected @Nullable QNameobjectTypeToQName(MObjectType objectType) protected SparseSchemaObject(byte[] fullObject, String identifier) protected <T> TparseSchemaObject(byte[] fullObject, String identifier, Class<T> clazz) protected ItemSqlMapper<Q,R> polyStringMapper(@NotNull Function<Q, com.querydsl.core.types.dsl.StringPath> origMapping, @NotNull Function<Q, com.querydsl.core.types.dsl.StringPath> normMapping) Returns the mapper creating the polystring filter/delta processors from context.protected IntegerprocessCacheableRelation(QName qName) Returns ID for relation QName creating newQUrirow in DB as needed.protected IntegerReturns ID for URI creating new cache row in DB as needed.protected IntegerprocessCacheableUri(QName qName) Returns ID for URI creating new cache row in DB as needed.protected Integer[]processCacheableUris(List<String> uris) Returns IDs as Integer array for URI strings creating new cache row in DB as needed.protected voidprocessExtensionColumns(S schemaObject, com.querydsl.core.Tuple tuple, Q entityPath) protected JsonbprocessExtensions(Containerable extContainer, MExtItemHolderType holderType) Converts extension container to the JSONB value.resolveIdToUri(Integer uriId) protected <O> OresolveReferenceNames(O object, JdbcSession session, Collection<SelectorOptions<GetOperationOptions>> options) resolveUriIdToQName(Integer uriId) protected MObjectTypeschemaTypeToObjectType(QName schemaType) protected voidsetPolyString(PolyStringType polyString, Consumer<String> origConsumer, Consumer<String> normConsumer) protected voidsetReference(ObjectReferenceType ref, Consumer<UUID> targetOidConsumer, Consumer<MObjectType> targetTypeConsumer, Consumer<Integer> relationIdConsumer) protected <REF extends MReference,OQ extends FlexibleRelationalPathBase<OR>, OR>
voidstoreRefs(OR ownerRow, @NotNull List<ObjectReferenceType> refs, @NotNull QReferenceMapping<?, REF, OQ, OR> mapping, @NotNull JdbcSession jdbcSession) protected ItemSqlMapper<Q,R> stringMapper(Function<Q, com.querydsl.core.types.dsl.StringPath> rootToQueryItem) Returns the mapper creating the string filter/delta processors from context.protected String[]stringsToArray(Collection<String> strings) protected <T extends Comparable<T>>
ItemSqlMapper<Q,R> timestampMapper(Function<Q, com.querydsl.core.types.dsl.DateTimePath<T>> rootToQueryItem) Returns the mapper creating the timestamp filter/delta processors from context.toSchemaObject(@NotNull com.querydsl.core.Tuple tuple, Q entityPath, @NotNull JdbcSession jdbcSession, Collection<SelectorOptions<GetOperationOptions>> options) Transforms row Tuple containingSqaleTableMappingunder entity path and extension columns.toSchemaObject(R row) Transforms row ofQueryTableMappingtype to schema typeQueryTableMapping.final StoSchemaObjectComplete(com.querydsl.core.Tuple rowTuple, Q entityPath, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull JdbcSession jdbcSession, boolean forceFull) Converts tuple to schema object and resolves reference names if necessary.toSchemaObjectCompleteSafe(com.querydsl.core.Tuple tuple, Q entityPath, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull JdbcSession jdbcSession, boolean forceFull) toSchemaObjectInternal(com.querydsl.core.Tuple rowTuple, Q entityPath, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull JdbcSession jdbcSession, boolean forceFull) Deprecated.protected ItemSqlMapper<Q,R> Returns the mapper creating the cached URI filter/delta processors from context.protected ItemSqlMapper<Q,R> uuidMapper(Function<Q, UuidPath> rootToQueryItem) Returns the mapper creating the UUID filter/delta processors from context.Methods inherited from class com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping
addDetailFetchMapper, addExtensionColumn, defaultAlias, defaultAliasName, detailFetchMappers, getExtensionColumns, joinOn, longMapper, newAlias, newAliasInstance, newRowObject, prismContext, selectExpressions, selectExpressionsWithCustomColumns, tableName, toString, updateGetOptionsMethods inherited from class com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping
addItemMapping, addRelationResolver, getItemMapper, getItemMappings, getRelationResolver, itemDefinition, itemMapper, queryType, relationResolver, schemaTypeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.evolveum.midpoint.repo.sqale.mapping.SqaleMappingMixin
addAuditRefMapping, addContainerTableMapping, addExtensionMapping, addItemMapping, addNestedMapping, addRefMapping, addRefMapping, addRelationResolver, afterModify, queryType
-
Constructor Details
-
SqaleTableMapping
-
-
Method Details
-
needsInitialization
protected static boolean needsInitialization(SqaleTableMapping<?, ?, ?> instance, SqaleRepoContext repositoryContext) -
repositoryContext
- Overrides:
repositoryContextin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R>
-
stringMapper
protected ItemSqlMapper<Q,R> stringMapper(Function<Q, com.querydsl.core.types.dsl.StringPath> rootToQueryItem) Returns the mapper creating the string filter/delta processors from context.- Overrides:
stringMapperin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R>
-
binaryMapper
-
integerMapper
public ItemSqlMapper<Q,R> integerMapper(Function<Q, com.querydsl.core.types.dsl.NumberPath<Integer>> rootToQueryItem) Returns the mapper creating the integer filter/delta processors from context.- Overrides:
integerMapperin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R>
-
booleanMapper
protected ItemSqlMapper<Q,R> booleanMapper(Function<Q, com.querydsl.core.types.dsl.BooleanPath> rootToQueryItem) Returns the mapper creating the boolean filter/delta processors from context.- Overrides:
booleanMapperin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R>
-
uuidMapper
Returns the mapper creating the UUID filter/delta processors from context.- Overrides:
uuidMapperin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R>
-
timestampMapper
protected <T extends Comparable<T>> ItemSqlMapper<Q,R> timestampMapper(Function<Q, com.querydsl.core.types.dsl.DateTimePath<T>> rootToQueryItem) Returns the mapper creating the timestamp filter/delta processors from context.- Overrides:
timestampMapperin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R> - Type Parameters:
T- actual data type of the query path storing the timestamp
-
polyStringMapper
protected ItemSqlMapper<Q,R> polyStringMapper(@NotNull @NotNull Function<Q, com.querydsl.core.types.dsl.StringPath> origMapping, @NotNull @NotNull Function<Q, com.querydsl.core.types.dsl.StringPath> normMapping) Returns the mapper creating the polystring filter/delta processors from context.- Overrides:
polyStringMapperin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R>
-
uriMapper
protected ItemSqlMapper<Q,R> uriMapper(Function<Q, com.querydsl.core.types.dsl.NumberPath<Integer>> rootToPath) Returns the mapper creating the cached URI filter/delta processors from context. -
enumMapper
public <E extends Enum<E>> ItemSqlMapper<Q,R> enumMapper(@NotNull @NotNull Function<Q, com.querydsl.core.types.dsl.EnumPath<E>> rootToQueryItem) Returns the mapper creating the enum filter/delta processors from context. -
multiPolyStringMapper
protected ItemSqlMapper<Q,R> multiPolyStringMapper(@NotNull @NotNull Function<Q, JsonbPath> rootToQueryItem) Returns the mapper creating poly-string multi-value filter/delta processors from context. -
multiStringMapper
protected ItemSqlMapper<Q,R> multiStringMapper(Function<Q, com.querydsl.core.types.dsl.ArrayPath<String[], String>> rootToQueryItem) Returns the mapper creating string multi-value filter/delta processors from context. -
multiUriMapper
protected ItemSqlMapper<Q,R> multiUriMapper(Function<Q, com.querydsl.core.types.dsl.ArrayPath<Integer[], Integer>> rootToQueryItem) Returns the mapper creating cached URI multi-value filter/delta processors from context. -
multiValueMapper
protected <VT,ST> ItemSqlMapper<Q,R> multiValueMapper(Function<Q, com.querydsl.core.types.dsl.ArrayPath<ST[], ST>> rootToQueryItem, Class<ST> elementType, String dbType, @Nullable @Nullable Function<VT, ST> queryConversionFunction, @Nullable @Nullable Function<VT, ST> updateConversionFunction) Returns the mapper creating general array-stored multi-value filter/delta processors.- Type Parameters:
VT- real-value type from schemaST- stored type (e.g. String for TEXT[])- Parameters:
dbType- name of the type for element in DB (without []) for the cast part of the conditionelementType- class necessary for array creation; must be a class convertable todbTypeby PG JDBC driver
-
toSchemaObject
Description copied from class:QueryTableMappingTransforms row ofQueryTableMappingtype 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- seeQueryTableMapping.toSchemaObject(Tuple, FlexibleRelationalPathBase, JdbcSession, Collection).- Specified by:
toSchemaObjectin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R> - 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 containingSqaleTableMappingunder entity path and extension columns. While public, for Sqale repo it should only be called for internal mapping purposes. *Do not call this in result list transformers* because the results would not have resolved reference names (if requested). Notice that the default implementation ofcreateRowTransformer(com.evolveum.midpoint.repo.sqlbase.SqlQueryContext<S, Q, R>, com.evolveum.midpoint.repo.sqlbase.JdbcSession)in this class callstoSchemaObjectCompleteSafe(com.querydsl.core.Tuple, Q, java.util.Collection<com.evolveum.midpoint.schema.SelectorOptions<com.evolveum.midpoint.schema.GetOperationOptions>>, com.evolveum.midpoint.repo.sqlbase.JdbcSession, boolean)which is the right thing to call in result list transformers.- Overrides:
toSchemaObjectin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R> - Throws:
SchemaException
-
processExtensionColumns
-
objectReference
@Nullable protected @Nullable ObjectReferenceType objectReference(@Nullable @Nullable UUID oid, MObjectType repoObjectType, Integer relationId) ReturnsObjectReferenceTypewith specified oid, proper type based onMObjectTypeand, optionally, target name/description. Returnsnullif OID is null. Fails if OID is not null andrepoObjectTypeis null. -
objectReference
@Nullable protected @Nullable ObjectReferenceType objectReference(@Nullable @Nullable UUID oid, MObjectType repoObjectType, String targetName) Object reference with target name. -
objectTypeToQName
-
processCacheableRelation
Returns ID for relation QName creating newQUrirow in DB as needed. Relation is normalized before consulting the cache. Never returns null, returns default ID for configured default relation. -
processCacheableUri
Returns ID for URI creating new cache row in DB as needed. -
processCacheableUri
Returns ID for URI creating new cache row in DB as needed. -
processCacheableUris
Returns IDs as Integer array for URI strings creating new cache row in DB as needed. Returns null for null or empty list on input. -
resolveIdToUri
-
resolveUriIdToQName
-
schemaTypeToObjectType
-
setPolyString
protected void setPolyString(PolyStringType polyString, Consumer<String> origConsumer, Consumer<String> normConsumer) -
setReference
protected void setReference(ObjectReferenceType ref, Consumer<UUID> targetOidConsumer, Consumer<MObjectType> targetTypeConsumer, Consumer<Integer> relationIdConsumer) -
storeRefs
protected <REF extends MReference,OQ extends FlexibleRelationalPathBase<OR>, void storeRefsOR> (@NotNull OR ownerRow, @NotNull @NotNull List<ObjectReferenceType> refs, @NotNull @NotNull QReferenceMapping<?, REF, OQ, OR> mapping, @NotNull @NotNull JdbcSession jdbcSession) -
stringsToArray
-
insert
Convenient insert shortcut when the row is fully populated. -
addExtensionMapping
public void addExtensionMapping(@NotNull @NotNull ItemName itemName, @NotNull @NotNull MExtItemHolderType holderType, @NotNull @NotNull Function<Q, JsonbPath> rootToPath) Adds extension container mapping, mainly the resolver for the extension container path. -
processExtensions
Converts extension container to the JSONB value. -
parseSchemaObject
- Throws:
SchemaException
-
parseSchemaObject
protected <T> T parseSchemaObject(byte[] fullObject, String identifier, Class<T> clazz) throws SchemaException - Throws:
SchemaException
-
createFullObject
Creates serialized (byte array) form of an object or a container.- Throws:
SchemaException
-
fullObjectItemsToSkip
-
toSchemaObjectInternal
@Deprecated public S toSchemaObjectInternal(com.querydsl.core.Tuple rowTuple, Q entityPath, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull @NotNull JdbcSession jdbcSession, boolean forceFull) throws SchemaException Deprecated.TODO: This should be merged with toSchemaObject and forceFull parameter should be deprecated. Proper usage of updateGetOptions() should replace it - see QShadowMapping where toSchemaObject is overridden and force reindex works as well. In the meantime: This is "internal" method in the sense it can be overridden to customize the default transformation behavior. It is public so one mapper can call it on another mapper, but otherwise should not be called from repo service or similar places - these should usetoSchemaObjectComplete(com.querydsl.core.Tuple, Q, java.util.Collection<com.evolveum.midpoint.schema.SelectorOptions<com.evolveum.midpoint.schema.GetOperationOptions>>, com.evolveum.midpoint.repo.sqlbase.JdbcSession, boolean). *Should I override this ortoSchemaObject(R)that is called from this method?* Prefer overridingtoSchemaObject(R)as we want to get rid of this version and forceFull flag. *Do not call this in result list transformers* because the results would not have resolved reference names (if requested). Notice that the default implementation ofcreateRowTransformer(com.evolveum.midpoint.repo.sqlbase.SqlQueryContext<S, Q, R>, com.evolveum.midpoint.repo.sqlbase.JdbcSession)in this class callstoSchemaObjectCompleteSafe(com.querydsl.core.Tuple, Q, java.util.Collection<com.evolveum.midpoint.schema.SelectorOptions<com.evolveum.midpoint.schema.GetOperationOptions>>, com.evolveum.midpoint.repo.sqlbase.JdbcSession, boolean)which is the right thing to call in result list transformers.- Parameters:
forceFull- true when reindex is forced on the modified object, otherwise false- Throws:
SchemaException
-
toSchemaObjectComplete
public final S toSchemaObjectComplete(com.querydsl.core.Tuple rowTuple, Q entityPath, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull @NotNull JdbcSession jdbcSession, @Deprecated boolean forceFull) throws SchemaException Converts tuple to schema object and resolves reference names if necessary. This is the method called from the "outside" of mappers to obtain complete object. This method is final to ensure the reference names resolution is the last step performed on the complete object. MethodtoSchemaObjectInternal(com.querydsl.core.Tuple, Q, java.util.Collection<com.evolveum.midpoint.schema.SelectorOptions<com.evolveum.midpoint.schema.GetOperationOptions>>, com.evolveum.midpoint.repo.sqlbase.JdbcSession, boolean)prepares the object; can be overridden by object/container mappers as necessary.- Parameters:
forceFull- true when reindex is forced on the modified object, otherwise false- Throws:
SchemaException
-
toSchemaObjectCompleteSafe
public S toSchemaObjectCompleteSafe(com.querydsl.core.Tuple tuple, Q entityPath, Collection<SelectorOptions<GetOperationOptions>> options, @NotNull @NotNull JdbcSession jdbcSession, @Deprecated boolean forceFull) Version oftoSchemaObjectComplete(com.querydsl.core.Tuple, Q, java.util.Collection<com.evolveum.midpoint.schema.SelectorOptions<com.evolveum.midpoint.schema.GetOperationOptions>>, com.evolveum.midpoint.repo.sqlbase.JdbcSession, boolean)with custom schema exception treatment. By default, it is simply wrapped into runtime exception, but is more sophisticated for object mapping. This method should be used when each row in return list should have its own exception treatment, which is the default behavior in midPoint. Instead of failing the whole search because of single-object schema error, a placeholder object for the row can be returned, possibly with error indicated. -
resolveReferenceNames
protected <O> O resolveReferenceNames(O object, JdbcSession session, Collection<SelectorOptions<GetOperationOptions>> options) -
createRowTransformer
public ResultListRowTransformer<S,Q, createRowTransformerR> (SqlQueryContext<S, Q, R> sqlQueryContext, JdbcSession jdbcSession) Description copied from class:QueryTableMappingReturns result transformer that by default callsQueryTableMapping.toSchemaObject(Tuple, FlexibleRelationalPathBase, JdbcSession, Collection)for each result row. This can be overridden, seeResultListRowTransformerjavadoc for details. This is useful for stateful transformers where the whole result can be pre-/post-processed as well.- Overrides:
createRowTransformerin classQueryTableMapping<S,Q extends FlexibleRelationalPathBase<R>, R>
-