Skip to content
Snippets Groups Projects
Commit 6d4207ed authored by Simon Barner's avatar Simon Barner
Browse files

Storage: Avoid duplicated save in case of duplicated/missing IDs

parent f04c3070
No related branches found
No related tags found
1 merge request!83459 check i ds avoid duplicate save
AutoUndoCommandStack.java 6aa645a9ed6e6547539c376fda97284928c4f9d4 GREEN
EMFTransactionalCommand.java ba4b5bead9768b6ce6c955b9238cd96cb722533c GREEN
EclipseResourceStorageService.java 1b9722e31a5ec33e4c3f7bb171fc2ce587729bf8 GREEN
ModelContext.java 85ede185d4b232221a96d0bf37a4c676b105dc00 GREEN
ModelContext.java 0510b23ced1fc381a43d5e45437ba6558b5d3301 YELLOW
NonDirtyingEMFTransactionalCommand.java ec5f282603891096b09f2628155dd27e3a21c588 GREEN
......@@ -151,7 +151,14 @@ class ModelContext implements ITopLevelElement, CommandStackListener {
}
});
checkIDs();
if(checkIDs()) {
try {
doSave(new NullProgressMonitor());
} catch(IOException | CoreException e) {
error(ToolingKernelActivator.getDefault(),
"Error saving model file when fixing missing/duplicate IDs.", e);
}
}
}
/** {@inheritDoc} */
......@@ -182,11 +189,17 @@ class ModelContext implements ITopLevelElement, CommandStackListener {
}
/**
* Checks whether all IDs are present and unique and updates {@link #maxId}. In case duplicate
* IDs have been detected (which could only be caused by a bug in AF3), these are removed and an
* error is logged.
* Checks whether all IDs are present and unique and updates {@link #maxId}.
* <ul>
* <li>Duplicate IDs indicate a programming error. They are removed and an error is logged</li>
* <li>Missing IDs are silently added.</li>
* </ul>
*
* @return {@code true} iff the model was modified because of missing/duplicated IDs (and hence
* must
* be saved).
*/
private void checkIDs() {
private boolean checkIDs() {
Set<Integer> ids = new HashSet<Integer>();
boolean hadMissing = false;
......@@ -222,20 +235,18 @@ class ModelContext implements ITopLevelElement, CommandStackListener {
runAsNonDirtyingCommand(() -> {
maxId = generateMissingIDs(getRootModelElement(), maxId);
});
try {
doSave(new NullProgressMonitor());
} catch(IOException | CoreException e) {
error(ToolingKernelActivator.getDefault(),
"Error saving model file when fixing missing/duplicate IDs.", e);
if(hadDuplicates) {
String msg = "Duplicate IDs have been removed from \"";
msg += resource.getURI().lastSegment() + "\". ";
msg +=
"Please report this incident since it could result in corrupted model files.";
error(ToolingKernelActivator.getDefault(), msg);
}
return true;
}
if(hadDuplicates) {
String msg = "Duplicate IDs have been removed from \"";
msg += resource.getURI().lastSegment() + "\". ";
msg += "Please report this incident since it could result in corrupted model files.";
error(ToolingKernelActivator.getDefault(), msg);
}
return false;
}
/** {@inheritDoc} */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment