use of org.eclipse.emf.transaction.RollbackException in project AGREE by loonwerks.
the class EphemeralImplementationUtil method cleanup.
/**
* Delete the accumulated ephemeral component implementations by deleting their containing {@link Resource}.
* <p>
* This method is intended to be called immediately prior to the instance of this utility going out of scope.
* However, it may be called multiple times, deleting the ephemeral implementations and resource accumulated to
* that point.
*/
public void cleanup() {
final TransactionalEditingDomain domain = WorkspaceEditingDomainFactory.INSTANCE.createEditingDomain();
// We execute this command on the command stack because otherwise, we will not
// have write permissions on the editing domain.
Command cmd = new RecordingCommand(domain) {
@Override
protected void doExecute() {
try {
Iterator<Resource> iter = ephemeralResources.iterator();
while (iter.hasNext()) {
Resource res = iter.next();
res.delete(Collections.EMPTY_MAP);
iter.remove();
}
} catch (IOException e) {
setErrorMessage(e.getMessage());
e.printStackTrace();
}
}
};
try {
((TransactionalCommandStack) domain.getCommandStack()).execute(cmd, null);
} catch (InterruptedException | RollbackException e) {
setErrorMessage(e.getMessage());
e.printStackTrace();
}
}
use of org.eclipse.emf.transaction.RollbackException in project emfcloud-modelserver by eclipse-emfcloud.
the class JsonPatchHelper method getJsonPatch.
public JsonNode getJsonPatch(final EObject root, final CCommandExecutionResult result) throws EncodingException {
// TODO Support multiple resource patches.
// See issue https://github.com/eclipse-emfcloud/emfcloud-modelserver/issues/159
JsonNode newModel = getCurrentModel(root);
ChangeDescription cd = (ChangeDescription) result.getChangeDescription();
ModelServerEditingDomain editingDomain = modelManager.getEditingDomain(root.eResource().getResourceSet());
JsonNode oldModel = null;
try {
// Compute the old model by reverting the current change. We need to do that in a write-transaction.
// Note: we could also apply it on a read-only copy of the model, but this could potentially modify
// the IDs (which are part of the Resource; not of the EObjects), causing unexpected patch changes.
InternalTransaction transaction = editingDomain.startTransaction(false, null);
try {
cd.applyAndReverse();
oldModel = getCurrentModel(root);
cd.applyAndReverse();
transaction.commit();
} catch (RollbackException e) {
LOG.error("Failed to generate JsonPatch", e);
return null;
} finally {
if (transaction != null && transaction.isActive()) {
rollback(transaction, editingDomain);
}
}
} catch (InterruptedException e) {
LOG.error("Failed to generate JsonPatch", e);
return null;
}
return diffModel(oldModel, newModel);
}
Aggregations