Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Mar 30, 2021
2 parents 7768520 + a1612d0 commit 3b2196e
Show file tree
Hide file tree
Showing 19 changed files with 117 additions and 74 deletions.
Expand Up @@ -1230,6 +1230,9 @@ protected void okPerformed(QName type, Collection<QName> relations, AjaxRequestT

@Override
protected QName getDefaultObjectType() {
if (QueryScope.SELECTED.equals(scope)) {
return FocusType.COMPLEX_TYPE;
}
return WebComponentUtil.classToQName(AbstractRoleMemberPanel.this.getPrismContext(),
AbstractRoleMemberPanel.this.getDefaultObjectType());
}
Expand Down
Expand Up @@ -46,7 +46,7 @@ public Predicate process(RefFilter filter) {
SqlQueryContext<?, QObjectReference, MReference> refContext =
((SqlQueryContext<?, QObject<?>, ?>) context)
.leftJoin(qObjectReferenceMapping, (o, r) -> o.oid.eq(r.ownerOid));
QReference ref = refContext.path();
QReference<?> ref = refContext.path();

return new RefItemFilterProcessor(context, ref.targetOid, ref.targetType, ref.relationId)
.process(filter);
Expand Down
Expand Up @@ -37,6 +37,7 @@
import com.evolveum.midpoint.repo.sqale.qmodel.object.ObjectSqlTransformer;
import com.evolveum.midpoint.repo.sqale.qmodel.object.QObject;
import com.evolveum.midpoint.repo.sqlbase.*;
import com.evolveum.midpoint.repo.sqlbase.mapping.item.ItemSqlMapper;
import com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.internals.InternalMonitor;
Expand Down Expand Up @@ -129,8 +130,7 @@ public SqaleRepositoryService(
// object = objectLocal;
// invokeConflictWatchers((w) -> w.afterGetObject(objectLocal));
} catch (RuntimeException e) { // TODO what else to catch?
handleGeneralException(e, operationResult);
throw new SystemException(e);
throw handledGeneralException(e, operationResult);
} catch (Throwable t) {
operationResult.recordFatalError(t);
throw t;
Expand Down Expand Up @@ -264,27 +264,27 @@ public <T extends ObjectType> String addObject(
object.checkConsistence(ConsistencyCheckScope.MANDATORY_CHECKS_ONLY);
}

// SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
// long opHandle = pm.registerOperationStart(OP_ADD_OBJECT, object.getCompileTimeClass());
// int attempt = 1;
// int restarts = 0;
// boolean noFetchExtensionValueInsertionForbidden = false;
// TODO use executeAttempts
final String operation = "adding";

if (object.getVersion() == null) {
object.setVersion("1");
}

/* old repo code missing in new repo:
SqlPerformanceMonitorImpl pm = getPerformanceMonitor();
long opHandle = pm.registerOperationStart(OP_ADD_OBJECT, object.getCompileTimeClass());
int attempt = 1;
int restarts = 0;
boolean noFetchExtensionValueInsertionForbidden = false;
String proposedOid = object.getOid();
while (true) {
try {
*/
// TODO use executeAttempts

String oid = new AddObjectOperation<>(object, options, operationResult)
.execute(transformerSupport);
invokeConflictWatchers((w) -> w.afterAddObject(oid, object));
return oid;
/*
String proposedOid = object.getOid();
while (true) {
try {
String createdOid = objectUpdater.addObjectAttempt(object, options, noFetchExtensionValueInsertionForbidden, subResult);
invokeConflictWatchers((w) -> w.afterAddObject(createdOid, object));
return createdOid;
} catch (RestartOperationRequestedException ex) {
// special case: we want to restart but we do not want to count these
LOGGER.trace("Restarting because of {}", ex.getMessage());
Expand All @@ -293,7 +293,7 @@ public <T extends ObjectType> String addObject(
throw new IllegalStateException("Too many operation restarts");
}
} catch (RuntimeException ex) {
attempt = baseHelper.logOperationAttempt(proposedOid, operation, attempt, ex, subResult);
attempt = baseHelper.logOperationAttempt(proposedOid, "adding", attempt, ex, subResult);
// pm.registerOperationNewAttempt(opHandle, attempt);
}
noFetchExtensionValueInsertionForbidden = true; // todo This is a temporary measure; needs better handling.
Expand Down Expand Up @@ -389,7 +389,7 @@ public <T extends ObjectType> ModifyObjectResult<T> modifyObject(
if (precondition != null && !precondition.holds(prismObject)) {
throw new PreconditionViolationException("Modification precondition does not hold for " + prismObject);
}
// invokeConflictWatchers(w -> w.beforeModifyObject(prismObject)); TODO
invokeConflictWatchers(w -> w.beforeModifyObject(prismObject));

PrismObject<T> originalObject = prismObject.clone();

Expand All @@ -416,6 +416,8 @@ public <T extends ObjectType> ModifyObjectResult<T> modifyObject(
// especially if called potentially multiple times.
return new ModifyObjectResult<>(originalObject, prismObject, modifications);
}
} catch (RepositoryException | RuntimeException e) {
throw handledGeneralException(e, operationResult);
} catch (Throwable t) {
operationResult.recordFatalError(t);
throw t;
Expand All @@ -433,7 +435,8 @@ public <T extends ObjectType> ModifyObjectResult<T> modifyObject(
void modifyObjectAttempt(
JdbcSession jdbcSession,
PrismObject<S> prismObject,
Collection<? extends ItemDelta<?, ?>> modifications) throws SchemaException {
Collection<? extends ItemDelta<?, ?>> modifications)
throws SchemaException, RepositoryException {

Collection<? extends ItemDelta<?, ?>> narrowedModifications =
prismObject.narrowModifications(modifications, EquivalenceStrategy.DATA,
Expand All @@ -447,13 +450,24 @@ void modifyObjectAttempt(
SQLUpdateClause update = jdbcSession.newUpdate(root)
.where(root.oid.eq(UUID.fromString(prismObject.getOid())));

// region updatePrismObject: can be extracted as updatePrismObject (not done before CID generation is cleared up
// TODO taken from "legacy" branch, how is this worse/different from ObjectDeltaUpdater.handleObjectCommonAttributes()?
ItemDeltaCollectionsUtil.applyTo(modifications, prismObject);
ObjectTypeUtil.normalizeAllRelations(prismObject, schemaService.relationRegistry());
// TODO generate missing container IDs? is it needed? doesn't model do it? see old repo PrismIdentifierGenerator
// BWT: it's not enough to do it in prism object, we need it for deltas adding containers too

int newVersion = SqaleUtils.objectVersionAsInt(prismObject) + 1;
prismObject.setVersion(String.valueOf(newVersion));
// endregion

// TODO APPLY modifications HERE (generate update/set clauses)
for (ItemDelta<?, ?> modification : modifications) {
System.out.println("modification = " + modification);
ItemSqlMapper mapper = rootMapping.itemMapper(modification.getPath().asSingleName());
// TODO get modify applicator or what
}

ObjectSqlTransformer<S, Q, R> transformer = (ObjectSqlTransformer<S, Q, R>)
rootMapping.createTransformer(transformerSupport);
update.set(root.fullObject, transformer.createFullObject(prismObject.asObjectable()));
Expand Down Expand Up @@ -504,9 +518,8 @@ public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
try {
var queryContext = SqaleQueryContext.from(type, transformerSupport, sqlRepoContext);
return sqlQueryExecutor.count(queryContext, query, options);
} catch (QueryException | RuntimeException e) {
handleGeneralException(e, operationResult);
throw new SystemException(e);
} catch (RepositoryException | RuntimeException e) {
throw handledGeneralException(e, operationResult);
} catch (Throwable t) {
operationResult.recordFatalError(t);
throw t;
Expand Down Expand Up @@ -538,9 +551,8 @@ public <T extends ObjectType> int countObjects(Class<T> type, ObjectQuery query,
//noinspection unchecked
return result.map(
o -> (PrismObject<T>) o.asPrismObject());
} catch (QueryException | RuntimeException e) {
handleGeneralException(e, operationResult);
throw new SystemException(e);
} catch (RepositoryException | RuntimeException e) {
throw handledGeneralException(e, operationResult);
} catch (Throwable t) {
operationResult.recordFatalError(t);
throw t;
Expand Down Expand Up @@ -619,8 +631,8 @@ public <T extends Containerable> SearchResultList<T> searchContainers(
SearchResultList<T> result =
sqlQueryExecutor.list(queryContext, query, options);
return result;
} catch (QueryException | RuntimeException e) {
handleGeneralException(e, operationResult);
} catch (RepositoryException | RuntimeException e) {
handledGeneralException(e, operationResult);
throw new SystemException(e);
} catch (Throwable t) {
operationResult.recordFatalError(t);
Expand Down Expand Up @@ -815,13 +827,14 @@ public void destroy() {

/**
* Handles exception outside of transaction - this does not handle transactional problems.
* Returns {@link SystemException}, call with `throw` keyword.
*/
private void handleGeneralException(@NotNull Throwable ex, OperationResult result) {
private SystemException handledGeneralException(@NotNull Throwable ex, OperationResult result) {
LOGGER.error("General checked exception occurred.", ex);
recordException(ex, result,
sqlRepoContext.getJdbcRepositoryConfiguration().isFatalException(ex));

throw ex instanceof SystemException
return ex instanceof SystemException
? (SystemException) ex
: new SystemException(ex.getMessage(), ex);
}
Expand Down
Expand Up @@ -48,11 +48,11 @@
import com.evolveum.midpoint.repo.sql.data.common.enums.ROperationResultStatus;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.helpers.BaseHelper;
import com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.repo.sql.util.TemporaryTableDialect;
import com.evolveum.midpoint.repo.sqlbase.*;
import com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorImpl;
import com.evolveum.midpoint.schema.*;
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.schema.result.OperationResult;
Expand Down Expand Up @@ -1131,7 +1131,7 @@ public int countObjects(
var queryContext = AuditSqlQueryContext.from(
AuditEventRecordType.class, transformerSupport, sqlRepoContext);
return sqlQueryExecutor.count(queryContext, query, options);
} catch (QueryException | RuntimeException e) {
} catch (RepositoryException | RuntimeException e) {
baseHelper.handleGeneralException(e, operationResult);
throw new SystemException(e);
} catch (Throwable t) {
Expand Down Expand Up @@ -1160,7 +1160,7 @@ public SearchResultList<AuditEventRecordType> searchObjects(
sqlQueryExecutor.list(queryContext, query, options);
// addContainerDefinition(AuditEventRecordType.class, result);
return result;
} catch (QueryException | RuntimeException e) {
} catch (RepositoryException | RuntimeException e) {
baseHelper.handleGeneralException(e, operationResult);
throw new SystemException(e);
} catch (Throwable t) {
Expand Down
Expand Up @@ -24,6 +24,7 @@
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

/** Transformation functionality common for audit. */
public abstract class AuditSqlTransformerBase<S, Q extends FlexibleRelationalPathBase<R>, R>
implements SqlTransformer<S, Q, R> {

Expand Down
Expand Up @@ -24,7 +24,7 @@
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

/**
* Simple class with methods for audit event transformation between repo and Prism world.
* Transformer between repo and Prism world for audit event.
*/
public class AuditDeltaSqlTransformer
extends AuditSqlTransformerBase<ObjectDeltaOperationType, QAuditDelta, MAuditDelta> {
Expand All @@ -36,19 +36,14 @@ public AuditDeltaSqlTransformer(
super(transformerSupport, mapping);
}

public ObjectDeltaOperationType toSchemaObject(MAuditDelta row) throws SchemaException {
public ObjectDeltaOperationType toSchemaObject(MAuditDelta row) {
ObjectDeltaOperationType odo = new ObjectDeltaOperationType();
SQLTemplates querydslTemplates = transformerSupport.sqlRepoContext().getQuerydslTemplates();

boolean usingSqlServer = querydslTemplates instanceof SQLServerTemplates;
odo.setObjectDelta(parseDelta(row.delta, usingSqlServer));
if (row.fullResult != null) {
String serializedResult =
RUtil.getSerializedFormFromBytes(row.fullResult, usingSqlServer);
odo.setObjectDelta(parseBytes(row.delta, usingSqlServer, ObjectDeltaType.class));
odo.setExecutionResult(parseBytes(row.fullResult, usingSqlServer, OperationResultType.class));

OperationResultType resultType = transformerSupport.parseRealValue(
serializedResult, OperationResultType.class);
odo.setExecutionResult(resultType);
}
if (row.objectNameOrig != null || row.objectNameNorm != null) {
odo.setObjectName(new PolyStringType(
new PolyString(row.objectNameOrig, row.objectNameNorm)));
Expand All @@ -62,19 +57,19 @@ public ObjectDeltaOperationType toSchemaObject(MAuditDelta row) throws SchemaExc
return odo;
}

private ObjectDeltaType parseDelta(byte[] rowDelta, boolean usingSqlServer) {
if (rowDelta == null) {
private <T> T parseBytes(byte[] bytes, boolean usingSqlServer, Class<T> clazz) {
if (bytes == null) {
return null;
}
String serializedDelta = RUtil.getSerializedFormFromBytes(rowDelta, usingSqlServer);

try {
return transformerSupport.parseRealValue(
serializedDelta, ObjectDeltaType.class);
return transformerSupport
.createStringParser(RUtil.getSerializedFormFromBytes(bytes, usingSqlServer))
.compat()
.parseRealValue(clazz);
} catch (SchemaException e) {
LOGGER.error("Cannot parse delta: {}", e.getMessage(), e);
LOGGER.error("Cannot parse {}: {}", clazz.getSimpleName(), e.getMessage(), e);
return null;
}
return null;

}
}
@@ -1,16 +1,15 @@
/*
* Copyright (c) 2010-2020 Evolveum and contributors
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.repo.sqlbase;

/**
* @author lazyman
* Query related repository exception.
*/
public class QueryException extends Exception {
public class QueryException extends RepositoryException {

public QueryException(String message) {
super(message);
Expand Down
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sqlbase;

/**
* Base repository exception.
*/
public class RepositoryException extends Exception {

public RepositoryException(String message) {
super(message);
}

public RepositoryException(Throwable cause) {
super(cause);
}

public RepositoryException(String message, Throwable cause) {
super(message, cause);
}
}
Expand Up @@ -103,7 +103,7 @@ public <T extends FlexibleRelationalPathBase<?>> T root(Class<T> rootType) {
}

@Override
public Predicate process(ObjectFilter filter) throws QueryException {
public Predicate process(ObjectFilter filter) throws RepositoryException {
if (filter == null) {
return null;
}
Expand All @@ -117,7 +117,7 @@ public Predicate process(ObjectFilter filter) throws QueryException {
/**
* This takes care of {@link ObjectPaging} which includes ordering.
*/
public void processObjectPaging(ObjectPaging paging) throws QueryException {
public void processObjectPaging(ObjectPaging paging) throws RepositoryException {
if (paging == null) {
return;
}
Expand All @@ -133,7 +133,8 @@ public void processObjectPaging(ObjectPaging paging) throws QueryException {
}
}

private void processOrdering(List<? extends ObjectOrdering> orderings) throws QueryException {
private void processOrdering(List<? extends ObjectOrdering> orderings)
throws RepositoryException {
for (ObjectOrdering ordering : orderings) {
ItemPath orderByItemPath = ordering.getOrderBy();
if (!(orderByItemPath.isSingleName())) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public <S, Q extends FlexibleRelationalPathBase<R>, R> int count(
@NotNull SqlQueryContext<S, Q, R> context,
ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options)
throws QueryException {
throws RepositoryException {

if (query != null) {
context.process(query.getFilter());
Expand All @@ -55,7 +55,7 @@ public <S, Q extends FlexibleRelationalPathBase<R>, R> SearchResultList<S> list(
@NotNull SqlQueryContext<S, Q, R> context,
ObjectQuery query,
Collection<SelectorOptions<GetOperationOptions>> options)
throws QueryException, SchemaException {
throws RepositoryException, SchemaException {

if (query != null) {
context.process(query.getFilter());
Expand Down
Expand Up @@ -57,8 +57,9 @@ public <T extends Objectable> ParseResult<T> parsePrismObject(String serializedF
return new ParseResult<>(parsingContext, prismObject);
}

public <T> T parseRealValue(String serializedResult, Class<T> clazz) throws SchemaException {
return schemaService.parserFor(serializedResult).compat().parseRealValue(clazz);
@NotNull
public PrismParserNoIO createStringParser(String serializedResult) {
return schemaService.parserFor(serializedResult);
}

/**
Expand Down

0 comments on commit 3b2196e

Please sign in to comment.