Skip to content

Commit

Permalink
MID-4778 fixed sequences reclaim in preview
Browse files Browse the repository at this point in the history
(cherry picked from commit 30142a3)
  • Loading branch information
1azyman committed Sep 4, 2018
1 parent a7ad32d commit fb71197
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Expand Up @@ -284,7 +284,7 @@ public <F extends ObjectType> ModelContext<F> previewChanges(
}

OperationResult result = parentResult.createSubresult(PREVIEW_CHANGES);
LensContext<F> context;
LensContext<F> context = null;

try {
RepositoryCache.enter();
Expand Down Expand Up @@ -320,6 +320,8 @@ public <F extends ObjectType> ModelContext<F> previewChanges(
throw new SystemException(e);

} finally {
LensUtil.reclaimSequences(context, cacheRepositoryService, task, result);

RepositoryCache.exit();
}

Expand Down
Expand Up @@ -1049,7 +1049,7 @@ private <F extends ObjectType> void processClockworkException(LensContext<F> con
result.recordFatalError(e);
auditEvent(context, AuditEventStage.EXECUTION, null, true, task, result);
recordOperationExecution(context, e, task, result);
reclaimSequences(context, task, result);
LensUtil.reclaimSequences(context, repositoryService, task, result);
}

private <F extends ObjectType> void auditEvent(LensContext<F> context, AuditEventStage stage,
Expand Down Expand Up @@ -1598,21 +1598,4 @@ private <F extends ObjectType> Collection<PrismContainerValue<AssignmentType>> d
}
return processedChangedAssignmentValues;
}

private <F extends ObjectType> void reclaimSequences(LensContext<F> context, Task task, OperationResult result) throws SchemaException {
Map<String, Long> sequenceMap = context.getSequences();
LOGGER.trace("Context sequence map: {}", sequenceMap);
for (Entry<String, Long> sequenceMapEntry: sequenceMap.entrySet()) {
Collection<Long> unusedValues = new ArrayList<>(1);
unusedValues.add(sequenceMapEntry.getValue());
try {
LOGGER.trace("Returning value {} to sequence {}", sequenceMapEntry.getValue(), sequenceMapEntry.getKey());
repositoryService.returnUnusedValuesToSequence(sequenceMapEntry.getKey(), unusedValues, result);
} catch (ObjectNotFoundException e) {
LOGGER.error("Cannot return unused value to sequence {}: it does not exist", sequenceMapEntry.getKey(), e);
// ... but otherwise ignore it and go on
}
}
}

}
Expand Up @@ -35,7 +35,12 @@
import com.evolveum.midpoint.model.common.mapping.PrismValueDeltaSetTripleProducer;
import com.evolveum.midpoint.model.impl.util.Utils;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.polystring.PrismDefaultPolyStringNormalizer;
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.query.RefFilter;
import com.evolveum.midpoint.prism.query.builder.QueryBuilder;
import com.evolveum.midpoint.prism.polystring.AlphanumericPolyStringNormalizer;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.util.*;
import com.evolveum.midpoint.util.DebugUtil;
Expand Down Expand Up @@ -1096,4 +1101,24 @@ public static SingleLocalizableMessageType interpretLocalizableMessageTemplate(L
}
return rv;
}

public static <F extends ObjectType> void reclaimSequences(LensContext<F> context, RepositoryService repositoryService, Task task, OperationResult result) throws SchemaException {
if (context == null) {
return;
}

Map<String, Long> sequenceMap = context.getSequences();
LOGGER.trace("Context sequence map: {}", sequenceMap);
for (Map.Entry<String, Long> sequenceMapEntry: sequenceMap.entrySet()) {
Collection<Long> unusedValues = new ArrayList<>(1);
unusedValues.add(sequenceMapEntry.getValue());
try {
LOGGER.trace("Returning value {} to sequence {}", sequenceMapEntry.getValue(), sequenceMapEntry.getKey());
repositoryService.returnUnusedValuesToSequence(sequenceMapEntry.getKey(), unusedValues, result);
} catch (ObjectNotFoundException e) {
LOGGER.error("Cannot return unused value to sequence {}: it does not exist", sequenceMapEntry.getKey(), e);
// ... but otherwise ignore it and go on
}
}
}
}

0 comments on commit fb71197

Please sign in to comment.