Skip to content

Commit

Permalink
#123 Ensure ChangeRecorder is disposed (#130)
Browse files Browse the repository at this point in the history
To ensure the changeDescription object is not null, do not reuse the TransactionChangeRecorder, but create a ChangeRecorder and ensure it is disposed to avoid leftover adapters
  • Loading branch information
ndoschek authored Sep 28, 2021
1 parent 71ab59f commit 4a4401e
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.change.ChangeDescription;
import org.eclipse.emf.transaction.impl.TransactionChangeRecorder;
import org.eclipse.emf.ecore.change.util.ChangeRecorder;
import org.eclipse.emfcloud.modelserver.command.CCommand;
import org.eclipse.emfcloud.modelserver.command.CCommandExecutionResult;
import org.eclipse.emfcloud.modelserver.emf.configuration.ChangePackageConfiguration;
Expand Down Expand Up @@ -47,32 +47,32 @@ public void initialize() {
@Override
protected CommandExecutionContext executeCommand(final ModelServerEditingDomain domain, final Command serverCommand,
final CCommand clientCommand) {
TransactionChangeRecorder recorder = domain.getChangeRecorder();
recorder.beginRecording();
ChangeRecorder recorder = new ChangeRecorder(domain.getResourceSet());
CommandExecutionContext context = super.executeCommand(domain, serverCommand, clientCommand);
ChangeDescription recording = recorder.endRecording();
recorder.dispose();
return new RecordingCommandExecutionContext(context, recording);
}

@Override
protected Optional<CommandExecutionContext> undoCommand(final ModelServerEditingDomain domain,
final Command serverCommand,
final CCommand clientCommand) {
TransactionChangeRecorder recorder = domain.getChangeRecorder();
recorder.beginRecording();
ChangeRecorder recorder = new ChangeRecorder(domain.getResourceSet());
Optional<CommandExecutionContext> context = super.undoCommand(domain, serverCommand, clientCommand);
ChangeDescription recording = recorder.endRecording();
recorder.dispose();
return context.map(existingContext -> new RecordingCommandExecutionContext(existingContext, recording));
}

@Override
protected Optional<CommandExecutionContext> redoCommand(final ModelServerEditingDomain domain,
final Command serverCommand,
final CCommand clientCommand) {
TransactionChangeRecorder recorder = domain.getChangeRecorder();
recorder.beginRecording();
ChangeRecorder recorder = new ChangeRecorder(domain.getResourceSet());
Optional<CommandExecutionContext> context = super.redoCommand(domain, serverCommand, clientCommand);
ChangeDescription recording = recorder.endRecording();
recorder.dispose();
return context.map(existingContext -> new RecordingCommandExecutionContext(existingContext, recording));
}

Expand Down

0 comments on commit 4a4401e

Please sign in to comment.