diff options
author | 2021-10-22 21:43:34 +0200 | |
---|---|---|
committer | 2021-10-22 21:43:34 +0200 | |
commit | 53deeff19ce9b777f125443504925f835d57fe21 (patch) | |
tree | 594e8aba85c537702c328caed4faa63940d11ae7 /store | |
parent | Test compilation fixes for Query building (diff) | |
download | refinery-53deeff19ce9b777f125443504925f835d57fe21.tar.gz refinery-53deeff19ce9b777f125443504925f835d57fe21.tar.zst refinery-53deeff19ce9b777f125443504925f835d57fe21.zip |
Viatra-specific code moved inside to QueriableModel
Diffstat (limited to 'store')
-rw-r--r-- | store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java | 2 | ||||
-rw-r--r-- | store/src/main/java/tools/refinery/store/query/internal/QueriableModelImpl.java | 39 | ||||
-rw-r--r-- | store/src/main/java/tools/refinery/store/query/internal/RelationalScope.java (renamed from store/src/main/java/tools/refinery/store/query/RelationalScope.java) | 20 | ||||
-rw-r--r-- | store/src/test/java/tools/refinery/store/query/test/QueryTest.java | 2 |
4 files changed, 40 insertions, 23 deletions
diff --git a/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java b/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java index f0ac0276..7558424b 100644 --- a/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java +++ b/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java | |||
@@ -8,7 +8,6 @@ import java.util.List; | |||
8 | import java.util.Map; | 8 | import java.util.Map; |
9 | import java.util.Set; | 9 | import java.util.Set; |
10 | 10 | ||
11 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; | ||
12 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; | 11 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; |
13 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | 12 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; |
14 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; | 13 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; |
@@ -27,7 +26,6 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | |||
27 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | 26 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; |
28 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 27 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
29 | 28 | ||
30 | import tools.refinery.store.query.RelationalScope; | ||
31 | import tools.refinery.store.query.building.DNFAnd; | 29 | import tools.refinery.store.query.building.DNFAnd; |
32 | import tools.refinery.store.query.building.DNFAtom; | 30 | import tools.refinery.store.query.building.DNFAtom; |
33 | import tools.refinery.store.query.building.DNFPredicate; | 31 | import tools.refinery.store.query.building.DNFPredicate; |
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 5b96ba74..414ef2c8 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 | |||
@@ -14,16 +14,18 @@ import org.eclipse.viatra.query.runtime.api.IQueryGroup; | |||
14 | import tools.refinery.store.map.Cursor; | 14 | import tools.refinery.store.map.Cursor; |
15 | import tools.refinery.store.model.Model; | 15 | import tools.refinery.store.model.Model; |
16 | import tools.refinery.store.model.ModelDiffCursor; | 16 | import tools.refinery.store.model.ModelDiffCursor; |
17 | import tools.refinery.store.model.Tuple; | ||
17 | import tools.refinery.store.model.representation.DataRepresentation; | 18 | import tools.refinery.store.model.representation.DataRepresentation; |
19 | import tools.refinery.store.model.representation.Relation; | ||
18 | import tools.refinery.store.query.QueriableModel; | 20 | import tools.refinery.store.query.QueriableModel; |
19 | import tools.refinery.store.query.QueriableModelStore; | 21 | import tools.refinery.store.query.QueriableModelStore; |
20 | import tools.refinery.store.query.RelationalScope; | ||
21 | import tools.refinery.store.query.building.DNFPredicate; | 22 | import tools.refinery.store.query.building.DNFPredicate; |
22 | 23 | ||
23 | public class QueriableModelImpl implements QueriableModel { | 24 | public class QueriableModelImpl implements QueriableModel { |
24 | protected final QueriableModelStore store; | 25 | protected final QueriableModelStore store; |
25 | protected final Model model; | 26 | protected final Model model; |
26 | 27 | ||
28 | protected final RelationalScope scope; | ||
27 | protected final AdvancedViatraQueryEngine engine; | 29 | protected final AdvancedViatraQueryEngine engine; |
28 | protected final Map<DNFPredicate, RawPatternMatcher> predicate2Matcher; | 30 | protected final Map<DNFPredicate, RawPatternMatcher> predicate2Matcher; |
29 | 31 | ||
@@ -31,15 +33,11 @@ public class QueriableModelImpl implements QueriableModel { | |||
31 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> predicates2PQuery) { | 33 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> predicates2PQuery) { |
32 | this.store = store; | 34 | this.store = store; |
33 | this.model = model; | 35 | this.model = model; |
34 | this.engine = initEngine(store, model); | 36 | this.scope = new RelationalScope(model, store.getViews()); |
37 | this.engine = AdvancedViatraQueryEngine.createUnmanagedEngine(scope); | ||
35 | this.predicate2Matcher = initMatchers(engine, predicates2PQuery); | 38 | this.predicate2Matcher = initMatchers(engine, predicates2PQuery); |
36 | } | 39 | } |
37 | 40 | ||
38 | private AdvancedViatraQueryEngine initEngine(QueriableModelStore store, Model model) { | ||
39 | RelationalScope scope = new RelationalScope(model, store.getViews()); | ||
40 | return AdvancedViatraQueryEngine.createUnmanagedEngine(scope); | ||
41 | } | ||
42 | |||
43 | private Map<DNFPredicate, RawPatternMatcher> initMatchers(AdvancedViatraQueryEngine engine, | 41 | private Map<DNFPredicate, RawPatternMatcher> initMatchers(AdvancedViatraQueryEngine engine, |
44 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> predicates2pQuery) { | 42 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> predicates2pQuery) { |
45 | // 1. prepare group | 43 | // 1. prepare group |
@@ -75,16 +73,30 @@ public class QueriableModelImpl implements QueriableModel { | |||
75 | return model.getAll(representation); | 73 | return model.getAll(representation); |
76 | } | 74 | } |
77 | 75 | ||
76 | @SuppressWarnings("unchecked") | ||
78 | @Override | 77 | @Override |
79 | public <K, V> V put(DataRepresentation<K, V> representation, K key, V value) { | 78 | public <K, V> V put(DataRepresentation<K, V> representation, K key, V value) { |
80 | // TODO Auto-generated method stub | 79 | V oldValue = this.model.put(representation, key, value); |
81 | return null; | 80 | if(representation instanceof Relation<?> relation) { |
81 | this.scope.processUpdate((Relation<V>)relation, (Tuple)key, oldValue, value); | ||
82 | } | ||
83 | return oldValue; | ||
82 | } | 84 | } |
83 | 85 | ||
84 | @Override | 86 | @Override |
85 | public <K, V> void putAll(DataRepresentation<K, V> representation, Cursor<K, V> cursor) { | 87 | public <K, V> void putAll(DataRepresentation<K, V> representation, Cursor<K, V> cursor) { |
86 | // TODO Auto-generated method stub | 88 | if(representation instanceof Relation<?>) { |
87 | 89 | @SuppressWarnings("unchecked") | |
90 | Relation<V> relation = (Relation<V>) representation; | ||
91 | while(cursor.move()) { | ||
92 | Tuple key = (Tuple) cursor.getKey(); | ||
93 | V newValue = cursor.getValue(); | ||
94 | V oldValue = this.model.put(relation, key, newValue); | ||
95 | this.scope.processUpdate(relation, key, oldValue, newValue); | ||
96 | } | ||
97 | } else { | ||
98 | this.model.putAll(representation, cursor); | ||
99 | } | ||
88 | } | 100 | } |
89 | 101 | ||
90 | @Override | 102 | @Override |
@@ -155,8 +167,7 @@ public class QueriableModelImpl implements QueriableModel { | |||
155 | } | 167 | } |
156 | @Override | 168 | @Override |
157 | public void flushChanges() { | 169 | public void flushChanges() { |
158 | // TODO Auto-generated method stub | 170 | this.scope.flush(); |
159 | |||
160 | } | 171 | } |
161 | 172 | ||
162 | @Override | 173 | @Override |
diff --git a/store/src/main/java/tools/refinery/store/query/RelationalScope.java b/store/src/main/java/tools/refinery/store/query/internal/RelationalScope.java index e37fdb95..e8d45356 100644 --- a/store/src/main/java/tools/refinery/store/query/RelationalScope.java +++ b/store/src/main/java/tools/refinery/store/query/internal/RelationalScope.java | |||
@@ -1,4 +1,4 @@ | |||
1 | package tools.refinery.store.query; | 1 | package tools.refinery.store.query.internal; |
2 | 2 | ||
3 | import java.util.Set; | 3 | import java.util.Set; |
4 | 4 | ||
@@ -9,8 +9,8 @@ import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; | |||
9 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; | 9 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; |
10 | 10 | ||
11 | import tools.refinery.store.model.Model; | 11 | import tools.refinery.store.model.Model; |
12 | import tools.refinery.store.query.internal.ModelUpdateListener; | 12 | import tools.refinery.store.model.Tuple; |
13 | import tools.refinery.store.query.internal.RelationalEngineContext; | 13 | import tools.refinery.store.model.representation.Relation; |
14 | import tools.refinery.store.query.view.RelationView; | 14 | import tools.refinery.store.query.view.RelationView; |
15 | 15 | ||
16 | public class RelationalScope extends QueryScope{ | 16 | public class RelationalScope extends QueryScope{ |
@@ -23,10 +23,18 @@ public class RelationalScope extends QueryScope{ | |||
23 | //this.changeListener = new | 23 | //this.changeListener = new |
24 | } | 24 | } |
25 | 25 | ||
26 | // public <D> void processUpdate(RelationView<D> relationView, Tuple key, D oldValue, D newValue) { | 26 | public <D> void processUpdate(Relation<D> relation, Tuple key, D oldValue, D newValue) { |
27 | // updateListener.processChange(relationView, key, oldValue, newValue); | 27 | updateListener.addUpdate(relation, key, oldValue, newValue); |
28 | // } | 28 | } |
29 | |||
30 | public boolean hasChange() { | ||
31 | return updateListener.hasChange(); | ||
32 | } | ||
29 | 33 | ||
34 | public void flush() { | ||
35 | updateListener.flush(); | ||
36 | } | ||
37 | |||
30 | @Override | 38 | @Override |
31 | protected IEngineContext createEngineContext(ViatraQueryEngine engine, IIndexingErrorListener errorListener, | 39 | protected IEngineContext createEngineContext(ViatraQueryEngine engine, IIndexingErrorListener errorListener, |
32 | Logger logger) { | 40 | Logger logger) { |
diff --git a/store/src/test/java/tools/refinery/store/query/test/QueryTest.java b/store/src/test/java/tools/refinery/store/query/test/QueryTest.java index beb50bf3..63714538 100644 --- a/store/src/test/java/tools/refinery/store/query/test/QueryTest.java +++ b/store/src/test/java/tools/refinery/store/query/test/QueryTest.java | |||
@@ -20,7 +20,6 @@ import tools.refinery.store.model.ModelStoreImpl; | |||
20 | import tools.refinery.store.model.Tuple; | 20 | import tools.refinery.store.model.Tuple; |
21 | import tools.refinery.store.model.representation.Relation; | 21 | import tools.refinery.store.model.representation.Relation; |
22 | import tools.refinery.store.model.representation.TruthValue; | 22 | import tools.refinery.store.model.representation.TruthValue; |
23 | import tools.refinery.store.query.RelationalScope; | ||
24 | import tools.refinery.store.query.building.DNFAnd; | 23 | import tools.refinery.store.query.building.DNFAnd; |
25 | import tools.refinery.store.query.building.DNFPredicate; | 24 | import tools.refinery.store.query.building.DNFPredicate; |
26 | import tools.refinery.store.query.building.EquivalenceAtom; | 25 | import tools.refinery.store.query.building.EquivalenceAtom; |
@@ -29,6 +28,7 @@ import tools.refinery.store.query.building.RelationAtom; | |||
29 | import tools.refinery.store.query.building.Variable; | 28 | import tools.refinery.store.query.building.Variable; |
30 | import tools.refinery.store.query.internal.DNF2PQuery; | 29 | import tools.refinery.store.query.internal.DNF2PQuery; |
31 | import tools.refinery.store.query.internal.RawPatternMatcher; | 30 | import tools.refinery.store.query.internal.RawPatternMatcher; |
31 | import tools.refinery.store.query.internal.RelationalScope; | ||
32 | import tools.refinery.store.query.view.FilteredRelationView; | 32 | import tools.refinery.store.query.view.FilteredRelationView; |
33 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 33 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
34 | import tools.refinery.store.query.view.RelationView; | 34 | import tools.refinery.store.query.view.RelationView; |