diff options
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate')
4 files changed, 27 insertions, 14 deletions
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 25919888..5a0da315 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 | |||
@@ -1,5 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.viewupdate; | 1 | package tools.refinery.store.query.viatra.internal.viewupdate; |
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | ||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
4 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
5 | import tools.refinery.store.model.Tuple; | 6 | import tools.refinery.store.model.Tuple; |
@@ -46,20 +47,23 @@ public class ModelUpdateListener { | |||
46 | return view2Buffers.containsKey(relationalKey); | 47 | return view2Buffers.containsKey(relationalKey); |
47 | } | 48 | } |
48 | 49 | ||
49 | public <D> void addListener(RelationView<D> relationView, ITuple seed, IQueryRuntimeContextListener listener) { | 50 | public <D> void addListener(IInputKey key, RelationView<D> relationView, ITuple seed, |
51 | IQueryRuntimeContextListener listener) { | ||
50 | if (view2Buffers.containsKey(relationView)) { | 52 | if (view2Buffers.containsKey(relationView)) { |
51 | ViewUpdateTranslator<D> updateListener = new ViewUpdateTranslator<>(relationView, seed, listener); | 53 | ViewUpdateTranslator<D> updateListener = new ViewUpdateTranslator<>(key, relationView, seed, listener); |
52 | ViewUpdateBuffer<D> updateBuffer = new ViewUpdateBuffer<>(updateListener); | 54 | ViewUpdateBuffer<D> updateBuffer = new ViewUpdateBuffer<>(updateListener); |
53 | view2Buffers.get(relationView).add(updateBuffer); | 55 | view2Buffers.get(relationView).add(updateBuffer); |
54 | } else | 56 | } else { |
55 | throw new IllegalArgumentException(); | 57 | throw new IllegalArgumentException(); |
58 | } | ||
56 | } | 59 | } |
57 | 60 | ||
58 | public void removeListener(RelationView<?> relationView, ITuple seed, IQueryRuntimeContextListener listener) { | 61 | public void removeListener(IInputKey key, RelationView<?> relationView, ITuple seed, |
62 | IQueryRuntimeContextListener listener) { | ||
59 | if (view2Buffers.containsKey(relationView)) { | 63 | if (view2Buffers.containsKey(relationView)) { |
60 | Set<ViewUpdateBuffer<?>> buffers = this.view2Buffers.get(relationView); | 64 | Set<ViewUpdateBuffer<?>> buffers = this.view2Buffers.get(relationView); |
61 | for (var buffer : buffers) { | 65 | for (var buffer : buffers) { |
62 | if (buffer.getUpdateListener().equals(relationView, seed, listener)) { | 66 | if (buffer.getUpdateListener().equals(key, relationView, seed, listener)) { |
63 | // remove buffer and terminate immediately, or it will break iterator. | 67 | // remove buffer and terminate immediately, or it will break iterator. |
64 | buffers.remove(buffer); | 68 | buffers.remove(buffer); |
65 | return; | 69 | return; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdate.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdate.java index c727f046..b9406018 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdate.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/viewupdate/ViewUpdate.java | |||
@@ -3,8 +3,7 @@ package tools.refinery.store.query.viatra.internal.viewupdate; | |||
3 | import java.util.Arrays; | 3 | import java.util.Arrays; |
4 | import java.util.Objects; | 4 | import java.util.Objects; |
5 | 5 | ||
6 | record ViewUpdate (Object[] tuple, boolean isInsertion) { | 6 | record ViewUpdate(Object[] tuple, boolean isInsertion) { |
7 | |||
8 | @Override | 7 | @Override |
9 | public int hashCode() { | 8 | public int hashCode() { |
10 | final int prime = 31; | 9 | final int prime = 31; |
@@ -28,7 +27,6 @@ record ViewUpdate (Object[] tuple, boolean isInsertion) { | |||
28 | 27 | ||
29 | @Override | 28 | @Override |
30 | public String toString() { | 29 | public String toString() { |
31 | return "ViewUpdate [" + Arrays.toString(tuple) + "insertion= "+this.isInsertion+"]"; | 30 | return "ViewUpdate [" + Arrays.toString(tuple) + "insertion= " + this.isInsertion + "]"; |
32 | } | 31 | } |
33 | |||
34 | } | 32 | } |
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 5a4243f2..e13a9cb8 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 | |||
@@ -8,6 +8,7 @@ import java.util.List; | |||
8 | 8 | ||
9 | public class ViewUpdateBuffer<D> { | 9 | public class ViewUpdateBuffer<D> { |
10 | protected final ViewUpdateTranslator<D> updateListener; | 10 | protected final ViewUpdateTranslator<D> updateListener; |
11 | |||
11 | protected final List<ViewUpdate> buffer = new ArrayList<>(); | 12 | protected final List<ViewUpdate> buffer = new ArrayList<>(); |
12 | 13 | ||
13 | public ViewUpdateBuffer(ViewUpdateTranslator<D> updateListener) { | 14 | public ViewUpdateBuffer(ViewUpdateTranslator<D> updateListener) { |
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 2f7f9a9c..62a10e45 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 | |||
@@ -1,5 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.viewupdate; | 1 | package tools.refinery.store.query.viatra.internal.viewupdate; |
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; | ||
3 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; | 4 | import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; |
4 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; | 5 | import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; |
5 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | 6 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; |
@@ -9,29 +10,38 @@ import tools.refinery.store.query.view.RelationView; | |||
9 | import java.util.Objects; | 10 | import java.util.Objects; |
10 | 11 | ||
11 | public class ViewUpdateTranslator<D> { | 12 | public class ViewUpdateTranslator<D> { |
13 | private final IInputKey wrappedKey; | ||
14 | |||
12 | private final RelationView<D> key; | 15 | private final RelationView<D> key; |
13 | 16 | ||
14 | private final ITuple filter; | 17 | private final ITuple filter; |
15 | 18 | ||
16 | private final IQueryRuntimeContextListener listener; | 19 | private final IQueryRuntimeContextListener listener; |
17 | 20 | ||
18 | public ViewUpdateTranslator(RelationView<D> key, ITuple filter, IQueryRuntimeContextListener listener) { | 21 | public ViewUpdateTranslator(IInputKey wrappedKey, RelationView<D> key, ITuple filter, |
22 | IQueryRuntimeContextListener listener) { | ||
19 | super(); | 23 | super(); |
24 | this.wrappedKey = wrappedKey; | ||
20 | this.key = key; | 25 | this.key = key; |
21 | this.filter = filter; | 26 | this.filter = filter; |
22 | this.listener = listener; | 27 | this.listener = listener; |
23 | } | 28 | } |
24 | 29 | ||
25 | public boolean equals(RelationView<?> relationView, ITuple seed, IQueryRuntimeContextListener listener) { | 30 | public boolean equals(IInputKey wrappedKey, RelationView<?> relationView, ITuple seed, |
26 | return key == relationView && filter.equals(seed) && this.listener == listener; | 31 | IQueryRuntimeContextListener listener) { |
32 | return this.wrappedKey == wrappedKey && key == relationView && filter.equals(seed) && this.listener == listener; | ||
27 | } | 33 | } |
28 | 34 | ||
29 | public void processChange(ViewUpdate change) { | 35 | public void processChange(ViewUpdate change) { |
30 | listener.update(key, Tuples.flatTupleOf(change.tuple()), change.isInsertion()); | 36 | listener.update(wrappedKey, Tuples.flatTupleOf(change.tuple()), change.isInsertion()); |
31 | } | 37 | } |
32 | 38 | ||
39 | @SuppressWarnings("squid:S1168") | ||
33 | public Object[] isMatching(Tuple tuple, D value) { | 40 | public Object[] isMatching(Tuple tuple, D value) { |
34 | return isMatching(key.getWrappedKey().transform(tuple, value), filter); | 41 | if (!key.filter(tuple, value)) { |
42 | return null; | ||
43 | } | ||
44 | return isMatching(key.forwardMap(tuple, value), filter); | ||
35 | } | 45 | } |
36 | 46 | ||
37 | @SuppressWarnings("squid:S1168") | 47 | @SuppressWarnings("squid:S1168") |