diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-02-01 20:22:28 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-02-01 20:22:28 +0100 |
commit | 8d9b031e3be7635bb57871df588a27df57f44e78 (patch) | |
tree | 4065579c67cedf651dee3e3c867efd33da9d6ca6 /subprojects/store-query-viatra/src | |
parent | chore(deps): bump dependencies (diff) | |
download | refinery-8d9b031e3be7635bb57871df588a27df57f44e78.tar.gz refinery-8d9b031e3be7635bb57871df588a27df57f44e78.tar.zst refinery-8d9b031e3be7635bb57871df588a27df57f44e78.zip |
refactor: VIATRA adapter fixes
Diffstat (limited to 'subprojects/store-query-viatra/src')
5 files changed, 28 insertions, 17 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/DummyBaseIndexer.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/DummyBaseIndexer.java index 4b311a64..29f0536c 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/DummyBaseIndexer.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/DummyBaseIndexer.java | |||
@@ -38,21 +38,21 @@ public class DummyBaseIndexer implements IBaseIndex { | |||
38 | 38 | ||
39 | @Override | 39 | @Override |
40 | public boolean addIndexingErrorListener(IIndexingErrorListener listener) { | 40 | public boolean addIndexingErrorListener(IIndexingErrorListener listener) { |
41 | return true; | 41 | return false; |
42 | } | 42 | } |
43 | 43 | ||
44 | @Override | 44 | @Override |
45 | public boolean removeIndexingErrorListener(IIndexingErrorListener listener) { | 45 | public boolean removeIndexingErrorListener(IIndexingErrorListener listener) { |
46 | return true; | 46 | return false; |
47 | } | 47 | } |
48 | 48 | ||
49 | @Override | 49 | @Override |
50 | public boolean addInstanceObserver(IInstanceObserver observer, Object observedObject) { | 50 | public boolean addInstanceObserver(IInstanceObserver observer, Object observedObject) { |
51 | return true; | 51 | return false; |
52 | } | 52 | } |
53 | 53 | ||
54 | @Override | 54 | @Override |
55 | public boolean removeInstanceObserver(IInstanceObserver observer, Object observedObject) { | 55 | public boolean removeInstanceObserver(IInstanceObserver observer, Object observedObject) { |
56 | return true; | 56 | return false; |
57 | } | 57 | } |
58 | } | 58 | } |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalQueryMetaContext.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalQueryMetaContext.java index 47b83634..81046b2a 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalQueryMetaContext.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalQueryMetaContext.java | |||
@@ -26,6 +26,11 @@ public class RelationalQueryMetaContext extends AbstractQueryMetaContext { | |||
26 | } | 26 | } |
27 | 27 | ||
28 | @Override | 28 | @Override |
29 | public boolean canLeadOutOfScope(IInputKey key) { | ||
30 | return false; | ||
31 | } | ||
32 | |||
33 | @Override | ||
29 | public Collection<InputKeyImplication> getImplications(IInputKey implyingKey) { | 34 | public Collection<InputKeyImplication> getImplications(IInputKey implyingKey) { |
30 | ensureValidKey(implyingKey); | 35 | ensureValidKey(implyingKey); |
31 | return Set.of(); | 36 | return Set.of(); |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java index 7375b240..9c1d966c 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java | |||
@@ -10,7 +10,6 @@ import tools.refinery.store.model.Model; | |||
10 | import tools.refinery.store.query.viatra.internal.pquery.RelationViewWrapper; | 10 | import tools.refinery.store.query.viatra.internal.pquery.RelationViewWrapper; |
11 | import tools.refinery.store.query.viatra.internal.update.ModelUpdateListener; | 11 | import tools.refinery.store.query.viatra.internal.update.ModelUpdateListener; |
12 | import tools.refinery.store.query.view.AnyRelationView; | 12 | import tools.refinery.store.query.view.AnyRelationView; |
13 | import tools.refinery.store.query.view.RelationView; | ||
14 | 13 | ||
15 | import java.lang.reflect.InvocationTargetException; | 14 | import java.lang.reflect.InvocationTargetException; |
16 | import java.util.Iterator; | 15 | import java.util.Iterator; |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java index eb815588..f2cb8d8d 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java | |||
@@ -27,6 +27,8 @@ import java.util.function.Function; | |||
27 | import java.util.stream.Collectors; | 27 | import java.util.stream.Collectors; |
28 | 28 | ||
29 | public class DNF2PQuery { | 29 | public class DNF2PQuery { |
30 | private static final Object P_CONSTRAINT_LOCK = new Object(); | ||
31 | |||
30 | private final Set<DNF> translating = new LinkedHashSet<>(); | 32 | private final Set<DNF> translating = new LinkedHashSet<>(); |
31 | 33 | ||
32 | private final Map<DNF, RawPQuery> dnf2PQueryMap = new HashMap<>(); | 34 | private final Map<DNF, RawPQuery> dnf2PQueryMap = new HashMap<>(); |
@@ -84,17 +86,22 @@ public class DNF2PQuery { | |||
84 | } | 86 | } |
85 | pQuery.setParameters(parameterList); | 87 | pQuery.setParameters(parameterList); |
86 | 88 | ||
87 | for (DNFAnd clause : dnfQuery.getClauses()) { | 89 | // The constructor of {@link org.eclipse.viatra.query.runtime.matchers.psystem.BasePConstraint} mutates |
88 | PBody body = new PBody(pQuery); | 90 | // global static state (<code>nextID</code>) without locking. Therefore, we need to synchronize before creating |
89 | List<ExportedParameter> symbolicParameters = new ArrayList<>(); | 91 | // any query constraints to avoid a data race. |
90 | for (var param : dnfQuery.getParameters()) { | 92 | synchronized (P_CONSTRAINT_LOCK) { |
91 | PVariable pVar = body.getOrCreateVariableByName(param.getUniqueName()); | 93 | for (DNFAnd clause : dnfQuery.getClauses()) { |
92 | symbolicParameters.add(new ExportedParameter(body, pVar, parameters.get(param))); | 94 | PBody body = new PBody(pQuery); |
93 | } | 95 | List<ExportedParameter> symbolicParameters = new ArrayList<>(); |
94 | body.setSymbolicParameters(symbolicParameters); | 96 | for (var param : dnfQuery.getParameters()) { |
95 | pQuery.addBody(body); | 97 | PVariable pVar = body.getOrCreateVariableByName(param.getUniqueName()); |
96 | for (DNFAtom constraint : clause.constraints()) { | 98 | symbolicParameters.add(new ExportedParameter(body, pVar, parameters.get(param))); |
97 | translateDNFAtom(constraint, body); | 99 | } |
100 | body.setSymbolicParameters(symbolicParameters); | ||
101 | pQuery.addBody(body); | ||
102 | for (DNFAtom constraint : clause.constraints()) { | ||
103 | translateDNFAtom(constraint, body); | ||
104 | } | ||
98 | } | 105 | } |
99 | } | 106 | } |
100 | 107 | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingRelationViewUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingRelationViewUpdateListener.java index c17e826d..0d43eac1 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingRelationViewUpdateListener.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingRelationViewUpdateListener.java | |||
@@ -28,7 +28,7 @@ public class TupleChangingRelationViewUpdateListener<T> extends RelationViewUpda | |||
28 | } else { // fromValue disappears | 28 | } else { // fromValue disappears |
29 | processUpdate(Tuples.flatTupleOf(relationView.forwardMap(key, fromValue)), false); | 29 | processUpdate(Tuples.flatTupleOf(relationView.forwardMap(key, fromValue)), false); |
30 | } | 30 | } |
31 | } else if (toPresent) { // toValue disappears | 31 | } else if (toPresent) { // toValue appears |
32 | processUpdate(Tuples.flatTupleOf(relationView.forwardMap(key, toValue)), true); | 32 | processUpdate(Tuples.flatTupleOf(relationView.forwardMap(key, toValue)), true); |
33 | } | 33 | } |
34 | } | 34 | } |