aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query-viatra/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java')
-rw-r--r--subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryConnectionFactory.java34
-rw-r--r--subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryNodeFactory.java37
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryBuilder.java6
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryStoreAdapter.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/RelationalScope.java8
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryAdapterImpl.java81
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryBuilderImpl.java16
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryStoreAdapterImpl.java6
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/DummyBaseIndexer.java10
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalEngineContext.java6
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalQueryMetaContext.java8
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java12
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendOperationExecutor.java8
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendPositivePatternCall.java18
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/FlatCostFunction.java12
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/GenericTypeExtend.java18
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchBackendFactory.java22
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchResultProvider.java16
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java24
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/AbstractViatraMatcher.java4
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalCursor.java4
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalViatraMatcher.java16
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/IndexerUtils.java53
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/MatcherUtils.java6
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RawPatternMatcher.java6
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalCursor.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalViatraMatcher.java16
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/UnsafeFunctionalCursor.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CheckEvaluator.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/Dnf2PQuery.java68
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/QueryWrapperFactory.java22
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RawPQuery.java16
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RepresentativeElectionConstraint.java45
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatefulMultisetAggregator.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatelessMultisetAggregator.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/SymbolViewWrapper.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/TermEvaluator.java4
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/ValueProviderBasedValuation.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyCopier.java35
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyNormalizer.java38
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java58
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteBackendFactory.java90
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteEngine.java134
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteRecipeCompiler.java228
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java47
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryNodeFactoryExtensions.java44
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionAlgorithm.java137
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionNode.java120
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/StronglyConnectedComponentAlgorithm.java66
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/WeaklyConnectedComponentAlgorithm.java85
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactory.java22
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactoryImpl.java74
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackage.java41
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackageImpl.java96
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipe.java17
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipeImpl.java105
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/ModelUpdateListener.java6
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/RelationViewFilter.java8
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/SymbolViewUpdateListener.java8
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingViewUpdateListener.java2
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TuplePreservingViewUpdateListener.java2
61 files changed, 205 insertions, 1876 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryConnectionFactory.java b/subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryConnectionFactory.java
deleted file mode 100644
index 241c5b58..00000000
--- a/subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryConnectionFactory.java
+++ /dev/null
@@ -1,34 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package org.eclipse.viatra.query.runtime.rete.network;
7
8import org.eclipse.viatra.query.runtime.rete.traceability.RecipeTraceInfo;
9import tools.refinery.store.query.viatra.internal.rete.network.RefineryConnectionFactoryExtensions;
10
11/**
12 * This class overrides some RETE connection types from {@link ConnectionFactory}.
13 * <p>
14 * Since {@link ConnectionFactory} is package-private, this class has to be in the
15 * {@code org.eclipse.viatra.query.runtime.rete.network} package as well.
16 * However, due to JAR signature verification errors, <b>this class cannot be loaded directly</b>
17 * and has to be loaded at runtime as a byte array instead.
18 */
19@SuppressWarnings("unused")
20public class RefineryConnectionFactory extends ConnectionFactory {
21 private final RefineryConnectionFactoryExtensions extensions;
22
23 public RefineryConnectionFactory(ReteContainer reteContainer) {
24 super(reteContainer);
25 extensions = new RefineryConnectionFactoryExtensions(reteContainer);
26 }
27
28 @Override
29 public void connectToParents(RecipeTraceInfo recipeTrace, Node freshNode) {
30 if (!extensions.connectToParents(recipeTrace, freshNode)) {
31 super.connectToParents(recipeTrace, freshNode);
32 }
33 }
34}
diff --git a/subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryNodeFactory.java b/subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryNodeFactory.java
deleted file mode 100644
index 1a76e22a..00000000
--- a/subprojects/store-query-viatra/src/main/java/org/eclipse/viatra/query/runtime/rete/network/RefineryNodeFactory.java
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package org.eclipse.viatra.query.runtime.rete.network;
7
8import org.apache.log4j.Logger;
9import org.eclipse.viatra.query.runtime.rete.recipes.ReteNodeRecipe;
10import org.eclipse.viatra.query.runtime.rete.traceability.TraceInfo;
11import tools.refinery.store.query.viatra.internal.rete.network.RefineryNodeFactoryExtensions;
12
13/**
14 * This class overrides some RETE node types from {@link NodeFactory}.
15 * <p>
16 * Since {@link NodeFactory} is package-private, this class has to be in the
17 * {@code org.eclipse.viatra.query.runtime.rete.network} package as well.
18 * However, due to JAR signature verification errors, <b>this class cannot be loaded directly</b>
19 * and has to be loaded at runtime as a byte array instead.
20 */
21@SuppressWarnings("unused")
22class RefineryNodeFactory extends NodeFactory {
23 private final RefineryNodeFactoryExtensions extensions = new RefineryNodeFactoryExtensions();
24
25 public RefineryNodeFactory(Logger logger) {
26 super(logger);
27 }
28
29 @Override
30 public Supplier createNode(ReteContainer reteContainer, ReteNodeRecipe recipe, TraceInfo... traces) {
31 var extendedResult = extensions.createNode(reteContainer, recipe, traces);
32 if (extendedResult != null) {
33 return extendedResult;
34 }
35 return super.createNode(reteContainer, recipe, traces);
36 }
37}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryBuilder.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryBuilder.java
index 66279c94..d31325f1 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryBuilder.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryBuilder.java
@@ -5,9 +5,9 @@
5 */ 5 */
6package tools.refinery.store.query.viatra; 6package tools.refinery.store.query.viatra;
7 7
8import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions; 8import tools.refinery.viatra.runtime.api.ViatraQueryEngineOptions;
9import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory; 9import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory;
10import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; 10import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint;
11import tools.refinery.store.model.ModelStore; 11import tools.refinery.store.model.ModelStore;
12import tools.refinery.store.query.ModelQueryBuilder; 12import tools.refinery.store.query.ModelQueryBuilder;
13import tools.refinery.store.query.dnf.AnyQuery; 13import tools.refinery.store.query.dnf.AnyQuery;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryStoreAdapter.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryStoreAdapter.java
index da6d7bd5..588c00d4 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryStoreAdapter.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryStoreAdapter.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra; 6package tools.refinery.store.query.viatra;
7 7
8import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions; 8import tools.refinery.viatra.runtime.api.ViatraQueryEngineOptions;
9import tools.refinery.store.model.Model; 9import tools.refinery.store.model.Model;
10import tools.refinery.store.query.ModelQueryStoreAdapter; 10import tools.refinery.store.query.ModelQueryStoreAdapter;
11 11
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 d1a65a89..9303cae6 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,10 +6,10 @@
6package tools.refinery.store.query.viatra.internal; 6package tools.refinery.store.query.viatra.internal;
7 7
8import org.apache.log4j.Logger; 8import org.apache.log4j.Logger;
9import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; 9import tools.refinery.viatra.runtime.api.ViatraQueryEngine;
10import org.eclipse.viatra.query.runtime.api.scope.IEngineContext; 10import tools.refinery.viatra.runtime.api.scope.IEngineContext;
11import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; 11import tools.refinery.viatra.runtime.api.scope.IIndexingErrorListener;
12import org.eclipse.viatra.query.runtime.api.scope.QueryScope; 12import tools.refinery.viatra.runtime.api.scope.QueryScope;
13import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext; 13import tools.refinery.store.query.viatra.internal.context.RelationalEngineContext;
14 14
15public class RelationalScope extends QueryScope { 15public class RelationalScope extends QueryScope {
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryAdapterImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryAdapterImpl.java
index e17386e1..f1209f69 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryAdapterImpl.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryAdapterImpl.java
@@ -5,69 +5,46 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal; 6package tools.refinery.store.query.viatra.internal;
7 7
8import org.eclipse.viatra.query.runtime.api.AdvancedViatraQueryEngine;
9import org.eclipse.viatra.query.runtime.api.GenericQueryGroup;
10import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
11import org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl;
12import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend;
13import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
14import tools.refinery.store.model.Model; 8import tools.refinery.store.model.Model;
15import tools.refinery.store.model.ModelListener; 9import tools.refinery.store.model.ModelListener;
16import tools.refinery.store.query.resultset.AnyResultSet;
17import tools.refinery.store.query.resultset.EmptyResultSet;
18import tools.refinery.store.query.resultset.ResultSet;
19import tools.refinery.store.query.dnf.AnyQuery; 10import tools.refinery.store.query.dnf.AnyQuery;
20import tools.refinery.store.query.dnf.FunctionalQuery; 11import tools.refinery.store.query.dnf.FunctionalQuery;
21import tools.refinery.store.query.dnf.Query; 12import tools.refinery.store.query.dnf.Query;
22import tools.refinery.store.query.dnf.RelationalQuery; 13import tools.refinery.store.query.dnf.RelationalQuery;
14import tools.refinery.store.query.resultset.AnyResultSet;
15import tools.refinery.store.query.resultset.EmptyResultSet;
16import tools.refinery.store.query.resultset.ResultSet;
23import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; 17import tools.refinery.store.query.viatra.ViatraModelQueryAdapter;
24import tools.refinery.store.query.viatra.internal.matcher.FunctionalViatraMatcher; 18import tools.refinery.store.query.viatra.internal.matcher.FunctionalViatraMatcher;
25import tools.refinery.store.query.viatra.internal.matcher.RawPatternMatcher; 19import tools.refinery.store.query.viatra.internal.matcher.RawPatternMatcher;
26import tools.refinery.store.query.viatra.internal.matcher.RelationalViatraMatcher; 20import tools.refinery.store.query.viatra.internal.matcher.RelationalViatraMatcher;
21import tools.refinery.viatra.runtime.api.AdvancedViatraQueryEngine;
22import tools.refinery.viatra.runtime.api.GenericQueryGroup;
23import tools.refinery.viatra.runtime.api.IQuerySpecification;
27 24
28import java.lang.invoke.MethodHandle;
29import java.lang.invoke.MethodHandles;
30import java.util.Collection;
31import java.util.Collections; 25import java.util.Collections;
32import java.util.LinkedHashMap; 26import java.util.LinkedHashMap;
33import java.util.Map; 27import java.util.Map;
34 28
35public class ViatraModelQueryAdapterImpl implements ViatraModelQueryAdapter, ModelListener { 29public class ViatraModelQueryAdapterImpl implements ViatraModelQueryAdapter, ModelListener {
36 private static final String DELAY_MESSAGE_DELIVERY_FIELD_NAME = "delayMessageDelivery";
37 private static final MethodHandle SET_UPDATE_PROPAGATION_DELAYED_HANDLE;
38 private static final String QUERY_BACKENDS_FIELD_NAME = "queryBackends";
39 private static final MethodHandle GET_QUERY_BACKENDS_HANDLE;
40
41 private final Model model; 30 private final Model model;
42 private final ViatraModelQueryStoreAdapterImpl storeAdapter; 31 private final ViatraModelQueryStoreAdapterImpl storeAdapter;
43 private final ViatraQueryEngineImpl queryEngine; 32 private final AdvancedViatraQueryEngine queryEngine;
44 private final Map<AnyQuery, AnyResultSet> resultSets; 33 private final Map<AnyQuery, AnyResultSet> resultSets;
45 private boolean pendingChanges; 34 private boolean pendingChanges;
46 35
47 static {
48 try {
49 var lookup = MethodHandles.privateLookupIn(ViatraQueryEngineImpl.class, MethodHandles.lookup());
50 SET_UPDATE_PROPAGATION_DELAYED_HANDLE = lookup.findSetter(ViatraQueryEngineImpl.class,
51 DELAY_MESSAGE_DELIVERY_FIELD_NAME, Boolean.TYPE);
52 GET_QUERY_BACKENDS_HANDLE = lookup.findGetter(ViatraQueryEngineImpl.class, QUERY_BACKENDS_FIELD_NAME,
53 Map.class);
54 } catch (IllegalAccessException | NoSuchFieldException e) {
55 throw new IllegalStateException("Cannot access private members of %s"
56 .formatted(ViatraQueryEngineImpl.class.getName()), e);
57 }
58 }
59
60 ViatraModelQueryAdapterImpl(Model model, ViatraModelQueryStoreAdapterImpl storeAdapter) { 36 ViatraModelQueryAdapterImpl(Model model, ViatraModelQueryStoreAdapterImpl storeAdapter) {
61 this.model = model; 37 this.model = model;
62 this.storeAdapter = storeAdapter; 38 this.storeAdapter = storeAdapter;
63 var scope = new RelationalScope(this); 39 var scope = new RelationalScope(this);
64 queryEngine = (ViatraQueryEngineImpl) AdvancedViatraQueryEngine.createUnmanagedEngine(scope, 40 queryEngine = AdvancedViatraQueryEngine.createUnmanagedEngine(scope,
65 storeAdapter.getEngineOptions()); 41 storeAdapter.getEngineOptions());
66 42
67 var querySpecifications = storeAdapter.getQuerySpecifications(); 43 var querySpecifications = storeAdapter.getQuerySpecifications();
68 GenericQueryGroup.of( 44 GenericQueryGroup.of(
69 Collections.<IQuerySpecification<?>>unmodifiableCollection(querySpecifications.values()).stream() 45 Collections.<IQuerySpecification<?>>unmodifiableCollection(querySpecifications.values()).stream()
70 ).prepare(queryEngine); 46 ).prepare(queryEngine);
47 queryEngine.flushChanges();
71 var vacuousQueries = storeAdapter.getVacuousQueries(); 48 var vacuousQueries = storeAdapter.getVacuousQueries();
72 resultSets = new LinkedHashMap<>(querySpecifications.size() + vacuousQueries.size()); 49 resultSets = new LinkedHashMap<>(querySpecifications.size() + vacuousQueries.size());
73 for (var entry : querySpecifications.entrySet()) { 50 for (var entry : querySpecifications.entrySet()) {
@@ -79,7 +56,6 @@ public class ViatraModelQueryAdapterImpl implements ViatraModelQueryAdapter, Mod
79 resultSets.put(vacuousQuery, new EmptyResultSet<>(this, (Query<?>) vacuousQuery)); 56 resultSets.put(vacuousQuery, new EmptyResultSet<>(this, (Query<?>) vacuousQuery));
80 } 57 }
81 58
82 setUpdatePropagationDelayed(true);
83 model.addListener(this); 59 model.addListener(this);
84 } 60 }
85 61
@@ -95,30 +71,6 @@ public class ViatraModelQueryAdapterImpl implements ViatraModelQueryAdapter, Mod
95 } 71 }
96 } 72 }
97 73
98 private void setUpdatePropagationDelayed(boolean value) {
99 try {
100 SET_UPDATE_PROPAGATION_DELAYED_HANDLE.invokeExact(queryEngine, value);
101 } catch (Error e) {
102 // Fatal JVM errors should not be wrapped.
103 throw e;
104 } catch (Throwable e) {
105 throw new IllegalStateException("Cannot set %s".formatted(DELAY_MESSAGE_DELIVERY_FIELD_NAME), e);
106 }
107 }
108
109 private Collection<IQueryBackend> getQueryBackends() {
110 try {
111 @SuppressWarnings("unchecked")
112 var backendMap = (Map<IQueryBackendFactory, IQueryBackend>) GET_QUERY_BACKENDS_HANDLE.invokeExact(queryEngine);
113 return backendMap.values();
114 } catch (Error e) {
115 // Fatal JVM errors should not be wrapped.
116 throw e;
117 } catch (Throwable e) {
118 throw new IllegalStateException("Cannot get %s".formatted(QUERY_BACKENDS_FIELD_NAME), e);
119 }
120 }
121
122 @Override 74 @Override
123 public Model getModel() { 75 public Model getModel() {
124 return model; 76 return model;
@@ -154,20 +106,7 @@ public class ViatraModelQueryAdapterImpl implements ViatraModelQueryAdapter, Mod
154 106
155 @Override 107 @Override
156 public void flushChanges() { 108 public void flushChanges() {
157 if (!queryEngine.isUpdatePropagationDelayed()) { 109 queryEngine.flushChanges();
158 throw new IllegalStateException("Trying to flush changes while changes are already being flushed");
159 }
160 if (!pendingChanges) {
161 return;
162 }
163 setUpdatePropagationDelayed(false);
164 try {
165 for (var queryBackend : getQueryBackends()) {
166 queryBackend.flushUpdates();
167 }
168 } finally {
169 setUpdatePropagationDelayed(true);
170 }
171 pendingChanges = false; 110 pendingChanges = false;
172 } 111 }
173 112
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryBuilderImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryBuilderImpl.java
index bf0708bf..c8aa067c 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryBuilderImpl.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryBuilderImpl.java
@@ -5,11 +5,6 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal; 6package tools.refinery.store.query.viatra.internal;
7 7
8import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
9import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions;
10import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHintOptions;
11import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
12import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
13import tools.refinery.store.adapter.AbstractModelAdapterBuilder; 8import tools.refinery.store.adapter.AbstractModelAdapterBuilder;
14import tools.refinery.store.model.ModelStore; 9import tools.refinery.store.model.ModelStore;
15import tools.refinery.store.query.dnf.AnyQuery; 10import tools.refinery.store.query.dnf.AnyQuery;
@@ -23,7 +18,12 @@ import tools.refinery.store.query.viatra.internal.localsearch.FlatCostFunction;
23import tools.refinery.store.query.viatra.internal.localsearch.RelationalLocalSearchBackendFactory; 18import tools.refinery.store.query.viatra.internal.localsearch.RelationalLocalSearchBackendFactory;
24import tools.refinery.store.query.viatra.internal.matcher.RawPatternMatcher; 19import tools.refinery.store.query.viatra.internal.matcher.RawPatternMatcher;
25import tools.refinery.store.query.viatra.internal.pquery.Dnf2PQuery; 20import tools.refinery.store.query.viatra.internal.pquery.Dnf2PQuery;
26import tools.refinery.store.query.viatra.internal.rete.RefineryReteBackendFactory; 21import tools.refinery.viatra.runtime.api.IQuerySpecification;
22import tools.refinery.viatra.runtime.api.ViatraQueryEngineOptions;
23import tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions;
24import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory;
25import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint;
26import tools.refinery.viatra.runtime.rete.matcher.ReteBackendFactory;
27 27
28import java.util.*; 28import java.util.*;
29import java.util.function.Function; 29import java.util.function.Function;
@@ -41,8 +41,8 @@ public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder<Via
41 41
42 public ViatraModelQueryBuilderImpl() { 42 public ViatraModelQueryBuilderImpl() {
43 engineOptionsBuilder = new ViatraQueryEngineOptions.Builder() 43 engineOptionsBuilder = new ViatraQueryEngineOptions.Builder()
44 .withDefaultBackend(RefineryReteBackendFactory.INSTANCE) 44 .withDefaultBackend(ReteBackendFactory.INSTANCE)
45 .withDefaultCachingBackend(RefineryReteBackendFactory.INSTANCE) 45 .withDefaultCachingBackend(ReteBackendFactory.INSTANCE)
46 .withDefaultSearchBackend(RelationalLocalSearchBackendFactory.INSTANCE); 46 .withDefaultSearchBackend(RelationalLocalSearchBackendFactory.INSTANCE);
47 rewriter = new CompositeRewriter(); 47 rewriter = new CompositeRewriter();
48 rewriter.addFirst(new DuplicateDnfRemover()); 48 rewriter.addFirst(new DuplicateDnfRemover());
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryStoreAdapterImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryStoreAdapterImpl.java
index 25f1cd02..5407ad01 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryStoreAdapterImpl.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryStoreAdapterImpl.java
@@ -5,9 +5,9 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal; 6package tools.refinery.store.query.viatra.internal;
7 7
8import org.eclipse.viatra.query.runtime.api.IQuerySpecification; 8import tools.refinery.viatra.runtime.api.IQuerySpecification;
9import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions; 9import tools.refinery.viatra.runtime.api.ViatraQueryEngineOptions;
10import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 10import tools.refinery.viatra.runtime.matchers.context.IInputKey;
11import tools.refinery.store.model.Model; 11import tools.refinery.store.model.Model;
12import tools.refinery.store.model.ModelStore; 12import tools.refinery.store.model.ModelStore;
13import tools.refinery.store.query.dnf.AnyQuery; 13import tools.refinery.store.query.dnf.AnyQuery;
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 8cb199d2..64d98258 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
@@ -5,16 +5,16 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.context; 6package tools.refinery.store.query.viatra.internal.context;
7 7
8import org.eclipse.viatra.query.runtime.api.scope.IBaseIndex; 8import tools.refinery.viatra.runtime.api.scope.IBaseIndex;
9import org.eclipse.viatra.query.runtime.api.scope.IIndexingErrorListener; 9import tools.refinery.viatra.runtime.api.scope.IIndexingErrorListener;
10import org.eclipse.viatra.query.runtime.api.scope.IInstanceObserver; 10import tools.refinery.viatra.runtime.api.scope.IInstanceObserver;
11import org.eclipse.viatra.query.runtime.api.scope.ViatraBaseIndexChangeListener; 11import tools.refinery.viatra.runtime.api.scope.ViatraBaseIndexChangeListener;
12 12
13import java.lang.reflect.InvocationTargetException; 13import java.lang.reflect.InvocationTargetException;
14import java.util.concurrent.Callable; 14import java.util.concurrent.Callable;
15 15
16/** 16/**
17 * Copied from <code>org.eclipse.viatra.query.runtime.tabular.TabularEngineContext</code> 17 * Copied from <code>tools.refinery.viatra.runtime.tabular.TabularEngineContext</code>
18 */ 18 */
19public class DummyBaseIndexer implements IBaseIndex { 19public class DummyBaseIndexer implements IBaseIndex {
20 DummyBaseIndexer() { 20 DummyBaseIndexer() {
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalEngineContext.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalEngineContext.java
index 7220f8ca..f7d323ff 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalEngineContext.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalEngineContext.java
@@ -5,9 +5,9 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.context; 6package tools.refinery.store.query.viatra.internal.context;
7 7
8import org.eclipse.viatra.query.runtime.api.scope.IBaseIndex; 8import tools.refinery.viatra.runtime.api.scope.IBaseIndex;
9import org.eclipse.viatra.query.runtime.api.scope.IEngineContext; 9import tools.refinery.viatra.runtime.api.scope.IEngineContext;
10import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext; 10import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext;
11import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 11import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
12 12
13public class RelationalEngineContext implements IEngineContext { 13public class RelationalEngineContext implements IEngineContext {
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 211eacb4..77d86a1c 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
@@ -5,10 +5,10 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.context; 6package tools.refinery.store.query.viatra.internal.context;
7 7
8import org.eclipse.viatra.query.runtime.matchers.context.AbstractQueryMetaContext; 8import tools.refinery.viatra.runtime.matchers.context.AbstractQueryMetaContext;
9import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 9import tools.refinery.viatra.runtime.matchers.context.IInputKey;
10import org.eclipse.viatra.query.runtime.matchers.context.InputKeyImplication; 10import tools.refinery.viatra.runtime.matchers.context.InputKeyImplication;
11import org.eclipse.viatra.query.runtime.matchers.context.common.JavaTransitiveInstancesKey; 11import tools.refinery.viatra.runtime.matchers.context.common.JavaTransitiveInstancesKey;
12import tools.refinery.store.query.viatra.internal.pquery.SymbolViewWrapper; 12import tools.refinery.store.query.viatra.internal.pquery.SymbolViewWrapper;
13import tools.refinery.store.query.view.AnySymbolView; 13import tools.refinery.store.query.view.AnySymbolView;
14 14
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 df80a33e..d1fa5239 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
@@ -5,12 +5,12 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.context; 6package tools.refinery.store.query.viatra.internal.context;
7 7
8import org.eclipse.viatra.query.runtime.matchers.context.*; 8import tools.refinery.viatra.runtime.matchers.context.*;
9import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; 9import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
10import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 10import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
11import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; 11import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
12import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 12import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
13import org.eclipse.viatra.query.runtime.matchers.util.Accuracy; 13import tools.refinery.viatra.runtime.matchers.util.Accuracy;
14import tools.refinery.store.model.Model; 14import tools.refinery.store.model.Model;
15import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 15import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
16import tools.refinery.store.query.viatra.internal.pquery.SymbolViewWrapper; 16import tools.refinery.store.query.viatra.internal.pquery.SymbolViewWrapper;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendOperationExecutor.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendOperationExecutor.java
index 37177cbf..fc75198c 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendOperationExecutor.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendOperationExecutor.java
@@ -8,9 +8,9 @@
8 *******************************************************************************/ 8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.localsearch; 9package tools.refinery.store.query.viatra.internal.localsearch;
10 10
11import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame; 11import tools.refinery.viatra.runtime.localsearch.MatchingFrame;
12import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext; 12import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext;
13import org.eclipse.viatra.query.runtime.localsearch.operations.ISearchOperation.ISearchOperationExecutor; 13import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation.ISearchOperationExecutor;
14 14
15import java.util.Iterator; 15import java.util.Iterator;
16 16
@@ -57,7 +57,7 @@ abstract class ExtendOperationExecutor<T> implements ISearchOperationExecutor {
57 } 57 }
58 58
59 /** 59 /**
60 * Fixed version of {@link org.eclipse.viatra.query.runtime.localsearch.operations.ExtendOperationExecutor#execute} 60 * Fixed version of {@link tools.refinery.viatra.runtime.localsearch.operations.ExtendOperationExecutor#execute}
61 * that handles failed unification of variables correctly. 61 * that handles failed unification of variables correctly.
62 * @param frame The matching frame to extend. 62 * @param frame The matching frame to extend.
63 * @param context The search context. 63 * @param context The search context.
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendPositivePatternCall.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendPositivePatternCall.java
index 9d48c785..b8b6b159 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendPositivePatternCall.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/ExtendPositivePatternCall.java
@@ -8,15 +8,15 @@
8 *******************************************************************************/ 8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.localsearch; 9package tools.refinery.store.query.viatra.internal.localsearch;
10 10
11import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame; 11import tools.refinery.viatra.runtime.localsearch.MatchingFrame;
12import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext; 12import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext;
13import org.eclipse.viatra.query.runtime.localsearch.operations.IPatternMatcherOperation; 13import tools.refinery.viatra.runtime.localsearch.operations.IPatternMatcherOperation;
14import org.eclipse.viatra.query.runtime.localsearch.operations.ISearchOperation; 14import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation;
15import org.eclipse.viatra.query.runtime.localsearch.operations.util.CallInformation; 15import tools.refinery.viatra.runtime.localsearch.operations.util.CallInformation;
16import org.eclipse.viatra.query.runtime.matchers.backend.IQueryResultProvider; 16import tools.refinery.viatra.runtime.matchers.backend.IQueryResultProvider;
17import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 17import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
18import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; 18import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
19import org.eclipse.viatra.query.runtime.matchers.tuple.VolatileModifiableMaskedTuple; 19import tools.refinery.viatra.runtime.matchers.tuple.VolatileModifiableMaskedTuple;
20 20
21import java.util.Iterator; 21import java.util.Iterator;
22import java.util.List; 22import java.util.List;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/FlatCostFunction.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/FlatCostFunction.java
index cc906f22..ce2a75bd 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/FlatCostFunction.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/FlatCostFunction.java
@@ -5,12 +5,12 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.localsearch; 6package tools.refinery.store.query.viatra.internal.localsearch;
7 7
8import org.eclipse.viatra.query.runtime.localsearch.planner.cost.IConstraintEvaluationContext; 8import tools.refinery.viatra.runtime.localsearch.planner.cost.IConstraintEvaluationContext;
9import org.eclipse.viatra.query.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction; 9import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction;
10import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 10import tools.refinery.viatra.runtime.matchers.context.IInputKey;
11import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; 11import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint;
12import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; 12import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
13import org.eclipse.viatra.query.runtime.matchers.util.Accuracy; 13import tools.refinery.viatra.runtime.matchers.util.Accuracy;
14 14
15import java.util.Optional; 15import java.util.Optional;
16 16
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/GenericTypeExtend.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/GenericTypeExtend.java
index 96ac4a72..0ee69b88 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/GenericTypeExtend.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/GenericTypeExtend.java
@@ -8,15 +8,15 @@
8 *******************************************************************************/ 8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.localsearch; 9package tools.refinery.store.query.viatra.internal.localsearch;
10 10
11import org.eclipse.viatra.query.runtime.localsearch.MatchingFrame; 11import tools.refinery.viatra.runtime.localsearch.MatchingFrame;
12import org.eclipse.viatra.query.runtime.localsearch.matcher.ISearchContext; 12import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext;
13import org.eclipse.viatra.query.runtime.localsearch.operations.IIteratingSearchOperation; 13import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation;
14import org.eclipse.viatra.query.runtime.localsearch.operations.ISearchOperation; 14import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation;
15import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 15import tools.refinery.viatra.runtime.matchers.context.IInputKey;
16import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 16import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
17import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; 17import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
18import org.eclipse.viatra.query.runtime.matchers.tuple.VolatileMaskedTuple; 18import tools.refinery.viatra.runtime.matchers.tuple.VolatileMaskedTuple;
19import org.eclipse.viatra.query.runtime.matchers.util.Preconditions; 19import tools.refinery.viatra.runtime.matchers.util.Preconditions;
20 20
21import java.util.*; 21import java.util.*;
22import java.util.function.Function; 22import java.util.function.Function;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchBackendFactory.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchBackendFactory.java
index 0c77f587..7d5401c6 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchBackendFactory.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchBackendFactory.java
@@ -5,17 +5,17 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.localsearch; 6package tools.refinery.store.query.viatra.internal.localsearch;
7 7
8import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.AbstractLocalSearchResultProvider; 8import tools.refinery.viatra.runtime.localsearch.matcher.integration.AbstractLocalSearchResultProvider;
9import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchBackend; 9import tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchBackend;
10import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints; 10import tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHints;
11import org.eclipse.viatra.query.runtime.localsearch.plan.IPlanProvider; 11import tools.refinery.viatra.runtime.localsearch.plan.IPlanProvider;
12import org.eclipse.viatra.query.runtime.localsearch.plan.SimplePlanProvider; 12import tools.refinery.viatra.runtime.localsearch.plan.SimplePlanProvider;
13import org.eclipse.viatra.query.runtime.matchers.backend.IMatcherCapability; 13import tools.refinery.viatra.runtime.matchers.backend.IMatcherCapability;
14import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend; 14import tools.refinery.viatra.runtime.matchers.backend.IQueryBackend;
15import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory; 15import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory;
16import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; 16import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint;
17import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext; 17import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext;
18import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; 18import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery;
19 19
20public class RelationalLocalSearchBackendFactory implements IQueryBackendFactory { 20public class RelationalLocalSearchBackendFactory implements IQueryBackendFactory {
21 public static final RelationalLocalSearchBackendFactory INSTANCE = new RelationalLocalSearchBackendFactory(); 21 public static final RelationalLocalSearchBackendFactory INSTANCE = new RelationalLocalSearchBackendFactory();
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchResultProvider.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchResultProvider.java
index da37be14..37d06864 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchResultProvider.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalLocalSearchResultProvider.java
@@ -5,14 +5,14 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.localsearch; 6package tools.refinery.store.query.viatra.internal.localsearch;
7 7
8import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.AbstractLocalSearchResultProvider; 8import tools.refinery.viatra.runtime.localsearch.matcher.integration.AbstractLocalSearchResultProvider;
9import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchBackend; 9import tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchBackend;
10import org.eclipse.viatra.query.runtime.localsearch.matcher.integration.LocalSearchHints; 10import tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHints;
11import org.eclipse.viatra.query.runtime.localsearch.plan.IPlanProvider; 11import tools.refinery.viatra.runtime.localsearch.plan.IPlanProvider;
12import org.eclipse.viatra.query.runtime.localsearch.planner.compiler.IOperationCompiler; 12import tools.refinery.viatra.runtime.localsearch.planner.compiler.IOperationCompiler;
13import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; 13import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint;
14import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext; 14import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext;
15import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; 15import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery;
16 16
17class RelationalLocalSearchResultProvider extends AbstractLocalSearchResultProvider { 17class RelationalLocalSearchResultProvider extends AbstractLocalSearchResultProvider {
18 public RelationalLocalSearchResultProvider(LocalSearchBackend backend, IQueryBackendContext context, PQuery query, 18 public RelationalLocalSearchResultProvider(LocalSearchBackend backend, IQueryBackendContext context, PQuery query,
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java
index f76ef486..37f264ae 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java
@@ -5,16 +5,16 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.localsearch; 6package tools.refinery.store.query.viatra.internal.localsearch;
7 7
8import org.eclipse.viatra.query.runtime.localsearch.operations.generic.GenericTypeExtendSingleValue; 8import tools.refinery.viatra.runtime.localsearch.operations.generic.GenericTypeExtendSingleValue;
9import org.eclipse.viatra.query.runtime.localsearch.operations.util.CallInformation; 9import tools.refinery.viatra.runtime.localsearch.operations.util.CallInformation;
10import org.eclipse.viatra.query.runtime.localsearch.planner.compiler.GenericOperationCompiler; 10import tools.refinery.viatra.runtime.localsearch.planner.compiler.GenericOperationCompiler;
11import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 11import tools.refinery.viatra.runtime.matchers.context.IInputKey;
12import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext; 12import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext;
13import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; 13import tools.refinery.viatra.runtime.matchers.psystem.PVariable;
14import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; 14import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
15import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; 15import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint;
16import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 16import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
17import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; 17import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
18 18
19import java.util.*; 19import java.util.*;
20 20
@@ -52,7 +52,7 @@ public class RelationalOperationCompiler extends GenericOperationCompiler {
52 unboundVariables.iterator().next())); 52 unboundVariables.iterator().next()));
53 } else { 53 } else {
54 // Use a fixed version of 54 // Use a fixed version of
55 // {@code org.eclipse.viatra.query.runtime.localsearch.operations.generic.GenericTypeExtend} that handles 55 // {@code tools.refinery.viatra.runtime.localsearch.operations.generic.GenericTypeExtend} that handles
56 // failed unification of variables correctly. 56 // failed unification of variables correctly.
57 operations.add(new GenericTypeExtend(inputKey, positions, callMask, indexerMask, unboundVariables)); 57 operations.add(new GenericTypeExtend(inputKey, positions, callMask, indexerMask, unboundVariables));
58 } 58 }
@@ -62,7 +62,7 @@ public class RelationalOperationCompiler extends GenericOperationCompiler {
62 protected void createExtend(PositivePatternCall pCall, Map<PVariable, Integer> variableMapping) { 62 protected void createExtend(PositivePatternCall pCall, Map<PVariable, Integer> variableMapping) {
63 CallInformation information = CallInformation.create(pCall, variableMapping, variableBindings.get(pCall)); 63 CallInformation information = CallInformation.create(pCall, variableMapping, variableBindings.get(pCall));
64 // Use a fixed version of 64 // Use a fixed version of
65 // {@code org.eclipse.viatra.query.runtime.localsearch.operations.extend.ExtendPositivePatternCall} that handles 65 // {@code tools.refinery.viatra.runtime.localsearch.operations.extend.ExtendPositivePatternCall} that handles
66 // failed unification of variables correctly. 66 // failed unification of variables correctly.
67 operations.add(new ExtendPositivePatternCall(information)); 67 operations.add(new ExtendPositivePatternCall(information));
68 dependencies.add(information.getCallWithAdornment()); 68 dependencies.add(information.getCallWithAdornment());
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/AbstractViatraMatcher.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/AbstractViatraMatcher.java
index 99b0a3d8..c4a5a236 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/AbstractViatraMatcher.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/AbstractViatraMatcher.java
@@ -5,8 +5,8 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.matchers.backend.IQueryResultProvider; 8import tools.refinery.viatra.runtime.matchers.backend.IQueryResultProvider;
9import org.eclipse.viatra.query.runtime.matchers.backend.IUpdateable; 9import tools.refinery.viatra.runtime.matchers.backend.IUpdateable;
10import tools.refinery.store.query.dnf.Query; 10import tools.refinery.store.query.dnf.Query;
11import tools.refinery.store.query.resultset.AbstractResultSet; 11import tools.refinery.store.query.resultset.AbstractResultSet;
12import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 12import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalCursor.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalCursor.java
index 47efb2aa..44038669 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalCursor.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalCursor.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.rete.index.IterableIndexer; 8import tools.refinery.viatra.runtime.rete.index.IterableIndexer;
9import tools.refinery.store.map.Cursor; 9import tools.refinery.store.map.Cursor;
10import tools.refinery.store.tuple.Tuple; 10import tools.refinery.store.tuple.Tuple;
11 11
@@ -13,7 +13,7 @@ import java.util.Iterator;
13 13
14class FunctionalCursor<T> implements Cursor<Tuple, T> { 14class FunctionalCursor<T> implements Cursor<Tuple, T> {
15 private final IterableIndexer indexer; 15 private final IterableIndexer indexer;
16 private final Iterator<org.eclipse.viatra.query.runtime.matchers.tuple.Tuple> iterator; 16 private final Iterator<tools.refinery.viatra.runtime.matchers.tuple.Tuple> iterator;
17 private boolean terminated; 17 private boolean terminated;
18 private Tuple key; 18 private Tuple key;
19 private T value; 19 private T value;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalViatraMatcher.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalViatraMatcher.java
index db4740cd..fb9e4df6 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalViatraMatcher.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/FunctionalViatraMatcher.java
@@ -5,10 +5,10 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; 8import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
9import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 9import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
10import org.eclipse.viatra.query.runtime.rete.index.IterableIndexer; 10import tools.refinery.viatra.runtime.rete.index.IterableIndexer;
11import org.eclipse.viatra.query.runtime.rete.matcher.RetePatternMatcher; 11import tools.refinery.viatra.runtime.rete.matcher.RetePatternMatcher;
12import tools.refinery.store.map.Cursor; 12import tools.refinery.store.map.Cursor;
13import tools.refinery.store.query.dnf.FunctionalQuery; 13import tools.refinery.store.query.dnf.FunctionalQuery;
14import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 14import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
@@ -17,9 +17,9 @@ import tools.refinery.store.tuple.Tuple;
17/** 17/**
18 * Directly access the tuples inside a VIATRA pattern matcher.<p> 18 * Directly access the tuples inside a VIATRA pattern matcher.<p>
19 * This class neglects calling 19 * This class neglects calling
20 * {@link org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext#wrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)} 20 * {@link tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext#wrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)}
21 * and 21 * and
22 * {@link org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext#unwrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)}, 22 * {@link tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext#unwrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)},
23 * because {@link tools.refinery.store.query.viatra.internal.context.RelationalRuntimeContext} provides a trivial 23 * because {@link tools.refinery.store.query.viatra.internal.context.RelationalRuntimeContext} provides a trivial
24 * implementation for these methods. 24 * implementation for these methods.
25 * Using this class with any other runtime context may lead to undefined behavior. 25 * Using this class with any other runtime context may lead to undefined behavior.
@@ -37,7 +37,7 @@ public class FunctionalViatraMatcher<T> extends AbstractViatraMatcher<T> {
37 emptyMask = TupleMask.empty(arityWithOutput); 37 emptyMask = TupleMask.empty(arityWithOutput);
38 omitOutputMask = TupleMask.omit(arity, arityWithOutput); 38 omitOutputMask = TupleMask.omit(arity, arityWithOutput);
39 if (backend instanceof RetePatternMatcher reteBackend) { 39 if (backend instanceof RetePatternMatcher reteBackend) {
40 var maybeIterableOmitOutputIndexer = IndexerUtils.getIndexer(reteBackend, omitOutputMask); 40 var maybeIterableOmitOutputIndexer = reteBackend.getInternalIndexer(omitOutputMask);
41 if (maybeIterableOmitOutputIndexer instanceof IterableIndexer iterableOmitOutputIndexer) { 41 if (maybeIterableOmitOutputIndexer instanceof IterableIndexer iterableOmitOutputIndexer) {
42 omitOutputIndexer = iterableOmitOutputIndexer; 42 omitOutputIndexer = iterableOmitOutputIndexer;
43 } else { 43 } else {
@@ -76,7 +76,7 @@ public class FunctionalViatraMatcher<T> extends AbstractViatraMatcher<T> {
76 } 76 }
77 77
78 @Override 78 @Override
79 public void update(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple updateElement, boolean isInsertion) { 79 public void update(tools.refinery.viatra.runtime.matchers.tuple.Tuple updateElement, boolean isInsertion) {
80 var key = MatcherUtils.keyToRefineryTuple(updateElement); 80 var key = MatcherUtils.keyToRefineryTuple(updateElement);
81 var value = MatcherUtils.<T>getValue(updateElement); 81 var value = MatcherUtils.<T>getValue(updateElement);
82 if (isInsertion) { 82 if (isInsertion) {
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/IndexerUtils.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/IndexerUtils.java
deleted file mode 100644
index 15f00b2d..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/IndexerUtils.java
+++ /dev/null
@@ -1,53 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.matcher;
7
8import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask;
9import org.eclipse.viatra.query.runtime.rete.index.Indexer;
10import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine;
11import org.eclipse.viatra.query.runtime.rete.matcher.RetePatternMatcher;
12import org.eclipse.viatra.query.runtime.rete.traceability.RecipeTraceInfo;
13
14import java.lang.invoke.MethodHandle;
15import java.lang.invoke.MethodHandles;
16import java.lang.invoke.MethodType;
17
18final class IndexerUtils {
19 private static final MethodHandle GET_ENGINE_HANDLE;
20 private static final MethodHandle GET_PRODUCTION_NODE_TRACE_HANDLE;
21 private static final MethodHandle ACCESS_PROJECTION_HANDLE;
22
23 static {
24 try {
25 var lookup = MethodHandles.privateLookupIn(RetePatternMatcher.class, MethodHandles.lookup());
26 GET_ENGINE_HANDLE = lookup.findGetter(RetePatternMatcher.class, "engine", ReteEngine.class);
27 GET_PRODUCTION_NODE_TRACE_HANDLE = lookup.findGetter(RetePatternMatcher.class, "productionNodeTrace",
28 RecipeTraceInfo.class);
29 ACCESS_PROJECTION_HANDLE = lookup.findVirtual(ReteEngine.class, "accessProjection",
30 MethodType.methodType(Indexer.class, RecipeTraceInfo.class, TupleMask.class));
31 } catch (IllegalAccessException | NoSuchFieldException | NoSuchMethodException e) {
32 throw new IllegalStateException("Cannot access private members of %s"
33 .formatted(RetePatternMatcher.class.getPackageName()), e);
34 }
35 }
36
37 private IndexerUtils() {
38 throw new IllegalStateException("This is a static utility class and should not be instantiated directly");
39 }
40
41 public static Indexer getIndexer(RetePatternMatcher backend, TupleMask mask) {
42 try {
43 var engine = (ReteEngine) GET_ENGINE_HANDLE.invokeExact(backend);
44 var trace = (RecipeTraceInfo) GET_PRODUCTION_NODE_TRACE_HANDLE.invokeExact(backend);
45 return (Indexer) ACCESS_PROJECTION_HANDLE.invokeExact(engine, trace, mask);
46 } catch (Error e) {
47 // Fatal JVM errors should not be wrapped.
48 throw e;
49 } catch (Throwable e) {
50 throw new IllegalStateException("Cannot access matcher for mask " + mask, e);
51 }
52 }
53}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/MatcherUtils.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/MatcherUtils.java
index 6e24812a..6cda23cd 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/MatcherUtils.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/MatcherUtils.java
@@ -5,8 +5,8 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; 8import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
9import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 9import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
10import org.jetbrains.annotations.Nullable; 10import org.jetbrains.annotations.Nullable;
11import tools.refinery.store.tuple.*; 11import tools.refinery.store.tuple.*;
12 12
@@ -17,7 +17,7 @@ final class MatcherUtils {
17 throw new IllegalStateException("This is a static utility class and should not be instantiated directly"); 17 throw new IllegalStateException("This is a static utility class and should not be instantiated directly");
18 } 18 }
19 19
20 public static org.eclipse.viatra.query.runtime.matchers.tuple.Tuple toViatraTuple(Tuple refineryTuple) { 20 public static tools.refinery.viatra.runtime.matchers.tuple.Tuple toViatraTuple(Tuple refineryTuple) {
21 if (refineryTuple instanceof Tuple0) { 21 if (refineryTuple instanceof Tuple0) {
22 return Tuples.staticArityFlatTupleOf(); 22 return Tuples.staticArityFlatTupleOf();
23 } else if (refineryTuple instanceof Tuple1) { 23 } else if (refineryTuple instanceof Tuple1) {
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RawPatternMatcher.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RawPatternMatcher.java
index 5b82c4b7..c0be70ba 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RawPatternMatcher.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RawPatternMatcher.java
@@ -5,9 +5,9 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.api.GenericPatternMatcher; 8import tools.refinery.viatra.runtime.api.GenericPatternMatcher;
9import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; 9import tools.refinery.viatra.runtime.api.GenericQuerySpecification;
10import org.eclipse.viatra.query.runtime.matchers.backend.IQueryResultProvider; 10import tools.refinery.viatra.runtime.matchers.backend.IQueryResultProvider;
11 11
12public class RawPatternMatcher extends GenericPatternMatcher { 12public class RawPatternMatcher extends GenericPatternMatcher {
13 public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) { 13 public RawPatternMatcher(GenericQuerySpecification<? extends GenericPatternMatcher> specification) {
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalCursor.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalCursor.java
index 1dc8f5db..53475218 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalCursor.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalCursor.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; 8import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
9import tools.refinery.store.map.Cursor; 9import tools.refinery.store.map.Cursor;
10import tools.refinery.store.tuple.Tuple; 10import tools.refinery.store.tuple.Tuple;
11 11
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalViatraMatcher.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalViatraMatcher.java
index ac95dcc0..da75e864 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalViatraMatcher.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/RelationalViatraMatcher.java
@@ -5,10 +5,10 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask; 8import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
9import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 9import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
10import org.eclipse.viatra.query.runtime.rete.index.Indexer; 10import tools.refinery.viatra.runtime.rete.index.Indexer;
11import org.eclipse.viatra.query.runtime.rete.matcher.RetePatternMatcher; 11import tools.refinery.viatra.runtime.rete.matcher.RetePatternMatcher;
12import tools.refinery.store.map.Cursor; 12import tools.refinery.store.map.Cursor;
13import tools.refinery.store.map.Cursors; 13import tools.refinery.store.map.Cursors;
14import tools.refinery.store.query.dnf.RelationalQuery; 14import tools.refinery.store.query.dnf.RelationalQuery;
@@ -18,9 +18,9 @@ import tools.refinery.store.tuple.Tuple;
18/** 18/**
19 * Directly access the tuples inside a VIATRA pattern matcher.<p> 19 * Directly access the tuples inside a VIATRA pattern matcher.<p>
20 * This class neglects calling 20 * This class neglects calling
21 * {@link org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext#wrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)} 21 * {@link tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext#wrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)}
22 * and 22 * and
23 * {@link org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext#unwrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)}, 23 * {@link tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext#unwrapTuple(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple)},
24 * because {@link tools.refinery.store.query.viatra.internal.context.RelationalRuntimeContext} provides a trivial 24 * because {@link tools.refinery.store.query.viatra.internal.context.RelationalRuntimeContext} provides a trivial
25 * implementation for these methods. 25 * implementation for these methods.
26 * Using this class with any other runtime context may lead to undefined behavior. 26 * Using this class with any other runtime context may lead to undefined behavior.
@@ -37,7 +37,7 @@ public class RelationalViatraMatcher extends AbstractViatraMatcher<Boolean> {
37 emptyMask = TupleMask.empty(arity); 37 emptyMask = TupleMask.empty(arity);
38 identityMask = TupleMask.identity(arity); 38 identityMask = TupleMask.identity(arity);
39 if (backend instanceof RetePatternMatcher reteBackend) { 39 if (backend instanceof RetePatternMatcher reteBackend) {
40 emptyMaskIndexer = IndexerUtils.getIndexer(reteBackend, emptyMask); 40 emptyMaskIndexer = reteBackend.getInternalIndexer(emptyMask);
41 } else { 41 } else {
42 emptyMaskIndexer = null; 42 emptyMaskIndexer = null;
43 } 43 }
@@ -73,7 +73,7 @@ public class RelationalViatraMatcher extends AbstractViatraMatcher<Boolean> {
73 } 73 }
74 74
75 @Override 75 @Override
76 public void update(org.eclipse.viatra.query.runtime.matchers.tuple.Tuple updateElement, boolean isInsertion) { 76 public void update(tools.refinery.viatra.runtime.matchers.tuple.Tuple updateElement, boolean isInsertion) {
77 var key = MatcherUtils.toRefineryTuple(updateElement); 77 var key = MatcherUtils.toRefineryTuple(updateElement);
78 notifyChange(key, !isInsertion, isInsertion); 78 notifyChange(key, !isInsertion, isInsertion);
79 } 79 }
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/UnsafeFunctionalCursor.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/UnsafeFunctionalCursor.java
index b0b507fe..093ade96 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/UnsafeFunctionalCursor.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/matcher/UnsafeFunctionalCursor.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.matcher; 6package tools.refinery.store.query.viatra.internal.matcher;
7 7
8import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; 8import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
9import tools.refinery.store.map.Cursor; 9import tools.refinery.store.map.Cursor;
10import tools.refinery.store.tuple.Tuple; 10import tools.refinery.store.tuple.Tuple;
11 11
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CheckEvaluator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CheckEvaluator.java
index 5dde41be..ada154d4 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CheckEvaluator.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CheckEvaluator.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; 8import tools.refinery.viatra.runtime.matchers.psystem.IValueProvider;
9import tools.refinery.store.query.term.Term; 9import tools.refinery.store.query.term.Term;
10 10
11class CheckEvaluator extends TermEvaluator<Boolean> { 11class CheckEvaluator extends TermEvaluator<Boolean> {
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 af3bf32e..492bd054 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
@@ -5,24 +5,6 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
9import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
10import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
11import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
12import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
13import org.eclipse.viatra.query.runtime.matchers.psystem.aggregations.BoundAggregator;
14import org.eclipse.viatra.query.runtime.matchers.psystem.aggregations.IMultisetAggregationOperator;
15import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation;
16import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.*;
17import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.BinaryTransitiveClosure;
18import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.ConstantValue;
19import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
20import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
21import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
22import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
23import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
24import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
25import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
26import tools.refinery.store.query.Constraint; 8import tools.refinery.store.query.Constraint;
27import tools.refinery.store.query.dnf.Dnf; 9import tools.refinery.store.query.dnf.Dnf;
28import tools.refinery.store.query.dnf.DnfClause; 10import tools.refinery.store.query.dnf.DnfClause;
@@ -34,6 +16,22 @@ import tools.refinery.store.query.term.StatelessAggregator;
34import tools.refinery.store.query.term.Variable; 16import tools.refinery.store.query.term.Variable;
35import tools.refinery.store.query.view.AnySymbolView; 17import tools.refinery.store.query.view.AnySymbolView;
36import tools.refinery.store.util.CycleDetectingMapper; 18import tools.refinery.store.util.CycleDetectingMapper;
19import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory;
20import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint;
21import tools.refinery.viatra.runtime.matchers.context.IInputKey;
22import tools.refinery.viatra.runtime.matchers.psystem.PBody;
23import tools.refinery.viatra.runtime.matchers.psystem.PVariable;
24import tools.refinery.viatra.runtime.matchers.psystem.aggregations.BoundAggregator;
25import tools.refinery.viatra.runtime.matchers.psystem.aggregations.IMultisetAggregationOperator;
26import tools.refinery.viatra.runtime.matchers.psystem.annotations.PAnnotation;
27import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.*;
28import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.*;
29import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.Connectivity;
30import tools.refinery.viatra.runtime.matchers.psystem.queries.PParameter;
31import tools.refinery.viatra.runtime.matchers.psystem.queries.PParameterDirection;
32import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery;
33import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
34import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
37 35
38import java.util.ArrayList; 36import java.util.ArrayList;
39import java.util.HashMap; 37import java.util.HashMap;
@@ -42,7 +40,6 @@ import java.util.Map;
42import java.util.function.Function; 40import java.util.function.Function;
43 41
44public class Dnf2PQuery { 42public class Dnf2PQuery {
45 private static final Object P_CONSTRAINT_LOCK = new Object();
46 private final CycleDetectingMapper<Dnf, RawPQuery> mapper = new CycleDetectingMapper<>(Dnf::name, 43 private final CycleDetectingMapper<Dnf, RawPQuery> mapper = new CycleDetectingMapper<>(Dnf::name,
47 this::doTranslate); 44 this::doTranslate);
48 private final QueryWrapperFactory wrapperFactory = new QueryWrapperFactory(this); 45 private final QueryWrapperFactory wrapperFactory = new QueryWrapperFactory(this);
@@ -91,22 +88,17 @@ public class Dnf2PQuery {
91 pQuery.addAnnotation(functionalDependencyAnnotation); 88 pQuery.addAnnotation(functionalDependencyAnnotation);
92 } 89 }
93 90
94 // The constructor of {@link org.eclipse.viatra.query.runtime.matchers.psystem.BasePConstraint} mutates 91 for (DnfClause clause : dnfQuery.getClauses()) {
95 // global static state (<code>nextID</code>) without locking. Therefore, we need to synchronize before creating 92 PBody body = new PBody(pQuery);
96 // any query literals to avoid a data race. 93 List<ExportedParameter> parameterExports = new ArrayList<>();
97 synchronized (P_CONSTRAINT_LOCK) { 94 for (var parameter : dnfQuery.getSymbolicParameters()) {
98 for (DnfClause clause : dnfQuery.getClauses()) { 95 PVariable pVar = body.getOrCreateVariableByName(parameter.getVariable().getUniqueName());
99 PBody body = new PBody(pQuery); 96 parameterExports.add(new ExportedParameter(body, pVar, parameters.get(parameter)));
100 List<ExportedParameter> parameterExports = new ArrayList<>(); 97 }
101 for (var parameter : dnfQuery.getSymbolicParameters()) { 98 body.setSymbolicParameters(parameterExports);
102 PVariable pVar = body.getOrCreateVariableByName(parameter.getVariable().getUniqueName()); 99 pQuery.addBody(body);
103 parameterExports.add(new ExportedParameter(body, pVar, parameters.get(parameter))); 100 for (Literal literal : clause.literals()) {
104 } 101 translateLiteral(literal, body);
105 body.setSymbolicParameters(parameterExports);
106 pQuery.addBody(body);
107 for (Literal literal : clause.literals()) {
108 translateLiteral(literal, body);
109 }
110 } 102 }
111 } 103 }
112 104
@@ -252,6 +244,10 @@ public class Dnf2PQuery {
252 private void translateRepresentativeElectionLiteral(RepresentativeElectionLiteral literal, PBody body) { 244 private void translateRepresentativeElectionLiteral(RepresentativeElectionLiteral literal, PBody body) {
253 var substitution = translateSubstitution(literal.getArguments(), body); 245 var substitution = translateSubstitution(literal.getArguments(), body);
254 var pattern = wrapConstraintWithIdentityArguments(literal.getTarget()); 246 var pattern = wrapConstraintWithIdentityArguments(literal.getTarget());
255 new RepresentativeElectionConstraint(body, substitution, pattern, literal.getConnectivity()); 247 var connectivity = switch (literal.getConnectivity()) {
248 case WEAK -> Connectivity.WEAK;
249 case STRONG -> Connectivity.STRONG;
250 };
251 new RepresentativeElectionConstraint(body, substitution, pattern, connectivity);
256 } 252 }
257} 253}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/QueryWrapperFactory.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/QueryWrapperFactory.java
index 502813e1..d21131e5 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/QueryWrapperFactory.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/QueryWrapperFactory.java
@@ -5,17 +5,17 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 8import tools.refinery.viatra.runtime.matchers.context.IInputKey;
9import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; 9import tools.refinery.viatra.runtime.matchers.psystem.PBody;
10import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; 10import tools.refinery.viatra.runtime.matchers.psystem.PVariable;
11import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; 11import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.ExportedParameter;
12import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; 12import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
13import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; 13import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint;
14import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; 14import tools.refinery.viatra.runtime.matchers.psystem.queries.PParameter;
15import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery; 15import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery;
16import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; 16import tools.refinery.viatra.runtime.matchers.psystem.queries.PVisibility;
17import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 17import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
18import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 18import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
19import tools.refinery.store.query.Constraint; 19import tools.refinery.store.query.Constraint;
20import tools.refinery.store.query.dnf.Dnf; 20import tools.refinery.store.query.dnf.Dnf;
21import tools.refinery.store.query.dnf.DnfUtils; 21import tools.refinery.store.query.dnf.DnfUtils;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RawPQuery.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RawPQuery.java
index 255738c5..06644bf2 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RawPQuery.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RawPQuery.java
@@ -5,14 +5,14 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.api.GenericQuerySpecification; 8import tools.refinery.viatra.runtime.api.GenericQuerySpecification;
9import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; 9import tools.refinery.viatra.runtime.api.ViatraQueryEngine;
10import org.eclipse.viatra.query.runtime.api.scope.QueryScope; 10import tools.refinery.viatra.runtime.api.scope.QueryScope;
11import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; 11import tools.refinery.viatra.runtime.matchers.psystem.PBody;
12import org.eclipse.viatra.query.runtime.matchers.psystem.annotations.PAnnotation; 12import tools.refinery.viatra.runtime.matchers.psystem.annotations.PAnnotation;
13import org.eclipse.viatra.query.runtime.matchers.psystem.queries.BasePQuery; 13import tools.refinery.viatra.runtime.matchers.psystem.queries.BasePQuery;
14import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; 14import tools.refinery.viatra.runtime.matchers.psystem.queries.PParameter;
15import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; 15import tools.refinery.viatra.runtime.matchers.psystem.queries.PVisibility;
16import tools.refinery.store.query.viatra.internal.RelationalScope; 16import tools.refinery.store.query.viatra.internal.RelationalScope;
17import tools.refinery.store.query.viatra.internal.matcher.RawPatternMatcher; 17import tools.refinery.store.query.viatra.internal.matcher.RawPatternMatcher;
18 18
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RepresentativeElectionConstraint.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RepresentativeElectionConstraint.java
deleted file mode 100644
index e146213e..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/RepresentativeElectionConstraint.java
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.pquery;
7
8import org.eclipse.viatra.query.runtime.matchers.context.IQueryMetaContext;
9import org.eclipse.viatra.query.runtime.matchers.psystem.*;
10import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
11import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
12import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
13import tools.refinery.store.query.literal.Connectivity;
14
15import java.util.Set;
16
17public class RepresentativeElectionConstraint extends KeyedEnumerablePConstraint<PQuery>
18 implements IQueryReference, ITypeInfoProviderConstraint {
19 private final Connectivity connectivity;
20
21 public RepresentativeElectionConstraint(PBody pBody, Tuple variablesTuple, PQuery supplierKey,
22 Connectivity connectivity) {
23 super(pBody, variablesTuple, supplierKey);
24 this.connectivity = connectivity;
25 }
26
27 public Connectivity getConnectivity() {
28 return connectivity;
29 }
30
31 @Override
32 public PQuery getReferredQuery() {
33 return supplierKey;
34 }
35
36 @Override
37 public Set<TypeJudgement> getImpliedJudgements(IQueryMetaContext context) {
38 return PositivePatternCall.getTypesImpliedByCall(supplierKey, variablesTuple);
39 }
40
41 @Override
42 protected String keyToString() {
43 return supplierKey.getFullyQualifiedName() + "#representative";
44 }
45}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatefulMultisetAggregator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatefulMultisetAggregator.java
index 461416f7..ba99cf9a 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatefulMultisetAggregator.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatefulMultisetAggregator.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.psystem.aggregations.IMultisetAggregationOperator; 8import tools.refinery.viatra.runtime.matchers.psystem.aggregations.IMultisetAggregationOperator;
9import tools.refinery.store.query.term.StatefulAggregate; 9import tools.refinery.store.query.term.StatefulAggregate;
10import tools.refinery.store.query.term.StatefulAggregator; 10import tools.refinery.store.query.term.StatefulAggregator;
11 11
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatelessMultisetAggregator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatelessMultisetAggregator.java
index 49175d75..bf2c2f4f 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatelessMultisetAggregator.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/StatelessMultisetAggregator.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.psystem.aggregations.IMultisetAggregationOperator; 8import tools.refinery.viatra.runtime.matchers.psystem.aggregations.IMultisetAggregationOperator;
9import tools.refinery.store.query.term.StatelessAggregator; 9import tools.refinery.store.query.term.StatelessAggregator;
10 10
11import java.util.stream.Stream; 11import java.util.stream.Stream;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/SymbolViewWrapper.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/SymbolViewWrapper.java
index a777613e..a774404e 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/SymbolViewWrapper.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/SymbolViewWrapper.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.context.common.BaseInputKeyWrapper; 8import tools.refinery.viatra.runtime.matchers.context.common.BaseInputKeyWrapper;
9import tools.refinery.store.query.view.AnySymbolView; 9import tools.refinery.store.query.view.AnySymbolView;
10 10
11public class SymbolViewWrapper extends BaseInputKeyWrapper<AnySymbolView> { 11public class SymbolViewWrapper extends BaseInputKeyWrapper<AnySymbolView> {
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/TermEvaluator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/TermEvaluator.java
index 1187f57a..5df861a6 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/TermEvaluator.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/TermEvaluator.java
@@ -5,8 +5,8 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; 8import tools.refinery.viatra.runtime.matchers.psystem.IExpressionEvaluator;
9import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; 9import tools.refinery.viatra.runtime.matchers.psystem.IValueProvider;
10import tools.refinery.store.query.term.Term; 10import tools.refinery.store.query.term.Term;
11import tools.refinery.store.query.term.Variable; 11import tools.refinery.store.query.term.Variable;
12 12
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/ValueProviderBasedValuation.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/ValueProviderBasedValuation.java
index 62cb8b3a..b9ae8ab2 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/ValueProviderBasedValuation.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/ValueProviderBasedValuation.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.pquery; 6package tools.refinery.store.query.viatra.internal.pquery;
7 7
8import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; 8import tools.refinery.viatra.runtime.matchers.psystem.IValueProvider;
9import tools.refinery.store.query.term.DataVariable; 9import tools.refinery.store.query.term.DataVariable;
10import tools.refinery.store.query.valuation.Valuation; 10import tools.refinery.store.query.valuation.Valuation;
11 11
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyCopier.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyCopier.java
deleted file mode 100644
index a833a37b..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyCopier.java
+++ /dev/null
@@ -1,35 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.pquery.rewriter;
7
8import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
9import org.eclipse.viatra.query.runtime.matchers.psystem.PConstraint;
10import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.IRewriterTraceCollector;
11import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyCopier;
12import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
13import tools.refinery.store.query.viatra.internal.pquery.RepresentativeElectionConstraint;
14
15public class RefineryPBodyCopier extends PBodyCopier {
16 public RefineryPBodyCopier(PBody body, IRewriterTraceCollector traceCollector) {
17 super(body, traceCollector);
18 }
19
20 @Override
21 protected void copyConstraint(PConstraint constraint) {
22 if (constraint instanceof RepresentativeElectionConstraint representativeElectionConstraint) {
23 copyRepresentativeElectionConstraint(representativeElectionConstraint);
24 } else {
25 super.copyConstraint(constraint);
26 }
27 }
28
29 private void copyRepresentativeElectionConstraint(RepresentativeElectionConstraint constraint) {
30 var mappedVariables = extractMappedVariables(constraint);
31 var variablesTuple = Tuples.flatTupleOf((Object[]) mappedVariables);
32 addTrace(constraint, new RepresentativeElectionConstraint(body, variablesTuple, constraint.getReferredQuery(),
33 constraint.getConnectivity()));
34 }
35}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyNormalizer.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyNormalizer.java
deleted file mode 100644
index ed85a843..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefineryPBodyNormalizer.java
+++ /dev/null
@@ -1,38 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2004-2010 Gabor Bergmann and Daniel Varro
3 * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/>
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-v20.html.
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.pquery.rewriter;
10
11import org.eclipse.viatra.query.runtime.matchers.context.IQueryMetaContext;
12import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
13import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction;
14import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
15import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyCopier;
16import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyNormalizer;
17
18import java.util.LinkedHashSet;
19import java.util.Set;
20
21public class RefineryPBodyNormalizer extends PBodyNormalizer {
22 public RefineryPBodyNormalizer(IQueryMetaContext context) {
23 super(context);
24 }
25
26 @Override
27 public PDisjunction rewrite(PDisjunction disjunction) {
28 Set<PBody> normalizedBodies = new LinkedHashSet<>();
29 for (PBody body : disjunction.getBodies()) {
30 PBodyCopier copier = new RefineryPBodyCopier(body, getTraceCollector());
31 PBody modifiedBody = copier.getCopiedBody();
32 normalizeBody(modifiedBody);
33 normalizedBodies.add(modifiedBody);
34 modifiedBody.setStatus(PQuery.PQueryStatus.OK);
35 }
36 return new PDisjunction(normalizedBodies);
37 }
38}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java
deleted file mode 100644
index dc288ba0..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/rewriter/RefinerySurrogateQueryRewriter.java
+++ /dev/null
@@ -1,58 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2015, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
3 * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/>
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-v20.html.
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.pquery.rewriter;
10
11import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
12import org.eclipse.viatra.query.runtime.matchers.context.surrogate.SurrogateQueryRegistry;
13import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
14import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
15import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
16import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
17import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PDisjunction;
18import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
19import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PBodyCopier;
20import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PDisjunctionRewriter;
21import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
22import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
23
24import java.util.LinkedHashSet;
25import java.util.Set;
26
27public class RefinerySurrogateQueryRewriter extends PDisjunctionRewriter {
28 @Override
29 public PDisjunction rewrite(PDisjunction disjunction) {
30 Set<PBody> replacedBodies = new LinkedHashSet<>();
31 for (PBody body : disjunction.getBodies()) {
32 PBodyCopier copier = new RefineryPBodyCopier(body, getTraceCollector()) {
33
34 @Override
35 protected void copyTypeConstraint(TypeConstraint typeConstraint) {
36 PVariable[] mappedVariables = extractMappedVariables(typeConstraint);
37 Tuple variablesTuple = Tuples.flatTupleOf((Object[]) mappedVariables);
38 final IInputKey supplierKey = typeConstraint.getSupplierKey();
39 if (SurrogateQueryRegistry.instance().hasSurrogateQueryFQN(supplierKey)) {
40 PQuery surrogateQuery = SurrogateQueryRegistry.instance().getSurrogateQuery(supplierKey);
41 if (surrogateQuery == null) {
42 throw new IllegalStateException("Surrogate query for feature %s not found"
43 .formatted(supplierKey.getPrettyPrintableName()));
44 }
45 addTrace(typeConstraint, new PositivePatternCall(getCopiedBody(), variablesTuple,
46 surrogateQuery));
47 } else {
48 addTrace(typeConstraint, new TypeConstraint(getCopiedBody(), variablesTuple, supplierKey));
49 }
50 }
51 };
52 PBody modifiedBody = copier.getCopiedBody();
53 replacedBodies.add(modifiedBody);
54 modifiedBody.setStatus(PQuery.PQueryStatus.OK);
55 }
56 return new PDisjunction(replacedBodies);
57 }
58}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteBackendFactory.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteBackendFactory.java
deleted file mode 100644
index 517e511a..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteBackendFactory.java
+++ /dev/null
@@ -1,90 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath and Daniel Varro
3 * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/>
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-v20.html.
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.rete;
10
11import org.eclipse.viatra.query.runtime.matchers.backend.*;
12import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
13import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
14import org.eclipse.viatra.query.runtime.rete.construction.plancompiler.ReteRecipeCompiler;
15import org.eclipse.viatra.query.runtime.rete.matcher.IncrementalMatcherCapability;
16import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine;
17import org.eclipse.viatra.query.runtime.rete.matcher.TimelyConfiguration;
18import org.eclipse.viatra.query.runtime.rete.util.Options;
19
20// Singleton implementations follows the VIATRA implementation.
21@SuppressWarnings("squid:S6548")
22public class RefineryReteBackendFactory implements IQueryBackendFactory {
23 /**
24 * EXPERIMENTAL
25 */
26 protected static final int RETE_THREADS = 0;
27
28 /**
29 * @since 2.0
30 */
31 public static final RefineryReteBackendFactory INSTANCE = new RefineryReteBackendFactory();
32
33 /**
34 * @since 1.5
35 */
36 @Override
37 public IQueryBackend create(IQueryBackendContext context) {
38 return create(context, false, null);
39 }
40
41 /**
42 * @since 2.4
43 */
44 public IQueryBackend create(IQueryBackendContext context, boolean deleteAndReDeriveEvaluation,
45 TimelyConfiguration timelyConfiguration) {
46 ReteEngine engine;
47 engine = new RefineryReteEngine(context, RETE_THREADS, deleteAndReDeriveEvaluation, timelyConfiguration);
48 IQueryBackendHintProvider hintConfiguration = engine.getHintConfiguration();
49 ReteRecipeCompiler compiler = new RefineryReteRecipeCompiler(
50 Options.builderMethod.layoutStrategy(context, hintConfiguration), context.getLogger(),
51 context.getRuntimeContext().getMetaContext(), context.getQueryCacheContext(), hintConfiguration,
52 context.getQueryAnalyzer(), deleteAndReDeriveEvaluation, timelyConfiguration);
53 engine.setCompiler(compiler);
54 return engine;
55 }
56
57 @Override
58 public Class<? extends IQueryBackend> getBackendClass() {
59 return ReteEngine.class;
60 }
61
62 @Override
63 public int hashCode() {
64 return RefineryReteBackendFactory.class.hashCode();
65 }
66
67 @Override
68 public boolean equals(Object obj) {
69 if (this == obj) {
70 return true;
71 }
72 if (obj == null) {
73 return false;
74 }
75 return obj instanceof RefineryReteBackendFactory;
76 }
77
78 /**
79 * @since 1.4
80 */
81 @Override
82 public IMatcherCapability calculateRequiredCapability(PQuery query, QueryEvaluationHint hint) {
83 return new IncrementalMatcherCapability();
84 }
85
86 @Override
87 public boolean isCaching() {
88 return true;
89 }
90}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteEngine.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteEngine.java
deleted file mode 100644
index c088219b..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteEngine.java
+++ /dev/null
@@ -1,134 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete;
7
8import org.apache.log4j.Logger;
9import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
10import org.eclipse.viatra.query.runtime.matchers.context.IQueryBackendContext;
11import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine;
12import org.eclipse.viatra.query.runtime.rete.matcher.TimelyConfiguration;
13import org.eclipse.viatra.query.runtime.rete.network.Network;
14import org.eclipse.viatra.query.runtime.rete.network.NodeProvisioner;
15import org.eclipse.viatra.query.runtime.rete.network.ReteContainer;
16
17import java.io.IOException;
18import java.lang.invoke.MethodHandle;
19import java.lang.invoke.MethodHandles;
20import java.lang.invoke.MethodType;
21
22public class RefineryReteEngine extends ReteEngine {
23 private static final MethodHandle REFINERY_NODE_FACTORY_CONSTRUCTOR;
24 private static final MethodHandle REFINERY_CONNECTION_FACTORY_CONSTRUCTOR;
25 private static final MethodHandle NETWORK_NODE_FACTORY_SETTER;
26 private static final MethodHandle RETE_CONTAINER_CONNECTION_FACTORY_SETTER;
27 private static final MethodHandle NODE_PROVISIONER_NODE_FACTORY_SETTER;
28 private static final MethodHandle NODE_PROVISIONER_CONNECTION_FACTORY_SETTER;
29
30 static {
31 MethodHandles.Lookup lookup;
32 try {
33 lookup = MethodHandles.privateLookupIn(Network.class, MethodHandles.lookup());
34 } catch (IllegalAccessException e) {
35 throw new IllegalStateException("Cannot create private lookup", e);
36 }
37 var refineryNodeFactoryClass = defineClassFromFile(lookup, "RefineryNodeFactory");
38 var refinaryConnectionFactoryClass = defineClassFromFile(lookup, "RefineryConnectionFactory");
39 try {
40 REFINERY_NODE_FACTORY_CONSTRUCTOR = lookup.findConstructor(refineryNodeFactoryClass,
41 MethodType.methodType(Void.TYPE, Logger.class));
42 REFINERY_CONNECTION_FACTORY_CONSTRUCTOR = lookup.findConstructor(refinaryConnectionFactoryClass,
43 MethodType.methodType(Void.TYPE, ReteContainer.class));
44 } catch (NoSuchMethodException | IllegalAccessException e) {
45 throw new IllegalStateException("Cannot get constructor", e);
46 }
47 var nodeFactoryClass = refineryNodeFactoryClass.getSuperclass();
48 var connectionFactoryClass = refinaryConnectionFactoryClass.getSuperclass();
49 try {
50 NETWORK_NODE_FACTORY_SETTER = lookup.findSetter(Network.class, "nodeFactory", nodeFactoryClass);
51 RETE_CONTAINER_CONNECTION_FACTORY_SETTER = lookup.findSetter(ReteContainer.class, "connectionFactory",
52 connectionFactoryClass);
53 NODE_PROVISIONER_NODE_FACTORY_SETTER = lookup.findSetter(NodeProvisioner.class, "nodeFactory",
54 nodeFactoryClass);
55 NODE_PROVISIONER_CONNECTION_FACTORY_SETTER = lookup.findSetter(NodeProvisioner.class, "connectionFactory",
56 connectionFactoryClass);
57 } catch (NoSuchFieldException | IllegalAccessException e) {
58 throw new IllegalStateException("Cannot get field setter", e);
59 }
60 }
61
62 private static Class<?> defineClassFromFile(MethodHandles.Lookup lookup, String name) {
63 byte[] classBytes;
64 try (var resource = Network.class.getResourceAsStream(name + ".class")) {
65 if (resource == null) {
66 throw new IllegalStateException("Cannot find %s class file".formatted(name));
67 }
68 classBytes = resource.readAllBytes();
69 } catch (IOException e) {
70 throw new IllegalStateException("Cannot read %s class file".formatted(name), e);
71 }
72 Class<?> clazz;
73 try {
74 clazz = lookup.defineClass(classBytes);
75 } catch (IllegalAccessException e) {
76 throw new IllegalStateException("Cannot define %s class".formatted(name), e);
77 }
78 return clazz;
79 }
80
81 public RefineryReteEngine(IQueryBackendContext context, int reteThreads, boolean deleteAndReDeriveEvaluation,
82 TimelyConfiguration timelyConfiguration) {
83 super(context, reteThreads, deleteAndReDeriveEvaluation, timelyConfiguration);
84 installFactories();
85 }
86
87 private void installFactories() {
88 var logger = getLogger();
89 Object nodeFactory;
90 try {
91 nodeFactory = REFINERY_NODE_FACTORY_CONSTRUCTOR.invoke(logger);
92 } catch (Error e) {
93 // Fatal JVM errors should not be wrapped.
94 throw e;
95 } catch (Throwable e) {
96 throw new IllegalStateException("Cannot construct node factory", e);
97 }
98 try {
99 NETWORK_NODE_FACTORY_SETTER.invoke(reteNet, nodeFactory);
100 } catch (Error e) {
101 // Fatal JVM errors should not be wrapped.
102 throw e;
103 } catch (Throwable e) {
104 throw new IllegalStateException("Cannot set factory", e);
105 }
106 for (var container : reteNet.getContainers()) {
107 Object connectionFactory;
108 try {
109 connectionFactory = REFINERY_CONNECTION_FACTORY_CONSTRUCTOR.invoke(container);
110 } catch (Error e) {
111 // Fatal JVM errors should not be wrapped.
112 throw e;
113 } catch (Throwable e) {
114 throw new IllegalStateException("Cannot construct connection factory", e);
115 }
116 var provisioner = container.getProvisioner();
117 try {
118 RETE_CONTAINER_CONNECTION_FACTORY_SETTER.invoke(container, connectionFactory);
119 NODE_PROVISIONER_NODE_FACTORY_SETTER.invoke(provisioner, nodeFactory);
120 NODE_PROVISIONER_CONNECTION_FACTORY_SETTER.invoke(provisioner, connectionFactory);
121 } catch (Error e) {
122 // Fatal JVM errors should not be wrapped.
123 throw e;
124 } catch (Throwable e) {
125 throw new IllegalStateException("Cannot set factory", e);
126 }
127 }
128 }
129
130 @Override
131 public IQueryBackendFactory getFactory() {
132 return RefineryReteBackendFactory.INSTANCE;
133 }
134}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteRecipeCompiler.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteRecipeCompiler.java
deleted file mode 100644
index fd1b48d8..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/RefineryReteRecipeCompiler.java
+++ /dev/null
@@ -1,228 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath and Daniel Varro
3 * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/>
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-v20.html.
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.rete;
10
11import org.apache.log4j.Logger;
12import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendHintProvider;
13import org.eclipse.viatra.query.runtime.matchers.context.IQueryCacheContext;
14import org.eclipse.viatra.query.runtime.matchers.context.IQueryMetaContext;
15import org.eclipse.viatra.query.runtime.matchers.planning.IQueryPlannerStrategy;
16import org.eclipse.viatra.query.runtime.matchers.planning.SubPlan;
17import org.eclipse.viatra.query.runtime.matchers.planning.operations.PApply;
18import org.eclipse.viatra.query.runtime.matchers.planning.operations.PEnumerate;
19import org.eclipse.viatra.query.runtime.matchers.psystem.EnumerablePConstraint;
20import org.eclipse.viatra.query.runtime.matchers.psystem.analysis.QueryAnalyzer;
21import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PQuery;
22import org.eclipse.viatra.query.runtime.matchers.psystem.rewriters.PDisjunctionRewriterCacher;
23import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
24import org.eclipse.viatra.query.runtime.rete.construction.plancompiler.CompilerHelper;
25import org.eclipse.viatra.query.runtime.rete.construction.plancompiler.ReteRecipeCompiler;
26import org.eclipse.viatra.query.runtime.rete.matcher.TimelyConfiguration;
27import org.eclipse.viatra.query.runtime.rete.recipes.ReteNodeRecipe;
28import org.eclipse.viatra.query.runtime.rete.traceability.CompiledSubPlan;
29import org.eclipse.viatra.query.runtime.rete.traceability.PlanningTrace;
30import org.eclipse.viatra.query.runtime.rete.util.ReteHintOptions;
31import org.jetbrains.annotations.Nullable;
32import tools.refinery.store.query.viatra.internal.pquery.RepresentativeElectionConstraint;
33import tools.refinery.store.query.viatra.internal.rete.recipe.RefineryRecipesFactory;
34import tools.refinery.store.query.viatra.internal.pquery.rewriter.RefineryPBodyNormalizer;
35import tools.refinery.store.query.viatra.internal.pquery.rewriter.RefinerySurrogateQueryRewriter;
36
37import java.lang.invoke.MethodHandle;
38import java.lang.invoke.MethodHandles;
39import java.lang.invoke.MethodType;
40import java.lang.reflect.Field;
41import java.util.Map;
42
43// Since we don't modify VIATRA code, this is our last resort.
44@SuppressWarnings("squid:S3011")
45public class RefineryReteRecipeCompiler extends ReteRecipeCompiler {
46 private static final MethodHandle GET_SUB_PLAN_COMPILER_CACHE;
47 private static final MethodHandle GET_COMPILER_BACK_TRACE;
48 private static final Field NORMALIZER_FIELD;
49 private static final MethodHandle DO_COMPILE_DISPATCH;
50 private static final MethodHandle COMPILE_TO_NATURAL_JOIN;
51 private static final MethodHandle REFER_QUERY;
52
53 static {
54 MethodHandles.Lookup lookup;
55 try {
56 lookup = MethodHandles.privateLookupIn(ReteRecipeCompiler.class, MethodHandles.lookup());
57 } catch (IllegalAccessException e) {
58 throw new IllegalStateException("Failed to create lookup", e);
59 }
60 try {
61 GET_SUB_PLAN_COMPILER_CACHE = lookup.findGetter(ReteRecipeCompiler.class, "subPlanCompilerCache",
62 Map.class);
63 GET_COMPILER_BACK_TRACE = lookup.findGetter(ReteRecipeCompiler.class, "compilerBackTrace", Map.class);
64 } catch (NoSuchFieldException | IllegalAccessException e) {
65 throw new IllegalStateException("Failed to find getter", e);
66 }
67
68 try {
69 NORMALIZER_FIELD = ReteRecipeCompiler.class.getDeclaredField("normalizer");
70 } catch (NoSuchFieldException e) {
71 throw new IllegalStateException("Failed to find field", e);
72 }
73 NORMALIZER_FIELD.setAccessible(true);
74
75 try {
76 DO_COMPILE_DISPATCH = lookup.findVirtual(ReteRecipeCompiler.class, "doCompileDispatch",
77 MethodType.methodType(CompiledSubPlan.class, SubPlan.class));
78 COMPILE_TO_NATURAL_JOIN = lookup.findVirtual(ReteRecipeCompiler.class, "compileToNaturalJoin",
79 MethodType.methodType(CompiledSubPlan.class, SubPlan.class, PlanningTrace.class,
80 PlanningTrace.class));
81 REFER_QUERY = lookup.findVirtual(ReteRecipeCompiler.class, "referQuery",
82 MethodType.methodType(PlanningTrace.class, PQuery.class, SubPlan.class, Tuple.class));
83 } catch (NoSuchMethodException | IllegalAccessException e) {
84 throw new IllegalStateException("Failed to find method", e);
85 }
86 }
87
88 private final Map<SubPlan, CompiledSubPlan> subPlanCompilerCache;
89 private final Map<ReteNodeRecipe, SubPlan> compilerBackTrace;
90
91 public RefineryReteRecipeCompiler(IQueryPlannerStrategy plannerStrategy, Logger logger,
92 IQueryMetaContext metaContext, IQueryCacheContext queryCacheContext,
93 IQueryBackendHintProvider hintProvider, QueryAnalyzer queryAnalyzer,
94 boolean deleteAndReDeriveEvaluation, TimelyConfiguration timelyEvaluation) {
95 super(plannerStrategy, logger, metaContext, queryCacheContext, hintProvider, queryAnalyzer,
96 deleteAndReDeriveEvaluation, timelyEvaluation);
97
98 var normalizer = new PDisjunctionRewriterCacher(new RefinerySurrogateQueryRewriter(),
99 new RefineryPBodyNormalizer(metaContext) {
100
101 @Override
102 protected boolean shouldExpandWeakenedAlternatives(PQuery query) {
103 var hint = hintProvider.getQueryEvaluationHint(query);
104 return ReteHintOptions.expandWeakenedAlternativeConstraints.getValueOrDefault(hint);
105 }
106
107 });
108 try {
109 // https://docs.oracle.com/javase/specs/jls/se17/html/jls-17.html#jls-17.5.3
110 // "The object should not be made visible to other threads, nor should the final fields be read,
111 // until all updates to the final fields of the object are complete."
112 // The {@code super} constructor only sets but doesn't read the {@code normalizer} field,
113 // therefore this is fine.
114 NORMALIZER_FIELD.set(this, normalizer);
115 } catch (IllegalAccessException e) {
116 throw new IllegalStateException("Failed to set private final field", e);
117 }
118
119 try {
120 @SuppressWarnings("unchecked")
121 var cache = (Map<SubPlan, CompiledSubPlan>) GET_SUB_PLAN_COMPILER_CACHE.invokeExact(
122 (ReteRecipeCompiler) this);
123 subPlanCompilerCache = cache;
124 @SuppressWarnings("unchecked")
125 var backTrace = (Map<ReteNodeRecipe, SubPlan>) GET_COMPILER_BACK_TRACE.invokeExact(
126 (ReteRecipeCompiler) this);
127 compilerBackTrace = backTrace;
128 } catch (Error e) {
129 // Fatal JVM errors should not be wrapped.
130 throw e;
131 } catch (Throwable e) {
132 throw new IllegalStateException("Failed to access private fields", e);
133 }
134 }
135
136 @Override
137 public CompiledSubPlan getCompiledForm(SubPlan plan) {
138 CompiledSubPlan compiled = subPlanCompilerCache.get(plan);
139 if (compiled == null) {
140 compiled = doCompileDispatchExtension(plan);
141 if (compiled == null) {
142 compiled = superDoCompileDispatch(plan);
143 }
144 subPlanCompilerCache.put(plan, compiled);
145 compilerBackTrace.put(compiled.getRecipe(), plan);
146 }
147 return compiled;
148 }
149
150 @Nullable
151 private CompiledSubPlan doCompileDispatchExtension(SubPlan plan) {
152 var operation = plan.getOperation();
153 if (operation instanceof PEnumerate enumerateOperation) {
154 return doCompileEnumerateExtension(enumerateOperation.getEnumerablePConstraint(), plan);
155 } else if (operation instanceof PApply applyOperation &&
156 applyOperation.getPConstraint() instanceof EnumerablePConstraint constraint) {
157 var secondaryParent = doEnumerateDispatchExtension(plan, constraint);
158 if (secondaryParent != null) {
159 var primaryParent = getCompiledForm(plan.getParentPlans().get(0));
160 return superCompileToNaturalJoin(plan, primaryParent, secondaryParent);
161 }
162 }
163 return null;
164 }
165
166 @Nullable
167 private CompiledSubPlan doCompileEnumerateExtension(EnumerablePConstraint constraint, SubPlan plan) {
168 var coreTrace = doEnumerateDispatchExtension(plan, constraint);
169 if (coreTrace == null) {
170 return null;
171 }
172 var trimmedTrace = CompilerHelper.checkAndTrimEqualVariables(plan, coreTrace);
173 return trimmedTrace.cloneFor(plan);
174 }
175
176 @Nullable
177 private PlanningTrace doEnumerateDispatchExtension(SubPlan plan, EnumerablePConstraint constraint) {
178 if (constraint instanceof RepresentativeElectionConstraint representativeElectionConstraint) {
179 return compileEnumerableExtension(plan, representativeElectionConstraint);
180 }
181 return null;
182 }
183
184 private PlanningTrace compileEnumerableExtension(SubPlan plan, RepresentativeElectionConstraint constraint) {
185 var referredQuery = constraint.getSupplierKey();
186 var callTrace = superReferQuery(referredQuery, plan, constraint.getVariablesTuple());
187 var recipe = RefineryRecipesFactory.eINSTANCE.createRepresentativeElectionRecipe();
188 recipe.setParent(callTrace.getRecipe());
189 recipe.setConnectivity(constraint.getConnectivity());
190 return new PlanningTrace(plan, CompilerHelper.convertVariablesTuple(constraint), recipe, callTrace);
191 }
192
193 private CompiledSubPlan superDoCompileDispatch(SubPlan plan) {
194 try {
195 return (CompiledSubPlan) DO_COMPILE_DISPATCH.invokeExact((ReteRecipeCompiler) this, plan);
196 } catch (Error | RuntimeException e) {
197 // Fatal JVM errors and runtime exceptions should not be wrapped.
198 throw e;
199 } catch (Throwable e) {
200 throw new IllegalStateException("Failed to call doCompileDispatch", e);
201 }
202 }
203
204 private CompiledSubPlan superCompileToNaturalJoin(SubPlan plan, PlanningTrace leftCompiled,
205 PlanningTrace rightCompiled) {
206 try {
207 return (CompiledSubPlan) COMPILE_TO_NATURAL_JOIN.invokeExact((ReteRecipeCompiler) this, plan,
208 leftCompiled, rightCompiled);
209 } catch (Error | RuntimeException e) {
210 // Fatal JVM errors and runtime exceptions should not be wrapped.
211 throw e;
212 } catch (Throwable e) {
213 throw new IllegalStateException("Failed to call compileToNaturalJoin", e);
214 }
215 }
216
217 private PlanningTrace superReferQuery(PQuery query, SubPlan plan, Tuple actualParametersTuple) {
218 try {
219 return (PlanningTrace) REFER_QUERY.invokeExact((ReteRecipeCompiler) this, query, plan,
220 actualParametersTuple);
221 } catch (Error | RuntimeException e) {
222 // Fatal JVM errors and runtime exceptions should not be wrapped.
223 throw e;
224 } catch (Throwable e) {
225 throw new IllegalStateException("Failed to call referQuery", e);
226 }
227 }
228}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java
deleted file mode 100644
index 0fe5ee27..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryConnectionFactoryExtensions.java
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.network;
7
8import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
9import org.eclipse.viatra.query.runtime.rete.network.Node;
10import org.eclipse.viatra.query.runtime.rete.network.ReteContainer;
11import org.eclipse.viatra.query.runtime.rete.network.Supplier;
12import org.eclipse.viatra.query.runtime.rete.remote.Address;
13import org.eclipse.viatra.query.runtime.rete.traceability.RecipeTraceInfo;
14import tools.refinery.store.query.viatra.internal.rete.recipe.RepresentativeElectionRecipe;
15
16import java.util.ArrayList;
17
18public class RefineryConnectionFactoryExtensions {
19 private final ReteContainer reteContainer;
20
21 public RefineryConnectionFactoryExtensions(ReteContainer reteContainer) {
22 this.reteContainer = reteContainer;
23 }
24
25 public boolean connectToParents(RecipeTraceInfo recipeTrace, Node freshNode) {
26 var recipe = recipeTrace.getRecipe();
27 if (recipe instanceof RepresentativeElectionRecipe representativeElectionRecipe) {
28 connectToParents(representativeElectionRecipe, (RepresentativeElectionNode) freshNode);
29 return true;
30 }
31 return false;
32 }
33
34 private void connectToParents(RepresentativeElectionRecipe recipe, RepresentativeElectionNode freshNode) {
35 var parentRecipe = recipe.getParent();
36 // Apparently VIATRA ensures that this cast is safe, see
37 // {@link org.eclipse.viatra.query.runtime.rete.network.ConnectionFactory.connectToParent}.
38 @SuppressWarnings("unchecked")
39 var parentAddress = (Address<? extends Supplier>) reteContainer.getNetwork()
40 .getExistingNodeByRecipe(parentRecipe);
41 var parentSupplier = reteContainer.getProvisioner().asSupplier(parentAddress);
42 var tuples = new ArrayList<Tuple>();
43 parentSupplier.pullInto(tuples, true);
44 freshNode.reinitializeWith(tuples);
45 reteContainer.connect(parentSupplier, freshNode);
46 }
47}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryNodeFactoryExtensions.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryNodeFactoryExtensions.java
deleted file mode 100644
index 82b63a55..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RefineryNodeFactoryExtensions.java
+++ /dev/null
@@ -1,44 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.network;
7
8import org.eclipse.viatra.query.runtime.rete.network.ReteContainer;
9import org.eclipse.viatra.query.runtime.rete.network.Supplier;
10import org.eclipse.viatra.query.runtime.rete.recipes.ReteNodeRecipe;
11import org.eclipse.viatra.query.runtime.rete.traceability.TraceInfo;
12import org.jetbrains.annotations.Nullable;
13import tools.refinery.store.query.viatra.internal.rete.recipe.RepresentativeElectionRecipe;
14
15public class RefineryNodeFactoryExtensions {
16 @Nullable
17 public Supplier createNode(ReteContainer reteContainer, ReteNodeRecipe recipe, TraceInfo... traces) {
18 var result = instantiateNode(reteContainer, recipe);
19 if (result == null) {
20 return null;
21 }
22 for (var traceInfo : traces) {
23 result.assignTraceInfo(traceInfo);
24 }
25 return result;
26 }
27
28 @Nullable
29 private Supplier instantiateNode(ReteContainer reteContainer, ReteNodeRecipe recipe) {
30 if (recipe instanceof RepresentativeElectionRecipe representativeElectionRecipe) {
31 return instantiateRepresentativeElectionNode(reteContainer, representativeElectionRecipe);
32 }
33 return null;
34 }
35
36 private Supplier instantiateRepresentativeElectionNode(ReteContainer reteContainer,
37 RepresentativeElectionRecipe recipe) {
38 RepresentativeElectionAlgorithm.Factory algorithmFactory = switch (recipe.getConnectivity()) {
39 case STRONG -> StronglyConnectedComponentAlgorithm::new;
40 case WEAK -> WeaklyConnectedComponentAlgorithm::new;
41 };
42 return new RepresentativeElectionNode(reteContainer, algorithmFactory);
43 }
44}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionAlgorithm.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionAlgorithm.java
deleted file mode 100644
index ff5c7158..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionAlgorithm.java
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.network;
7
8import org.eclipse.viatra.query.runtime.base.itc.graphimpl.Graph;
9import org.eclipse.viatra.query.runtime.base.itc.igraph.IGraphObserver;
10import org.eclipse.viatra.query.runtime.matchers.util.Direction;
11
12import java.util.*;
13
14public abstract class RepresentativeElectionAlgorithm implements IGraphObserver<Object> {
15 protected final Graph<Object> graph;
16 protected final Map<Object, Object> representatives = new HashMap<>();
17 protected final Map<Object, Set<Object>> components = new HashMap<>();
18 private RepresentativeElectionNode observer;
19
20 protected RepresentativeElectionAlgorithm(Graph<Object> graph) {
21 this.graph = graph;
22 initializeComponents();
23 graph.attachObserver(this);
24 }
25
26 protected abstract void initializeComponents();
27
28 protected void initializeSet(Set<Object> set) {
29 var iterator = set.iterator();
30 if (!iterator.hasNext()) {
31 // Set is empty.
32 return;
33 }
34 var representative = iterator.next();
35 for (var node : set) {
36 var oldRepresentative = representatives.put(node, representative);
37 if (oldRepresentative != null && !representative.equals(oldRepresentative)) {
38 throw new IllegalStateException("Node %s is already in a set represented by %s, cannot add it to %s"
39 .formatted(node, oldRepresentative, set));
40 }
41 }
42 components.put(representative, set);
43 }
44
45 protected void merge(Object leftRepresentative, Object rightRepresentative) {
46 if (leftRepresentative.equals(rightRepresentative)) {
47 return;
48 }
49 var leftSet = getComponent(leftRepresentative);
50 var rightSet = getComponent(rightRepresentative);
51 if (leftSet.size() < rightSet.size()) {
52 merge(rightRepresentative, rightSet, leftRepresentative, leftSet);
53 } else {
54 merge(leftRepresentative, leftSet, rightRepresentative, rightSet);
55 }
56 }
57
58 private void merge(Object preservedRepresentative, Set<Object> preservedSet, Object removedRepresentative,
59 Set<Object> removedSet) {
60 components.remove(removedRepresentative);
61 for (var node : removedSet) {
62 representatives.put(node, preservedRepresentative);
63 preservedSet.add(node);
64 notifyToObservers(node, removedRepresentative, preservedRepresentative);
65 }
66 }
67
68 protected void assignNewRepresentative(Object oldRepresentative, Set<Object> set) {
69 var iterator = set.iterator();
70 if (!iterator.hasNext()) {
71 return;
72 }
73 var newRepresentative = iterator.next();
74 components.put(newRepresentative, set);
75 for (var node : set) {
76 var oldRepresentativeOfNode = representatives.put(node, newRepresentative);
77 if (!oldRepresentative.equals(oldRepresentativeOfNode)) {
78 throw new IllegalArgumentException("Node %s was not represented by %s but by %s"
79 .formatted(node, oldRepresentative, oldRepresentativeOfNode));
80 }
81 notifyToObservers(node, oldRepresentative, newRepresentative);
82 }
83 }
84
85 public void setObserver(RepresentativeElectionNode observer) {
86 this.observer = observer;
87 }
88
89 public Map<Object, Set<Object>> getComponents() {
90 return components;
91 }
92
93 public Object getRepresentative(Object node) {
94 return representatives.get(node);
95 }
96
97 public Set<Object> getComponent(Object representative) {
98 return components.get(representative);
99 }
100
101 public void dispose() {
102 graph.detachObserver(this);
103 }
104
105 @Override
106 public void nodeInserted(Object n) {
107 var component = new HashSet<>(1);
108 component.add(n);
109 initializeSet(component);
110 notifyToObservers(n, n, Direction.INSERT);
111 }
112
113 @Override
114 public void nodeDeleted(Object n) {
115 var representative = representatives.remove(n);
116 if (!representative.equals(n)) {
117 throw new IllegalStateException("Trying to delete node with dangling edges");
118 }
119 components.remove(representative);
120 notifyToObservers(n, representative, Direction.DELETE);
121 }
122
123 protected void notifyToObservers(Object node, Object oldRepresentative, Object newRepresentative) {
124 notifyToObservers(node, oldRepresentative, Direction.DELETE);
125 notifyToObservers(node, newRepresentative, Direction.INSERT);
126 }
127
128 protected void notifyToObservers(Object node, Object representative, Direction direction) {
129 if (observer != null) {
130 observer.tupleChanged(node, representative, direction);
131 }
132 }
133
134 interface Factory {
135 RepresentativeElectionAlgorithm create(Graph<Object> graph);
136 }
137}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionNode.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionNode.java
deleted file mode 100644
index 701f6ffe..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/RepresentativeElectionNode.java
+++ /dev/null
@@ -1,120 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2012, Tamas Szabo, Gabor Bergmann, Istvan Rath and Daniel Varro
3 * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/>
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-v20.html.
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.store.query.viatra.internal.rete.network;
10
11import org.eclipse.viatra.query.runtime.base.itc.graphimpl.Graph;
12import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
13import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
14import org.eclipse.viatra.query.runtime.matchers.util.Clearable;
15import org.eclipse.viatra.query.runtime.matchers.util.Direction;
16import org.eclipse.viatra.query.runtime.matchers.util.timeline.Timeline;
17import org.eclipse.viatra.query.runtime.rete.network.ReteContainer;
18import org.eclipse.viatra.query.runtime.rete.network.communication.Timestamp;
19import org.eclipse.viatra.query.runtime.rete.single.SingleInputNode;
20
21import java.util.Collection;
22import java.util.Map;
23
24public class RepresentativeElectionNode extends SingleInputNode implements Clearable {
25 private final RepresentativeElectionAlgorithm.Factory algorithmFactory;
26 private Graph<Object> graph;
27 private RepresentativeElectionAlgorithm algorithm;
28
29 public RepresentativeElectionNode(ReteContainer reteContainer,
30 RepresentativeElectionAlgorithm.Factory algorithmFactory) {
31 super(reteContainer);
32 this.algorithmFactory = algorithmFactory;
33 graph = new Graph<>();
34 algorithm = algorithmFactory.create(graph);
35 algorithm.setObserver(this);
36 reteContainer.registerClearable(this);
37 }
38
39 @Override
40 public void networkStructureChanged() {
41 if (reteContainer.isTimelyEvaluation() && reteContainer.getCommunicationTracker().isInRecursiveGroup(this)) {
42 throw new IllegalStateException(this + " cannot be used in recursive differential dataflow evaluation!");
43 }
44 super.networkStructureChanged();
45 }
46
47 public void reinitializeWith(Collection<Tuple> tuples) {
48 algorithm.dispose();
49 graph = new Graph<>();
50 for (var tuple : tuples) {
51 insertEdge(tuple.get(0), tuple.get(1));
52 }
53 algorithm = algorithmFactory.create(graph);
54 algorithm.setObserver(this);
55 }
56
57 public void tupleChanged(Object source, Object representative, Direction direction) {
58 var tuple = Tuples.staticArityFlatTupleOf(source, representative);
59 propagateUpdate(direction, tuple, Timestamp.ZERO);
60 }
61
62 @Override
63 public void clear() {
64 algorithm.dispose();
65 graph = new Graph<>();
66 algorithm = algorithmFactory.create(graph);
67 }
68
69 @Override
70 public void update(Direction direction, Tuple updateElement, Timestamp timestamp) {
71 var source = updateElement.get(0);
72 var target = updateElement.get(1);
73 switch (direction) {
74 case INSERT -> insertEdge(source, target);
75 case DELETE -> deleteEdge(source, target);
76 default -> throw new IllegalArgumentException("Unknown direction: " + direction);
77 }
78 }
79
80 private void insertEdge(Object source, Object target) {
81 graph.insertNode(source);
82 graph.insertNode(target);
83 graph.insertEdge(source, target);
84 }
85
86 private void deleteEdge(Object source, Object target) {
87 graph.deleteEdgeIfExists(source, target);
88 if (isIsolated(source)) {
89 graph.deleteNode(source);
90 }
91 if (!source.equals(target) && isIsolated(target)) {
92 graph.deleteNode(target);
93 }
94 }
95
96 private boolean isIsolated(Object node) {
97 return graph.getTargetNodes(node).isEmpty() && graph.getSourceNodes(node).isEmpty();
98 }
99
100 @Override
101 public void pullInto(Collection<Tuple> collector, boolean flush) {
102 for (var entry : algorithm.getComponents().entrySet()) {
103 var representative = entry.getKey();
104 for (var node : entry.getValue()) {
105 collector.add(Tuples.staticArityFlatTupleOf(node, representative));
106 }
107 }
108 }
109
110 @Override
111 public void pullIntoWithTimeline(Map<Tuple, Timeline<Timestamp>> collector, boolean flush) {
112 // Use all zero timestamps because this node cannot be used in recursive groups anyway.
113 for (var entry : algorithm.getComponents().entrySet()) {
114 var representative = entry.getKey();
115 for (var node : entry.getValue()) {
116 collector.put(Tuples.staticArityFlatTupleOf(node, representative), Timestamp.INSERT_AT_ZERO_TIMELINE);
117 }
118 }
119 }
120}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/StronglyConnectedComponentAlgorithm.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/StronglyConnectedComponentAlgorithm.java
deleted file mode 100644
index 11155f3e..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/StronglyConnectedComponentAlgorithm.java
+++ /dev/null
@@ -1,66 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.network;
7
8import org.eclipse.viatra.query.runtime.base.itc.alg.misc.GraphHelper;
9import org.eclipse.viatra.query.runtime.base.itc.alg.misc.bfs.BFS;
10import org.eclipse.viatra.query.runtime.base.itc.alg.misc.scc.SCC;
11import org.eclipse.viatra.query.runtime.base.itc.graphimpl.Graph;
12
13import java.util.Collection;
14import java.util.Set;
15
16public class StronglyConnectedComponentAlgorithm extends RepresentativeElectionAlgorithm {
17 public StronglyConnectedComponentAlgorithm(Graph<Object> graph) {
18 super(graph);
19 }
20
21 @Override
22 protected void initializeComponents() {
23 var computedSCCs = SCC.computeSCC(graph).getSccs();
24 for (var computedSCC : computedSCCs) {
25 initializeSet(computedSCC);
26 }
27 }
28
29 @Override
30 public void edgeInserted(Object source, Object target) {
31 var sourceRoot = getRepresentative(source);
32 var targetRoot = getRepresentative(target);
33 if (sourceRoot.equals(targetRoot)) {
34 // New edge does not change strongly connected components.
35 return;
36 }
37 if (BFS.isReachable(target, source, graph)) {
38 merge(sourceRoot, targetRoot);
39 }
40 }
41
42 @Override
43 public void edgeDeleted(Object source, Object target) {
44 var sourceRoot = getRepresentative(source);
45 var targetRoot = getRepresentative(target);
46 if (!sourceRoot.equals(targetRoot)) {
47 // New edge does not change strongly connected components.
48 return;
49 }
50 var component = GraphHelper.getSubGraph(getComponent(sourceRoot), graph);
51 if (!BFS.isReachable(source, target, component)) {
52 var newSCCs = SCC.computeSCC(component).getSccs();
53 split(sourceRoot, newSCCs);
54 }
55 }
56
57 private void split(Object preservedRepresentative, Collection<? extends Set<Object>> sets) {
58 for (var set : sets) {
59 if (set.contains(preservedRepresentative)) {
60 components.put(preservedRepresentative, set);
61 } else {
62 assignNewRepresentative(preservedRepresentative, set);
63 }
64 }
65 }
66}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/WeaklyConnectedComponentAlgorithm.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/WeaklyConnectedComponentAlgorithm.java
deleted file mode 100644
index 118004dd..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/network/WeaklyConnectedComponentAlgorithm.java
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.network;
7
8import org.eclipse.viatra.query.runtime.base.itc.graphimpl.Graph;
9
10import java.util.ArrayDeque;
11import java.util.HashSet;
12import java.util.Set;
13
14public class WeaklyConnectedComponentAlgorithm extends RepresentativeElectionAlgorithm {
15 public WeaklyConnectedComponentAlgorithm(Graph<Object> graph) {
16 super(graph);
17 }
18
19 @Override
20 protected void initializeComponents() {
21 for (var node : graph.getAllNodes()) {
22 if (representatives.containsKey(node)) {
23 continue;
24 }
25 var reachable = getReachableNodes(node);
26 initializeSet(reachable);
27 }
28 }
29
30 @Override
31 public void edgeInserted(Object source, Object target) {
32 var sourceRoot = getRepresentative(source);
33 var targetRoot = getRepresentative(target);
34 merge(sourceRoot, targetRoot);
35 }
36
37 @Override
38 public void edgeDeleted(Object source, Object target) {
39 var sourceRoot = getRepresentative(source);
40 var targetRoot = getRepresentative(target);
41 if (!sourceRoot.equals(targetRoot)) {
42 throw new IllegalArgumentException("Trying to remove edge not in graph");
43 }
44 var targetReachable = getReachableNodes(target);
45 if (!targetReachable.contains(source)) {
46 split(sourceRoot, targetReachable);
47 }
48 }
49
50 private void split(Object sourceRepresentative, Set<Object> targetReachable) {
51 var sourceComponent = getComponent(sourceRepresentative);
52 sourceComponent.removeAll(targetReachable);
53 if (targetReachable.contains(sourceRepresentative)) {
54 components.put(sourceRepresentative, targetReachable);
55 assignNewRepresentative(sourceRepresentative, sourceComponent);
56 } else {
57 assignNewRepresentative(sourceRepresentative, targetReachable);
58 }
59 }
60
61 private Set<Object> getReachableNodes(Object source) {
62 var retSet = new HashSet<>();
63 retSet.add(source);
64 var nodeQueue = new ArrayDeque<>();
65 nodeQueue.addLast(source);
66
67 while (!nodeQueue.isEmpty()) {
68 var node = nodeQueue.removeFirst();
69 for (var neighbor : graph.getTargetNodes(node).distinctValues()) {
70 if (!retSet.contains(neighbor)) {
71 retSet.add(neighbor);
72 nodeQueue.addLast(neighbor);
73 }
74 }
75 for (var neighbor : graph.getSourceNodes(node).distinctValues()) {
76 if (!retSet.contains(neighbor)) {
77 retSet.add(neighbor);
78 nodeQueue.addLast(neighbor);
79 }
80 }
81 }
82
83 return retSet;
84 }
85}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactory.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactory.java
deleted file mode 100644
index 1f8b3034..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactory.java
+++ /dev/null
@@ -1,22 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.recipe;
7
8import org.eclipse.emf.ecore.EDataType;
9import org.eclipse.emf.ecore.EFactory;
10import tools.refinery.store.query.literal.Connectivity;
11
12// Naming and index computation follows EMF conventions.
13@SuppressWarnings("squid:S115")
14public interface RefineryRecipesFactory extends EFactory {
15 RefineryRecipesFactory eINSTANCE = RefineryRecipesFactoryImpl.init();
16
17 RepresentativeElectionRecipe createRepresentativeElectionRecipe();
18
19 Connectivity createConnectivityFromString(EDataType eDataType, String initialValue);
20
21 String convertConnectivityToString(EDataType eDataType, Object instanceValue);
22}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactoryImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactoryImpl.java
deleted file mode 100644
index 4e2a695c..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesFactoryImpl.java
+++ /dev/null
@@ -1,74 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.recipe;
7
8import org.eclipse.emf.ecore.EClass;
9import org.eclipse.emf.ecore.EDataType;
10import org.eclipse.emf.ecore.EObject;
11import org.eclipse.emf.ecore.EPackage;
12import org.eclipse.emf.ecore.impl.EFactoryImpl;
13import org.eclipse.emf.ecore.plugin.EcorePlugin;
14import tools.refinery.store.query.literal.Connectivity;
15
16public class RefineryRecipesFactoryImpl extends EFactoryImpl implements RefineryRecipesFactory {
17 public static RefineryRecipesFactory init() {
18 try {
19 var factory = (RefineryRecipesFactory) EPackage.Registry.INSTANCE.getEFactory(
20 RefineryRecipesPackage.eNS_URI);
21 if (factory != null) {
22 return factory;
23 }
24 }
25 catch (Exception exception) {
26 EcorePlugin.INSTANCE.log(exception);
27 }
28 return new RefineryRecipesFactoryImpl();
29 }
30
31 @Override
32 public EObject create(EClass eClass) {
33 if (eClass.getClassifierID() == RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE) {
34 return createRepresentativeElectionRecipe();
35 } else {
36 throw new IllegalArgumentException("The class '%s' is not a valid classifier".formatted(eClass.getName()));
37 }
38 }
39
40 @Override
41 public Object createFromString(EDataType eDataType, String stringValue) {
42 if (eDataType.getClassifierID() == RefineryRecipesPackage.CONNECTIVITY) {
43 return createConnectivityFromString(eDataType, stringValue);
44 } else {
45 throw new IllegalArgumentException("The datatype '%s' is not a valid classifier"
46 .formatted(eDataType.getName()));
47 }
48 }
49
50 @Override
51 public String convertToString(EDataType eDataType, Object objectValue) {
52 if (eDataType.getClassifierID() == RefineryRecipesPackage.CONNECTIVITY) {
53 return convertConnectivityToString(eDataType, objectValue);
54 } else {
55 throw new IllegalArgumentException("The datatype '%s' is not a valid classifier"
56 .formatted(eDataType.getName()));
57 }
58 }
59
60 @Override
61 public RepresentativeElectionRecipe createRepresentativeElectionRecipe() {
62 return new RepresentativeElectionRecipeImpl();
63 }
64
65 @Override
66 public Connectivity createConnectivityFromString(EDataType eDataType, String initialValue) {
67 return (Connectivity) super.createFromString(eDataType, initialValue);
68 }
69
70 @Override
71 public String convertConnectivityToString(EDataType eDataType, Object instanceValue) {
72 return super.convertToString(eDataType, instanceValue);
73 }
74}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackage.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackage.java
deleted file mode 100644
index 6c933c45..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackage.java
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.recipe;
7
8import org.eclipse.emf.ecore.*;
9import org.eclipse.viatra.query.runtime.rete.recipes.RecipesPackage;
10
11// Naming and index computation follows EMF conventions.
12@SuppressWarnings({"squid:S100", "squid:S115", "PointlessArithmeticExpression"})
13public interface RefineryRecipesPackage extends EPackage {
14 String eNAME = "refineryReteRecipes";
15
16 String eNS_URI = "https://refinery.tools/emf/2021/RefineryReteRecipes";
17
18 String eNS_PREFIX = "refineryReteRecipes";
19
20 RefineryRecipesPackage eINSTANCE = RefineryRecipesPackageImpl.init();
21
22 int REPRESENTATIVE_ELECTION_RECIPE = 0;
23
24 int REPRESENTATIVE_ELECTION_RECIPE__CONNECTIVITY = RecipesPackage.ALPHA_RECIPE_FEATURE_COUNT + 0;
25
26 int REPRESENTATIVE_ELECTION_RECIPE_FEATURE_COUNT = RecipesPackage.ALPHA_RECIPE_FEATURE_COUNT + 1;
27
28 int REPRESENTATIVE_ELECTION_RECIPE__GET_ARITY = RecipesPackage.ALPHA_RECIPE_OPERATION_COUNT + 0;
29
30 int REPRESENTATIVE_ELECTION_RECIPE_OPERATION_COUNT = RecipesPackage.ALPHA_RECIPE_OPERATION_COUNT + 1;
31
32 int CONNECTIVITY = 1;
33
34 EClass getRepresentativeElectionRecipe();
35
36 EAttribute getRepresentativeElectionRecipe_Connectivity();
37
38 EOperation getRepresentativeElectionRecipe_GetArity();
39
40 EDataType getConnectivity();
41}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackageImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackageImpl.java
deleted file mode 100644
index d5073402..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RefineryRecipesPackageImpl.java
+++ /dev/null
@@ -1,96 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.recipe;
7
8import org.eclipse.emf.ecore.*;
9import org.eclipse.emf.ecore.impl.EPackageImpl;
10import org.eclipse.viatra.query.runtime.rete.recipes.RecipesPackage;
11import tools.refinery.store.query.literal.Connectivity;
12
13public class RefineryRecipesPackageImpl extends EPackageImpl implements RefineryRecipesPackage {
14 private static boolean isInstanceInitialized;
15 private boolean isCreated;
16 private boolean isInitialized;
17 private EClass representativeElectionRecipe;
18 private EDataType connectivity;
19
20 public static RefineryRecipesPackage init() {
21 if (isInstanceInitialized) {
22 return (RefineryRecipesPackage) Registry.INSTANCE.getEPackage(eNS_URI);
23 }
24 var thePackage = Registry.INSTANCE.get(eNS_URI) instanceof RefineryRecipesPackageImpl impl ? impl :
25 new RefineryRecipesPackageImpl();
26 isInstanceInitialized = true;
27 thePackage.createPackageContents();
28 thePackage.initializePackageContents();
29 thePackage.freeze();
30 Registry.INSTANCE.put(eNS_URI, thePackage);
31 return thePackage;
32 }
33
34 private RefineryRecipesPackageImpl() {
35 super(eNS_URI, RefineryRecipesFactory.eINSTANCE);
36 }
37
38 @Override
39 public EClass getRepresentativeElectionRecipe() {
40 return representativeElectionRecipe;
41 }
42
43 @Override
44 public EAttribute getRepresentativeElectionRecipe_Connectivity() {
45 return (EAttribute) representativeElectionRecipe.getEStructuralFeatures().get(0);
46 }
47
48 @Override
49 public EOperation getRepresentativeElectionRecipe_GetArity() {
50 return representativeElectionRecipe.getEOperations().get(0);
51 }
52
53 @Override
54 public EDataType getConnectivity() {
55 return connectivity;
56 }
57
58 public void createPackageContents() {
59 if (isCreated) {
60 return;
61 }
62 isCreated = true;
63
64 representativeElectionRecipe = createEClass(REPRESENTATIVE_ELECTION_RECIPE);
65 createEAttribute(representativeElectionRecipe, REPRESENTATIVE_ELECTION_RECIPE__CONNECTIVITY);
66 createEOperation(representativeElectionRecipe, REPRESENTATIVE_ELECTION_RECIPE__GET_ARITY);
67
68 connectivity = createEDataType(CONNECTIVITY);
69 }
70
71 public void initializePackageContents() {
72 if (isInitialized) {
73 return;
74 }
75 isInitialized = true;
76
77 setName(eNAME);
78 setNsPrefix(eNS_PREFIX);
79 setNsURI(eNS_URI);
80
81 representativeElectionRecipe.getESuperTypes().add(RecipesPackage.Literals.ALPHA_RECIPE);
82
83 initEClass(representativeElectionRecipe, RepresentativeElectionRecipe.class,
84 "RepresentativeElectionRecipe", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS);
85 initEAttribute(getRepresentativeElectionRecipe_Connectivity(), getConnectivity(), "connectivity", null, 0, 1,
86 RepresentativeElectionRecipe.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID,
87 IS_UNIQUE, !IS_DERIVED, IS_ORDERED);
88 initEOperation(getRepresentativeElectionRecipe_GetArity(), EcorePackage.Literals.EINT, "getArity", 0, 1,
89 !IS_UNIQUE, IS_ORDERED);
90
91 initEDataType(connectivity, Connectivity.class, "Connectivity", IS_SERIALIZABLE,
92 !IS_GENERATED_INSTANCE_CLASS);
93
94 createResource(eNS_URI);
95 }
96}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipe.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipe.java
deleted file mode 100644
index def825c2..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipe.java
+++ /dev/null
@@ -1,17 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.recipe;
7
8import org.eclipse.viatra.query.runtime.rete.recipes.AlphaRecipe;
9import tools.refinery.store.query.literal.Connectivity;
10
11public interface RepresentativeElectionRecipe extends AlphaRecipe {
12 Connectivity getConnectivity();
13
14 void setConnectivity(Connectivity connectivity);
15
16 int getArity();
17}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipeImpl.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipeImpl.java
deleted file mode 100644
index 959836d2..00000000
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/rete/recipe/RepresentativeElectionRecipeImpl.java
+++ /dev/null
@@ -1,105 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.query.viatra.internal.rete.recipe;
7
8import org.eclipse.emf.common.notify.Notification;
9import org.eclipse.emf.common.util.EList;
10import org.eclipse.emf.ecore.EClass;
11import org.eclipse.emf.ecore.impl.ENotificationImpl;
12import org.eclipse.viatra.query.runtime.rete.recipes.RecipesPackage;
13import org.eclipse.viatra.query.runtime.rete.recipes.ReteNodeRecipe;
14import org.eclipse.viatra.query.runtime.rete.recipes.impl.AlphaRecipeImpl;
15import tools.refinery.store.query.literal.Connectivity;
16
17import java.lang.reflect.InvocationTargetException;
18
19public class RepresentativeElectionRecipeImpl extends AlphaRecipeImpl implements RepresentativeElectionRecipe {
20 private Connectivity connectivity;
21
22 @Override
23 protected EClass eStaticClass() {
24 return RefineryRecipesPackage.eINSTANCE.getRepresentativeElectionRecipe();
25 }
26
27 @Override
28 public Connectivity getConnectivity() {
29 return connectivity;
30 }
31
32 @Override
33 public void setConnectivity(Connectivity newStrong) {
34 var oldConnectivity = connectivity;
35 connectivity = newStrong;
36 if (eNotificationRequired()) {
37 eNotify(new ENotificationImpl(this, Notification.SET,
38 RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE__CONNECTIVITY, oldConnectivity,
39 connectivity));
40 }
41 }
42
43 @Override
44 public int getArity() {
45 return 2;
46 }
47
48 @Override
49 public Object eGet(int featureID, boolean resolve, boolean coreType) {
50 if (featureID == RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE__CONNECTIVITY) {
51 return getConnectivity();
52 }
53 return super.eGet(featureID, resolve, coreType);
54 }
55
56 @Override
57 public void eSet(int featureID, Object newValue) {
58 if (featureID == RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE__CONNECTIVITY) {
59 setConnectivity((Connectivity) newValue);
60 } else {
61 super.eSet(featureID, newValue);
62 }
63 }
64
65 @Override
66 public void eUnset(int featureID) {
67 if (featureID == RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE__CONNECTIVITY) {
68 setConnectivity(null);
69 } else {
70 super.eUnset(featureID);
71 }
72 }
73
74 @Override
75 public boolean eIsSet(int featureID) {
76 if (featureID == RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE__CONNECTIVITY) {
77 return connectivity != null;
78 }
79 return super.eIsSet(featureID);
80 }
81
82 @Override
83 public int eDerivedOperationID(int baseOperationID, Class<?> baseClass) {
84 if (baseClass == ReteNodeRecipe.class && baseOperationID == RecipesPackage.RETE_NODE_RECIPE___GET_ARITY) {
85 return RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE__GET_ARITY;
86 }
87 return super.eDerivedOperationID(baseOperationID, baseClass);
88 }
89
90 @Override
91 public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
92 if (operationID == RefineryRecipesPackage.REPRESENTATIVE_ELECTION_RECIPE__GET_ARITY) {
93 return getArity();
94 }
95 return super.eInvoke(operationID, arguments);
96 }
97
98 @Override
99 public String toString() {
100 if (eIsProxy()) {
101 return super.toString();
102 }
103 return "%s (connectivity: %s)".formatted(super.toString(), connectivity);
104 }
105}
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/ModelUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/ModelUpdateListener.java
index 986bb0b1..e1bc9efc 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/ModelUpdateListener.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/ModelUpdateListener.java
@@ -5,9 +5,9 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.update; 6package tools.refinery.store.query.viatra.internal.update;
7 7
8import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 8import tools.refinery.viatra.runtime.matchers.context.IInputKey;
9import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; 9import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContextListener;
10import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; 10import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
11import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 11import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
12import tools.refinery.store.query.view.AnySymbolView; 12import tools.refinery.store.query.view.AnySymbolView;
13import tools.refinery.store.query.view.SymbolView; 13import tools.refinery.store.query.view.SymbolView;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/RelationViewFilter.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/RelationViewFilter.java
index efdbfcbe..73c4a3f9 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/RelationViewFilter.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/RelationViewFilter.java
@@ -5,10 +5,10 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.update; 6package tools.refinery.store.query.viatra.internal.update;
7 7
8import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 8import tools.refinery.viatra.runtime.matchers.context.IInputKey;
9import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; 9import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContextListener;
10import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; 10import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
11import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 11import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
12 12
13import java.util.Arrays; 13import java.util.Arrays;
14import java.util.Objects; 14import java.util.Objects;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/SymbolViewUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/SymbolViewUpdateListener.java
index f1a2ac7c..d0cdda72 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/SymbolViewUpdateListener.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/SymbolViewUpdateListener.java
@@ -5,10 +5,10 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.update; 6package tools.refinery.store.query.viatra.internal.update;
7 7
8import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 8import tools.refinery.viatra.runtime.matchers.context.IInputKey;
9import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContextListener; 9import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContextListener;
10import org.eclipse.viatra.query.runtime.matchers.tuple.ITuple; 10import tools.refinery.viatra.runtime.matchers.tuple.ITuple;
11import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 11import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
12import tools.refinery.store.model.Interpretation; 12import tools.refinery.store.model.Interpretation;
13import tools.refinery.store.model.InterpretationListener; 13import tools.refinery.store.model.InterpretationListener;
14import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 14import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingViewUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingViewUpdateListener.java
index 45d35571..9dc739f1 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingViewUpdateListener.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TupleChangingViewUpdateListener.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.update; 6package tools.refinery.store.query.viatra.internal.update;
7 7
8import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 8import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
9import tools.refinery.store.model.Interpretation; 9import tools.refinery.store.model.Interpretation;
10import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 10import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
11import tools.refinery.store.query.view.SymbolView; 11import tools.refinery.store.query.view.SymbolView;
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TuplePreservingViewUpdateListener.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TuplePreservingViewUpdateListener.java
index c18dbafb..7dbd50b3 100644
--- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TuplePreservingViewUpdateListener.java
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/update/TuplePreservingViewUpdateListener.java
@@ -5,7 +5,7 @@
5 */ 5 */
6package tools.refinery.store.query.viatra.internal.update; 6package tools.refinery.store.query.viatra.internal.update;
7 7
8import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 8import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
9import tools.refinery.store.model.Interpretation; 9import tools.refinery.store.model.Interpretation;
10import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl; 10import tools.refinery.store.query.viatra.internal.ViatraModelQueryAdapterImpl;
11import tools.refinery.store.query.view.TuplePreservingView; 11import tools.refinery.store.query.view.TuplePreservingView;