diff options
-rw-r--r-- | store/src/main/java/tools/refinery/store/query/internal/QueriableModelImpl.java | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/store/src/main/java/tools/refinery/store/query/internal/QueriableModelImpl.java b/store/src/main/java/tools/refinery/store/query/internal/QueriableModelImpl.java index 414ef2c8..0f4d609f 100644 --- a/store/src/main/java/tools/refinery/store/query/internal/QueriableModelImpl.java +++ b/store/src/main/java/tools/refinery/store/query/internal/QueriableModelImpl.java | |||
@@ -12,6 +12,7 @@ import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; | |||
12 | import org.eclipse.viatra.query.runtime.api.IQueryGroup; | 12 | import org.eclipse.viatra.query.runtime.api.IQueryGroup; |
13 | 13 | ||
14 | import tools.refinery.store.map.Cursor; | 14 | import tools.refinery.store.map.Cursor; |
15 | import tools.refinery.store.map.DiffCursor; | ||
15 | import tools.refinery.store.model.Model; | 16 | import tools.refinery.store.model.Model; |
16 | import tools.refinery.store.model.ModelDiffCursor; | 17 | import tools.refinery.store.model.ModelDiffCursor; |
17 | import tools.refinery.store.model.Tuple; | 18 | import tools.refinery.store.model.Tuple; |
@@ -24,18 +25,24 @@ import tools.refinery.store.query.building.DNFPredicate; | |||
24 | public class QueriableModelImpl implements QueriableModel { | 25 | public class QueriableModelImpl implements QueriableModel { |
25 | protected final QueriableModelStore store; | 26 | protected final QueriableModelStore store; |
26 | protected final Model model; | 27 | protected final Model model; |
28 | protected final Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> predicates2PQuery; | ||
27 | 29 | ||
28 | protected final RelationalScope scope; | 30 | protected RelationalScope scope; |
29 | protected final AdvancedViatraQueryEngine engine; | 31 | protected AdvancedViatraQueryEngine engine; |
30 | protected final Map<DNFPredicate, RawPatternMatcher> predicate2Matcher; | 32 | protected Map<DNFPredicate, RawPatternMatcher> predicate2Matcher; |
31 | 33 | ||
32 | public QueriableModelImpl(QueriableModelStore store, Model model, | 34 | public QueriableModelImpl(QueriableModelStore store, Model model, |
33 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> predicates2PQuery) { | 35 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> predicates2PQuery) { |
34 | this.store = store; | 36 | this.store = store; |
35 | this.model = model; | 37 | this.model = model; |
36 | this.scope = new RelationalScope(model, store.getViews()); | 38 | this.predicates2PQuery = predicates2PQuery; |
37 | this.engine = AdvancedViatraQueryEngine.createUnmanagedEngine(scope); | 39 | initEngine(); |
38 | this.predicate2Matcher = initMatchers(engine, predicates2PQuery); | 40 | } |
41 | |||
42 | private void initEngine() { | ||
43 | this.scope = new RelationalScope(this.model, this.store.getViews()); | ||
44 | this.engine = AdvancedViatraQueryEngine.createUnmanagedEngine(this.scope); | ||
45 | this.predicate2Matcher = initMatchers(this.engine, this.predicates2PQuery); | ||
39 | } | 46 | } |
40 | 47 | ||
41 | private Map<DNFPredicate, RawPatternMatcher> initMatchers(AdvancedViatraQueryEngine engine, | 48 | private Map<DNFPredicate, RawPatternMatcher> initMatchers(AdvancedViatraQueryEngine engine, |
@@ -172,20 +179,34 @@ public class QueriableModelImpl implements QueriableModel { | |||
172 | 179 | ||
173 | @Override | 180 | @Override |
174 | public ModelDiffCursor getDiffCursor(long to) { | 181 | public ModelDiffCursor getDiffCursor(long to) { |
175 | // TODO Auto-generated method stub | 182 | return model.getDiffCursor(to); |
176 | return null; | ||
177 | } | 183 | } |
178 | 184 | ||
179 | @Override | 185 | @Override |
180 | public long commit() { | 186 | public long commit() { |
181 | // TODO Auto-generated method stub | 187 | return this.model.commit(); |
182 | return 0; | ||
183 | } | 188 | } |
184 | 189 | ||
185 | @Override | 190 | @Override |
186 | public void restore(long state) { | 191 | public void restore(long state) { |
187 | // TODO Auto-generated method stub | 192 | restoreWithDiffReplay(state); |
193 | } | ||
188 | 194 | ||
195 | public void restoreWithDiffReplay(long state) { | ||
196 | var modelDiffCursor = getDiffCursor(state); | ||
197 | for(DataRepresentation<?,?> dataRepresentation : this.getDataRepresentations()) { | ||
198 | restoreRepresentationWithDiffReplay(modelDiffCursor, dataRepresentation); | ||
199 | } | ||
189 | } | 200 | } |
190 | 201 | ||
202 | private <K,V> void restoreRepresentationWithDiffReplay(ModelDiffCursor modelDiffCursor, | ||
203 | DataRepresentation<K, V> dataRepresentation) { | ||
204 | DiffCursor<K,V> diffCursor = modelDiffCursor.getCursor(dataRepresentation); | ||
205 | this.putAll(dataRepresentation, diffCursor); | ||
206 | } | ||
207 | |||
208 | public void restoreWithReinit(long state) { | ||
209 | model.restore(state); | ||
210 | this.initEngine(); | ||
211 | } | ||
191 | } | 212 | } |