aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java')
-rw-r--r--subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java
index 2b12d5a6..d11e431b 100644
--- a/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java
+++ b/subprojects/store/src/main/java/tools/refinery/store/model/internal/ModelImpl.java
@@ -13,23 +13,26 @@ import tools.refinery.store.model.*;
13import tools.refinery.store.representation.AnySymbol; 13import tools.refinery.store.representation.AnySymbol;
14import tools.refinery.store.representation.Symbol; 14import tools.refinery.store.representation.Symbol;
15import tools.refinery.store.tuple.Tuple; 15import tools.refinery.store.tuple.Tuple;
16import tools.refinery.store.util.CancellationToken;
16 17
17import java.util.*; 18import java.util.*;
18 19
19public class ModelImpl implements Model { 20public class ModelImpl implements Model {
20 private final ModelStore store; 21 private final ModelStoreImpl store;
21 private Version state; 22 private Version state;
22 private LinkedHashMap<? extends AnySymbol, ? extends VersionedInterpretation<?>> interpretations; 23 private LinkedHashMap<? extends AnySymbol, ? extends VersionedInterpretation<?>> interpretations;
23 private final List<ModelAdapter> adapters; 24 private final List<ModelAdapter> adapters;
24 private final List<ModelListener> listeners = new ArrayList<>(); 25 private final List<ModelListener> listeners = new ArrayList<>();
26 private final CancellationToken cancellationToken;
25 private boolean uncommittedChanges; 27 private boolean uncommittedChanges;
26 private ModelAction pendingAction = ModelAction.NONE; 28 private ModelAction pendingAction = ModelAction.NONE;
27 private Version restoringToState = null; 29 private Version restoringToState = null;
28 30
29 ModelImpl(ModelStore store, Version state, int adapterCount) { 31 ModelImpl(ModelStoreImpl store, Version state, int adapterCount) {
30 this.store = store; 32 this.store = store;
31 this.state = state; 33 this.state = state;
32 adapters = new ArrayList<>(adapterCount); 34 adapters = new ArrayList<>(adapterCount);
35 cancellationToken = store.getCancellationToken();
33 } 36 }
34 37
35 void setInterpretations(LinkedHashMap<? extends AnySymbol, ? extends VersionedInterpretation<?>> interpretations) { 38 void setInterpretations(LinkedHashMap<? extends AnySymbol, ? extends VersionedInterpretation<?>> interpretations) {
@@ -88,6 +91,7 @@ public class ModelImpl implements Model {
88 91
89 @Override 92 @Override
90 public Version commit() { 93 public Version commit() {
94 checkCancelled();
91 if (hasPendingAction()) { 95 if (hasPendingAction()) {
92 throw pendingActionError("commit"); 96 throw pendingActionError("commit");
93 } 97 }
@@ -106,6 +110,7 @@ public class ModelImpl implements Model {
106 Version[] interpretationVersions = new Version[interpretations.size()]; 110 Version[] interpretationVersions = new Version[interpretations.size()];
107 int j = 0; 111 int j = 0;
108 for (var interpretationEntry : interpretations.entrySet()) { 112 for (var interpretationEntry : interpretations.entrySet()) {
113 checkCancelled();
109 interpretationVersions[j++] = interpretationEntry.getValue().commit(); 114 interpretationVersions[j++] = interpretationEntry.getValue().commit();
110 } 115 }
111 ModelVersion modelVersion = new ModelVersion(interpretationVersions); 116 ModelVersion modelVersion = new ModelVersion(interpretationVersions);
@@ -125,6 +130,7 @@ public class ModelImpl implements Model {
125 130
126 @Override 131 @Override
127 public void restore(Version version) { 132 public void restore(Version version) {
133 checkCancelled();
128 if (hasPendingAction()) { 134 if (hasPendingAction()) {
129 throw pendingActionError("restore to %s".formatted(version)); 135 throw pendingActionError("restore to %s".formatted(version));
130 } 136 }
@@ -140,6 +146,7 @@ public class ModelImpl implements Model {
140 } 146 }
141 int j = 0; 147 int j = 0;
142 for (var interpretation : interpretations.values()) { 148 for (var interpretation : interpretations.values()) {
149 checkCancelled();
143 interpretation.restore(ModelVersion.getInternalVersion(version, j++)); 150 interpretation.restore(ModelVersion.getInternalVersion(version, j++));
144 } 151 }
145 152
@@ -187,4 +194,9 @@ public class ModelImpl implements Model {
187 public void removeListener(ModelListener listener) { 194 public void removeListener(ModelListener listener) {
188 listeners.remove(listener); 195 listeners.remove(listener);
189 } 196 }
197
198 @Override
199 public void checkCancelled() {
200 cancellationToken.checkCancelled();
201 }
190} 202}