Search in sources :

Example 1 with AddObjectContext

use of com.evolveum.midpoint.repo.sqale.update.AddObjectContext in project midpoint by Evolveum.

the class SqaleRepositoryService method executeOverwriteObject.

/**
 * Overwrite is more like update than add.
 */
private <T extends ObjectType> String executeOverwriteObject(@NotNull PrismObject<T> newObject) throws SchemaException, RepositoryException, ObjectAlreadyExistsException {
    String oid = newObject.getOid();
    UUID oidUuid = checkOid(oid);
    long opHandle = registerOperationStart(OP_ADD_OBJECT_OVERWRITE, newObject);
    try (JdbcSession jdbcSession = sqlRepoContext.newJdbcSession().startTransaction()) {
        try {
            // noinspection ConstantConditions
            RootUpdateContext<T, QObject<MObject>, MObject> updateContext = prepareUpdateContext(jdbcSession, newObject.getCompileTimeClass(), oidUuid);
            PrismObject<T> prismObject = updateContext.getPrismObject();
            // no precondition check for overwrite
            invokeConflictWatchers(w -> w.beforeModifyObject(prismObject));
            newObject.setUserData(RepositoryService.KEY_ORIGINAL_OBJECT, prismObject.clone());
            ObjectDelta<T> delta = prismObject.diff(newObject, EquivalenceStrategy.LITERAL);
            Collection<? extends ItemDelta<?, ?>> modifications = delta.getModifications();
            logger.trace("overwriteAddObjectAttempt: originalOid={}, modifications={}", oid, modifications);
            Collection<? extends ItemDelta<?, ?>> executedModifications = updateContext.execute(modifications, false);
            replaceObject(updateContext, updateContext.getPrismObject());
            if (!executedModifications.isEmpty()) {
                invokeConflictWatchers((w) -> w.afterModifyObject(oid));
            }
            logger.trace("OBJECT after:\n{}", prismObject.debugDumpLazily());
        } catch (ObjectNotFoundException e) {
            // so it is just plain addObject after all
            new AddObjectContext<>(sqlRepoContext, newObject).execute(jdbcSession);
            invokeConflictWatchers((w) -> w.afterAddObject(oid, newObject));
        }
        jdbcSession.commit();
        return oid;
    } catch (RuntimeException e) {
        SqaleUtils.handlePostgresException(e);
        throw e;
    } finally {
        registerOperationFinish(opHandle);
    }
}
Also used : Connection(java.sql.Connection) com.evolveum.midpoint.prism.query(com.evolveum.midpoint.prism.query) com.evolveum.midpoint.repo.sqlbase(com.evolveum.midpoint.repo.sqlbase) QOrgClosure(com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgClosure) Autowired(org.springframework.beans.factory.annotation.Autowired) QueryTableMapping(com.evolveum.midpoint.repo.sqlbase.mapping.QueryTableMapping) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) InternalsConfig(com.evolveum.midpoint.schema.internals.InternalsConfig) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) S_MatchingRuleEntry(com.evolveum.midpoint.prism.query.builder.S_MatchingRuleEntry) com.evolveum.midpoint.repo.api(com.evolveum.midpoint.repo.api) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) XmlTypeConverter(com.evolveum.midpoint.prism.xml.XmlTypeConverter) S_ConditionEntry(com.evolveum.midpoint.prism.query.builder.S_ConditionEntry) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) RootUpdateContext(com.evolveum.midpoint.repo.sqale.update.RootUpdateContext) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) Expressions(com.querydsl.core.types.dsl.Expressions) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) FocusTypeUtil(com.evolveum.midpoint.schema.util.FocusTypeUtil) Tuple(com.querydsl.core.Tuple) FlexibleRelationalPathBase(com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase) com.evolveum.midpoint.schema(com.evolveum.midpoint.schema) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ObjectFilterExpressionEvaluator(com.evolveum.midpoint.repo.api.query.ObjectFilterExpressionEvaluator) AddObjectContext(com.evolveum.midpoint.repo.sqale.update.AddObjectContext) CryptoUtil(com.evolveum.midpoint.common.crypto.CryptoUtil) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDeltaCollectionsUtil(com.evolveum.midpoint.prism.delta.ItemDeltaCollectionsUtil) Trace(com.evolveum.midpoint.util.logging.Trace) ObjectUtils.defaultIfNull(org.apache.commons.lang3.ObjectUtils.defaultIfNull) Path(com.querydsl.core.types.Path) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) QOrgMapping(com.evolveum.midpoint.repo.sqale.qmodel.org.QOrgMapping) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) QObjectReferenceMapping(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReferenceMapping) Strings(com.google.common.base.Strings) SQLException(java.sql.SQLException) EquivalenceStrategy(com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) MObjectType(com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType) SQLQuery(com.querydsl.sql.SQLQuery) QObjectReference(com.evolveum.midpoint.repo.sqale.qmodel.ref.QObjectReference) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SqaleTableMapping(com.evolveum.midpoint.repo.sqale.mapping.SqaleTableMapping) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject) ObjectArrays(com.google.common.collect.ObjectArrays) InternalMonitor(com.evolveum.midpoint.schema.internals.InternalMonitor) QOrg(com.evolveum.midpoint.repo.sqale.qmodel.org.QOrg) SqlPerformanceMonitorImpl(com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Consumer(java.util.function.Consumer) Validate(org.apache.commons.lang3.Validate) Driver(java.sql.Driver) SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) DriverManager(java.sql.DriverManager) AddObjectContext(com.evolveum.midpoint.repo.sqale.update.AddObjectContext) MObject(com.evolveum.midpoint.repo.sqale.qmodel.object.MObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) QObject(com.evolveum.midpoint.repo.sqale.qmodel.object.QObject)

Aggregations

CryptoUtil (com.evolveum.midpoint.common.crypto.CryptoUtil)1 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ItemDeltaCollectionsUtil (com.evolveum.midpoint.prism.delta.ItemDeltaCollectionsUtil)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)1 EquivalenceStrategy (com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 com.evolveum.midpoint.prism.query (com.evolveum.midpoint.prism.query)1 S_ConditionEntry (com.evolveum.midpoint.prism.query.builder.S_ConditionEntry)1 S_MatchingRuleEntry (com.evolveum.midpoint.prism.query.builder.S_MatchingRuleEntry)1 XmlTypeConverter (com.evolveum.midpoint.prism.xml.XmlTypeConverter)1 com.evolveum.midpoint.repo.api (com.evolveum.midpoint.repo.api)1 ObjectFilterExpressionEvaluator (com.evolveum.midpoint.repo.api.query.ObjectFilterExpressionEvaluator)1 SqaleTableMapping (com.evolveum.midpoint.repo.sqale.mapping.SqaleTableMapping)1 MObject (com.evolveum.midpoint.repo.sqale.qmodel.object.MObject)1 MObjectType (com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType)1 QObject (com.evolveum.midpoint.repo.sqale.qmodel.object.QObject)1 QOrg (com.evolveum.midpoint.repo.sqale.qmodel.org.QOrg)1