diff options
author | 2022-09-27 02:08:44 +0200 | |
---|---|---|
committer | 2022-10-03 20:06:52 +0200 | |
commit | 7a310819cbbdd70767a9ed17e1bf84c2add9faed (patch) | |
tree | a381add842a69115d778ac902b47b40159a7feaf /subprojects/store-query-viatra/src/main | |
parent | refactor: remove viatra dependency from store (diff) | |
download | refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.gz refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.zst refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.zip |
refactor: tuples in QueryableModel
Diffstat (limited to 'subprojects/store-query-viatra/src/main')
7 files changed, 62 insertions, 31 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java new file mode 100644 index 00000000..46c28434 --- /dev/null +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraTupleLike.java | |||
@@ -0,0 +1,18 @@ | |||
1 | package tools.refinery.store.query.viatra; | ||
2 | |||
3 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | ||
4 | import tools.refinery.store.tuple.Tuple1; | ||
5 | import tools.refinery.store.tuple.TupleLike; | ||
6 | |||
7 | public record ViatraTupleLike(ITuple wrappedTuple) implements TupleLike { | ||
8 | @Override | ||
9 | public int getSize() { | ||
10 | return wrappedTuple.getSize(); | ||
11 | } | ||
12 | |||
13 | @Override | ||
14 | public int get(int element) { | ||
15 | var wrappedValue = (Tuple1) wrappedTuple.get(element); | ||
16 | return wrappedValue.value0(); | ||
17 | } | ||
18 | } | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java index be348a63..2c488319 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RawPatternMatcher.java | |||
@@ -2,8 +2,9 @@ package tools.refinery.store.query.viatra.internal; | |||
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; | 3 | import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; |
4 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; | 4 | import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.AbstractTuple; | 5 | import tools.refinery.store.query.viatra.ViatraTupleLike; |
6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | 6 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.tuple.TupleLike; | ||
7 | 8 | ||
8 | import java.util.Optional; | 9 | import java.util.Optional; |
9 | import java.util.stream.Stream; | 10 | import java.util.stream.Stream; |
@@ -13,39 +14,50 @@ public class RawPatternMatcher extends GenericPatternMatcher { | |||
13 | 14 | ||
14 | public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) { | 15 | public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) { |
15 | super(specification); | 16 | super(specification); |
16 | this.empty = new Object[specification.getParameterNames().size()]; | 17 | empty = new Object[specification.getParameterNames().size()]; |
17 | } | 18 | } |
18 | 19 | ||
19 | public boolean hasResult() { | 20 | public boolean hasResult() { |
20 | return hasResult(empty); | 21 | return backend.hasMatch(empty); |
21 | } | 22 | } |
22 | 23 | ||
23 | public boolean hasResult(Object[] parameters) { | 24 | public boolean hasResult(Tuple parameters) { |
24 | return this.backend.hasMatch(parameters); | 25 | return backend.hasMatch(toParametersArray(parameters)); |
25 | } | 26 | } |
26 | 27 | ||
27 | public Optional<Object[]> oneResult() { | 28 | public Optional<TupleLike> oneResult() { |
28 | return oneResult(empty); | 29 | return backend.getOneArbitraryMatch(empty).map(ViatraTupleLike::new); |
29 | } | 30 | } |
30 | 31 | ||
31 | public Optional<Object[]> oneResult(Object[] parameters) { | 32 | public Optional<TupleLike> oneResult(Tuple parameters) { |
32 | Optional<Tuple> tuple = this.backend.getOneArbitraryMatch(parameters); | 33 | return backend.getOneArbitraryMatch(toParametersArray(parameters)).map(ViatraTupleLike::new); |
33 | return tuple.map(AbstractTuple::getElements); | ||
34 | } | 34 | } |
35 | 35 | ||
36 | public Stream<Object[]> allResults() { | 36 | public Stream<TupleLike> allResults() { |
37 | return allResults(empty); | 37 | return backend.getAllMatches(empty).map(ViatraTupleLike::new); |
38 | } | 38 | } |
39 | 39 | ||
40 | public Stream<Object[]> allResults(Object[] parameters) { | 40 | public Stream<TupleLike> allResults(Tuple parameters) { |
41 | return this.backend.getAllMatches(parameters).map(AbstractTuple::getElements); | 41 | return backend.getAllMatches(toParametersArray(parameters)).map(ViatraTupleLike::new); |
42 | } | 42 | } |
43 | 43 | ||
44 | public int countResults() { | 44 | public int countResults() { |
45 | return countResults(empty); | 45 | return backend.countMatches(empty); |
46 | } | 46 | } |
47 | 47 | ||
48 | public int countResults(Object[] parameters) { | 48 | public int countResults(Tuple parameters) { |
49 | return backend.countMatches(parameters); | 49 | return backend.countMatches(toParametersArray(parameters)); |
50 | } | ||
51 | |||
52 | private Object[] toParametersArray(Tuple tuple) { | ||
53 | int size = tuple.getSize(); | ||
54 | var array = new Object[tuple.getSize()]; | ||
55 | for (int i = 0; i < size; i++) { | ||
56 | var value = tuple.get(i); | ||
57 | if (value >= 0) { | ||
58 | array[i] = Tuple.of(value); | ||
59 | } | ||
60 | } | ||
61 | return array; | ||
50 | } | 62 | } |
51 | } | 63 | } |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java index 8dfa22e0..5ddad67d 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java | |||
@@ -6,7 +6,7 @@ import org.eclipse.viatra.query.runtime.api.scope.IEngineContext; | |||
6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; | 6 | import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; |
7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; | 7 | import org.eclipse.viatra.query.runtime.api.scope.QueryScope; |
8 | import tools.refinery.store.model.Model; | 8 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.model.Tuple; | 9 | import tools.refinery.store.tuple.Tuple; |
10 | import tools.refinery.store.model.representation.Relation; | 10 | import tools.refinery.store.model.representation.Relation; |
11 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; | 11 | import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; |
12 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; | 12 | import tools.refinery.store.query.viatra.internal.viewupdate.ModelUpdateListener; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java index 3803702d..1c15e8f9 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraQueryableModel.java | |||
@@ -8,12 +8,13 @@ import tools.refinery.store.map.Cursor; | |||
8 | import tools.refinery.store.map.DiffCursor; | 8 | import tools.refinery.store.map.DiffCursor; |
9 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.model.ModelDiffCursor; | 10 | import tools.refinery.store.model.ModelDiffCursor; |
11 | import tools.refinery.store.model.Tuple; | ||
12 | import tools.refinery.store.model.representation.DataRepresentation; | 11 | import tools.refinery.store.model.representation.DataRepresentation; |
13 | import tools.refinery.store.model.representation.Relation; | 12 | import tools.refinery.store.model.representation.Relation; |
14 | import tools.refinery.store.query.QueryableModel; | 13 | import tools.refinery.store.query.QueryableModel; |
15 | import tools.refinery.store.query.QueryableModelStore; | 14 | import tools.refinery.store.query.QueryableModelStore; |
16 | import tools.refinery.store.query.building.DNFPredicate; | 15 | import tools.refinery.store.query.building.DNFPredicate; |
16 | import tools.refinery.store.tuple.Tuple; | ||
17 | import tools.refinery.store.tuple.TupleLike; | ||
17 | 18 | ||
18 | import java.util.HashMap; | 19 | import java.util.HashMap; |
19 | import java.util.Map; | 20 | import java.util.Map; |
@@ -124,9 +125,9 @@ public class ViatraQueryableModel implements QueryableModel { | |||
124 | return result; | 125 | return result; |
125 | } | 126 | } |
126 | 127 | ||
127 | protected void validateParameters(DNFPredicate predicate, Object[] parameters) { | 128 | protected void validateParameters(DNFPredicate predicate, Tuple parameters) { |
128 | int predicateArity = predicate.getVariables().size(); | 129 | int predicateArity = predicate.getVariables().size(); |
129 | int parameterArity = parameters.length; | 130 | int parameterArity = parameters.getSize(); |
130 | if (parameterArity != predicateArity) { | 131 | if (parameterArity != predicateArity) { |
131 | throw new IllegalArgumentException( | 132 | throw new IllegalArgumentException( |
132 | "Predicate %s with %d arity called with different number of parameters (%d)" | 133 | "Predicate %s with %d arity called with different number of parameters (%d)" |
@@ -140,29 +141,29 @@ public class ViatraQueryableModel implements QueryableModel { | |||
140 | } | 141 | } |
141 | 142 | ||
142 | @Override | 143 | @Override |
143 | public boolean hasResult(DNFPredicate predicate, Object[] parameters) { | 144 | public boolean hasResult(DNFPredicate predicate, Tuple parameters) { |
144 | validateParameters(predicate, parameters); | 145 | validateParameters(predicate, parameters); |
145 | return getMatcher(predicate).hasResult(parameters); | 146 | return getMatcher(predicate).hasResult(parameters); |
146 | } | 147 | } |
147 | 148 | ||
148 | @Override | 149 | @Override |
149 | public Optional<Object[]> oneResult(DNFPredicate predicate) { | 150 | public Optional<TupleLike> oneResult(DNFPredicate predicate) { |
150 | return getMatcher(predicate).oneResult(); | 151 | return getMatcher(predicate).oneResult(); |
151 | } | 152 | } |
152 | 153 | ||
153 | @Override | 154 | @Override |
154 | public Optional<Object[]> oneResult(DNFPredicate predicate, Object[] parameters) { | 155 | public Optional<TupleLike> oneResult(DNFPredicate predicate, Tuple parameters) { |
155 | validateParameters(predicate, parameters); | 156 | validateParameters(predicate, parameters); |
156 | return getMatcher(predicate).oneResult(parameters); | 157 | return getMatcher(predicate).oneResult(parameters); |
157 | } | 158 | } |
158 | 159 | ||
159 | @Override | 160 | @Override |
160 | public Stream<Object[]> allResults(DNFPredicate predicate) { | 161 | public Stream<TupleLike> allResults(DNFPredicate predicate) { |
161 | return getMatcher(predicate).allResults(); | 162 | return getMatcher(predicate).allResults(); |
162 | } | 163 | } |
163 | 164 | ||
164 | @Override | 165 | @Override |
165 | public Stream<Object[]> allResults(DNFPredicate predicate, Object[] parameters) { | 166 | public Stream<TupleLike> allResults(DNFPredicate predicate, Tuple parameters) { |
166 | validateParameters(predicate, parameters); | 167 | validateParameters(predicate, parameters); |
167 | return getMatcher(predicate).allResults(parameters); | 168 | return getMatcher(predicate).allResults(parameters); |
168 | } | 169 | } |
@@ -173,7 +174,7 @@ public class ViatraQueryableModel implements QueryableModel { | |||
173 | } | 174 | } |
174 | 175 | ||
175 | @Override | 176 | @Override |
176 | public int countResults(DNFPredicate predicate, Object[] parameters) { | 177 | public int countResults(DNFPredicate predicate, Tuple parameters) { |
177 | validateParameters(predicate, parameters); | 178 | validateParameters(predicate, parameters); |
178 | return getMatcher(predicate).countResults(parameters); | 179 | return getMatcher(predicate).countResults(parameters); |
179 | 180 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java index 5a0da315..1a2fcee7 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ModelUpdateListener.java | |||
@@ -3,7 +3,7 @@ package tools.refinery.store.query.viatra.internal.viewupdate; | |||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | 3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; |
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import tools.refinery.store.model.Tuple; | 6 | import tools.refinery.store.tuple.Tuple; |
7 | import tools.refinery.store.model.representation.Relation; | 7 | import tools.refinery.store.model.representation.Relation; |
8 | import tools.refinery.store.query.view.RelationView; | 8 | import tools.refinery.store.query.view.RelationView; |
9 | 9 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java index e13a9cb8..49f4c501 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateBuffer.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.viewupdate; | 1 | package tools.refinery.store.query.viatra.internal.viewupdate; |
2 | 2 | ||
3 | import tools.refinery.store.model.Tuple; | 3 | import tools.refinery.store.tuple.Tuple; |
4 | 4 | ||
5 | import java.util.ArrayList; | 5 | import java.util.ArrayList; |
6 | import java.util.Arrays; | 6 | import java.util.Arrays; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java index 62a10e45..74d0b366 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdateTranslator.java | |||
@@ -4,7 +4,7 @@ import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | |||
4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
7 | import tools.refinery.store.model.Tuple; | 7 | import tools.refinery.store.tuple.Tuple; |
8 | import tools.refinery.store.query.view.RelationView; | 8 | import tools.refinery.store.query.view.RelationView; |
9 | 9 | ||
10 | import java.util.Objects; | 10 | import java.util.Objects; |