aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query-viatra/src
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-query-viatra/src')
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryBuilder.java14
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/ViatraModelQueryAdapterImpl.java6
-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.java10
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/Dnf2PQuery.java (renamed from subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java)86
-rw-r--r--subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java155
-rw-r--r--subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java8
7 files changed, 149 insertions, 146 deletions
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 efc6146c..24aa52e2 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
@@ -4,7 +4,7 @@ import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions;
4import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory; 4import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
5import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; 5import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
6import tools.refinery.store.model.ModelStore; 6import tools.refinery.store.model.ModelStore;
7import tools.refinery.store.query.DNF; 7import tools.refinery.store.query.Dnf;
8import tools.refinery.store.query.ModelQueryBuilder; 8import tools.refinery.store.query.ModelQueryBuilder;
9 9
10import java.util.Collection; 10import java.util.Collection;
@@ -23,25 +23,25 @@ public interface ViatraModelQueryBuilder extends ModelQueryBuilder {
23 ViatraModelQueryBuilder searchBackend(IQueryBackendFactory queryBackendFactory); 23 ViatraModelQueryBuilder searchBackend(IQueryBackendFactory queryBackendFactory);
24 24
25 @Override 25 @Override
26 default ViatraModelQueryBuilder queries(DNF... queries) { 26 default ViatraModelQueryBuilder queries(Dnf... queries) {
27 ModelQueryBuilder.super.queries(queries); 27 ModelQueryBuilder.super.queries(queries);
28 return this; 28 return this;
29 } 29 }
30 30
31 @Override 31 @Override
32 default ViatraModelQueryBuilder queries(Collection<DNF> queries) { 32 default ViatraModelQueryBuilder queries(Collection<Dnf> queries) {
33 ModelQueryBuilder.super.queries(queries); 33 ModelQueryBuilder.super.queries(queries);
34 return this; 34 return this;
35 } 35 }
36 36
37 @Override 37 @Override
38 ViatraModelQueryBuilder query(DNF query); 38 ViatraModelQueryBuilder query(Dnf query);
39 39
40 ViatraModelQueryBuilder query(DNF query, QueryEvaluationHint queryEvaluationHint); 40 ViatraModelQueryBuilder query(Dnf query, QueryEvaluationHint queryEvaluationHint);
41 41
42 ViatraModelQueryBuilder computeHint(Function<DNF, QueryEvaluationHint> computeHint); 42 ViatraModelQueryBuilder computeHint(Function<Dnf, QueryEvaluationHint> computeHint);
43 43
44 ViatraModelQueryBuilder hint(DNF dnf, QueryEvaluationHint queryEvaluationHint); 44 ViatraModelQueryBuilder hint(Dnf dnf, QueryEvaluationHint queryEvaluationHint);
45 45
46 @Override 46 @Override
47 ViatraModelQueryStoreAdapter createStoreAdapter(ModelStore store); 47 ViatraModelQueryStoreAdapter createStoreAdapter(ModelStore store);
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 039f46fa..e5d8e2f6 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
@@ -7,7 +7,7 @@ import org.eclipse.viatra.query.runtime.internal.apiimpl.ViatraQueryEngineImpl;
7import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend; 7import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackend;
8import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory; 8import org.eclipse.viatra.query.runtime.matchers.backend.IQueryBackendFactory;
9import tools.refinery.store.model.Model; 9import tools.refinery.store.model.Model;
10import tools.refinery.store.query.DNF; 10import tools.refinery.store.query.Dnf;
11import tools.refinery.store.query.ResultSet; 11import tools.refinery.store.query.ResultSet;
12import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; 12import tools.refinery.store.query.viatra.ViatraModelQueryAdapter;
13 13
@@ -27,7 +27,7 @@ public class ViatraModelQueryAdapterImpl implements ViatraModelQueryAdapter {
27 private final ViatraQueryEngineImpl queryEngine; 27 private final ViatraQueryEngineImpl queryEngine;
28 private final MethodHandle setUpdatePropagationDelayedHandle; 28 private final MethodHandle setUpdatePropagationDelayedHandle;
29 private final MethodHandle getQueryBackendsHandle; 29 private final MethodHandle getQueryBackendsHandle;
30 private final Map<DNF, ResultSet> resultSets; 30 private final Map<Dnf, ResultSet> resultSets;
31 private boolean pendingChanges; 31 private boolean pendingChanges;
32 32
33 ViatraModelQueryAdapterImpl(Model model, ViatraModelQueryStoreAdapterImpl storeAdapter) { 33 ViatraModelQueryAdapterImpl(Model model, ViatraModelQueryStoreAdapterImpl storeAdapter) {
@@ -95,7 +95,7 @@ public class ViatraModelQueryAdapterImpl implements ViatraModelQueryAdapter {
95 } 95 }
96 96
97 @Override 97 @Override
98 public ResultSet getResultSet(DNF query) { 98 public ResultSet getResultSet(Dnf query) {
99 var resultSet = resultSets.get(query); 99 var resultSet = resultSets.get(query);
100 if (resultSet == null) { 100 if (resultSet == null) {
101 throw new IllegalArgumentException("No matcher for query %s in model".formatted(query.name())); 101 throw new IllegalArgumentException("No matcher for query %s in model".formatted(query.name()));
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 9f1e55b1..af20033a 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
@@ -9,9 +9,9 @@ import org.eclipse.viatra.query.runtime.rete.matcher.ReteBackendFactory;
9import tools.refinery.store.adapter.AbstractModelAdapterBuilder; 9import tools.refinery.store.adapter.AbstractModelAdapterBuilder;
10import tools.refinery.store.model.ModelStore; 10import tools.refinery.store.model.ModelStore;
11import tools.refinery.store.model.ModelStoreBuilder; 11import tools.refinery.store.model.ModelStoreBuilder;
12import tools.refinery.store.query.DNF; 12import tools.refinery.store.query.Dnf;
13import tools.refinery.store.query.viatra.ViatraModelQueryBuilder; 13import tools.refinery.store.query.viatra.ViatraModelQueryBuilder;
14import tools.refinery.store.query.viatra.internal.pquery.DNF2PQuery; 14import tools.refinery.store.query.viatra.internal.pquery.Dnf2PQuery;
15import tools.refinery.store.query.viatra.internal.pquery.RawPatternMatcher; 15import tools.refinery.store.query.viatra.internal.pquery.RawPatternMatcher;
16 16
17import java.util.Collections; 17import java.util.Collections;
@@ -21,8 +21,8 @@ import java.util.function.Function;
21 21
22public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder implements ViatraModelQueryBuilder { 22public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder implements ViatraModelQueryBuilder {
23 private ViatraQueryEngineOptions.Builder engineOptionsBuilder; 23 private ViatraQueryEngineOptions.Builder engineOptionsBuilder;
24 private final DNF2PQuery dnf2PQuery = new DNF2PQuery(); 24 private final Dnf2PQuery dnf2PQuery = new Dnf2PQuery();
25 private final Map<DNF, IQuerySpecification<RawPatternMatcher>> querySpecifications = new LinkedHashMap<>(); 25 private final Map<Dnf, IQuerySpecification<RawPatternMatcher>> querySpecifications = new LinkedHashMap<>();
26 26
27 public ViatraModelQueryBuilderImpl(ModelStoreBuilder storeBuilder) { 27 public ViatraModelQueryBuilderImpl(ModelStoreBuilder storeBuilder) {
28 super(storeBuilder); 28 super(storeBuilder);
@@ -63,7 +63,7 @@ public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder imp
63 } 63 }
64 64
65 @Override 65 @Override
66 public ViatraModelQueryBuilder query(DNF query) { 66 public ViatraModelQueryBuilder query(Dnf query) {
67 if (querySpecifications.containsKey(query)) { 67 if (querySpecifications.containsKey(query)) {
68 throw new IllegalArgumentException("%s was already added to the query engine".formatted(query.name())); 68 throw new IllegalArgumentException("%s was already added to the query engine".formatted(query.name()));
69 } 69 }
@@ -73,20 +73,20 @@ public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder imp
73 } 73 }
74 74
75 @Override 75 @Override
76 public ViatraModelQueryBuilder query(DNF query, QueryEvaluationHint queryEvaluationHint) { 76 public ViatraModelQueryBuilder query(Dnf query, QueryEvaluationHint queryEvaluationHint) {
77 query(query); 77 query(query);
78 hint(query, queryEvaluationHint); 78 hint(query, queryEvaluationHint);
79 return this; 79 return this;
80 } 80 }
81 81
82 @Override 82 @Override
83 public ViatraModelQueryBuilder computeHint(Function<DNF, QueryEvaluationHint> computeHint) { 83 public ViatraModelQueryBuilder computeHint(Function<Dnf, QueryEvaluationHint> computeHint) {
84 dnf2PQuery.setComputeHint(computeHint); 84 dnf2PQuery.setComputeHint(computeHint);
85 return this; 85 return this;
86 } 86 }
87 87
88 @Override 88 @Override
89 public ViatraModelQueryBuilder hint(DNF dnf, QueryEvaluationHint queryEvaluationHint) { 89 public ViatraModelQueryBuilder hint(Dnf dnf, QueryEvaluationHint queryEvaluationHint) {
90 var pQuery = dnf2PQuery.getAlreadyTranslated(dnf); 90 var pQuery = dnf2PQuery.getAlreadyTranslated(dnf);
91 if (pQuery == null) { 91 if (pQuery == null) {
92 throw new IllegalArgumentException( 92 throw new IllegalArgumentException(
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 394e407e..8323118b 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,7 +5,7 @@ import org.eclipse.viatra.query.runtime.api.ViatraQueryEngineOptions;
5import org.eclipse.viatra.query.runtime.matchers.context.IInputKey; 5import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
6import tools.refinery.store.model.Model; 6import tools.refinery.store.model.Model;
7import tools.refinery.store.model.ModelStore; 7import tools.refinery.store.model.ModelStore;
8import tools.refinery.store.query.DNF; 8import tools.refinery.store.query.Dnf;
9import tools.refinery.store.query.viatra.ViatraModelQueryStoreAdapter; 9import tools.refinery.store.query.viatra.ViatraModelQueryStoreAdapter;
10import tools.refinery.store.query.viatra.internal.pquery.RawPatternMatcher; 10import tools.refinery.store.query.viatra.internal.pquery.RawPatternMatcher;
11import tools.refinery.store.query.view.AnyRelationView; 11import tools.refinery.store.query.view.AnyRelationView;
@@ -17,11 +17,11 @@ public class ViatraModelQueryStoreAdapterImpl implements ViatraModelQueryStoreAd
17 private final ModelStore store; 17 private final ModelStore store;
18 private final ViatraQueryEngineOptions engineOptions; 18 private final ViatraQueryEngineOptions engineOptions;
19 private final Map<AnyRelationView, IInputKey> inputKeys; 19 private final Map<AnyRelationView, IInputKey> inputKeys;
20 private final Map<DNF, IQuerySpecification<RawPatternMatcher>> querySpecifications; 20 private final Map<Dnf, IQuerySpecification<RawPatternMatcher>> querySpecifications;
21 21
22 ViatraModelQueryStoreAdapterImpl(ModelStore store, ViatraQueryEngineOptions engineOptions, 22 ViatraModelQueryStoreAdapterImpl(ModelStore store, ViatraQueryEngineOptions engineOptions,
23 Map<AnyRelationView, IInputKey> inputKeys, 23 Map<AnyRelationView, IInputKey> inputKeys,
24 Map<DNF, IQuerySpecification<RawPatternMatcher>> querySpecifications) { 24 Map<Dnf, IQuerySpecification<RawPatternMatcher>> querySpecifications) {
25 this.store = store; 25 this.store = store;
26 this.engineOptions = engineOptions; 26 this.engineOptions = engineOptions;
27 this.inputKeys = inputKeys; 27 this.inputKeys = inputKeys;
@@ -42,11 +42,11 @@ public class ViatraModelQueryStoreAdapterImpl implements ViatraModelQueryStoreAd
42 } 42 }
43 43
44 @Override 44 @Override
45 public Collection<DNF> getQueries() { 45 public Collection<Dnf> getQueries() {
46 return querySpecifications.keySet(); 46 return querySpecifications.keySet();
47 } 47 }
48 48
49 Map<DNF, IQuerySpecification<RawPatternMatcher>> getQuerySpecifications() { 49 Map<Dnf, IQuerySpecification<RawPatternMatcher>> getQuerySpecifications() {
50 return querySpecifications; 50 return querySpecifications;
51 } 51 }
52 52
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 60f1bcae..02e26bde 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
@@ -17,38 +17,38 @@ import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
17import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; 17import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
18import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; 18import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
19import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; 19import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
20import tools.refinery.store.query.DNF; 20import tools.refinery.store.query.Dnf;
21import tools.refinery.store.query.DNFAnd; 21import tools.refinery.store.query.DnfClause;
22import tools.refinery.store.query.DNFUtils; 22import tools.refinery.store.query.DnfUtils;
23import tools.refinery.store.query.Variable; 23import tools.refinery.store.query.Variable;
24import tools.refinery.store.query.atom.*; 24import tools.refinery.store.query.literal.*;
25import tools.refinery.store.query.view.AnyRelationView; 25import tools.refinery.store.query.view.AnyRelationView;
26 26
27import java.util.*; 27import java.util.*;
28import java.util.function.Function; 28import java.util.function.Function;
29import java.util.stream.Collectors; 29import java.util.stream.Collectors;
30 30
31public class DNF2PQuery { 31public class Dnf2PQuery {
32 private static final Object P_CONSTRAINT_LOCK = new Object(); 32 private static final Object P_CONSTRAINT_LOCK = new Object();
33 33
34 private final Set<DNF> translating = new LinkedHashSet<>(); 34 private final Set<Dnf> translating = new LinkedHashSet<>();
35 35
36 private final Map<DNF, RawPQuery> dnf2PQueryMap = new HashMap<>(); 36 private final Map<Dnf, RawPQuery> dnf2PQueryMap = new HashMap<>();
37 37
38 private final Map<AnyRelationView, RelationViewWrapper> view2WrapperMap = new LinkedHashMap<>(); 38 private final Map<AnyRelationView, RelationViewWrapper> view2WrapperMap = new LinkedHashMap<>();
39 39
40 private final Map<AnyRelationView, RawPQuery> view2EmbeddedMap = new HashMap<>(); 40 private final Map<AnyRelationView, RawPQuery> view2EmbeddedMap = new HashMap<>();
41 41
42 private Function<DNF, QueryEvaluationHint> computeHint = dnf -> new QueryEvaluationHint(null, 42 private Function<Dnf, QueryEvaluationHint> computeHint = dnf -> new QueryEvaluationHint(null,
43 QueryEvaluationHint.BackendRequirement.UNSPECIFIED); 43 QueryEvaluationHint.BackendRequirement.UNSPECIFIED);
44 44
45 public void setComputeHint(Function<DNF, QueryEvaluationHint> computeHint) { 45 public void setComputeHint(Function<Dnf, QueryEvaluationHint> computeHint) {
46 this.computeHint = computeHint; 46 this.computeHint = computeHint;
47 } 47 }
48 48
49 public RawPQuery translate(DNF dnfQuery) { 49 public RawPQuery translate(Dnf dnfQuery) {
50 if (translating.contains(dnfQuery)) { 50 if (translating.contains(dnfQuery)) {
51 var path = translating.stream().map(DNF::name).collect(Collectors.joining(" -> ")); 51 var path = translating.stream().map(Dnf::name).collect(Collectors.joining(" -> "));
52 throw new IllegalStateException("Circular reference %s -> %s detected".formatted(path, 52 throw new IllegalStateException("Circular reference %s -> %s detected".formatted(path,
53 dnfQuery.name())); 53 dnfQuery.name()));
54 } 54 }
@@ -71,11 +71,11 @@ public class DNF2PQuery {
71 return Collections.unmodifiableMap(view2WrapperMap); 71 return Collections.unmodifiableMap(view2WrapperMap);
72 } 72 }
73 73
74 public RawPQuery getAlreadyTranslated(DNF dnfQuery) { 74 public RawPQuery getAlreadyTranslated(Dnf dnfQuery) {
75 return dnf2PQueryMap.get(dnfQuery); 75 return dnf2PQueryMap.get(dnfQuery);
76 } 76 }
77 77
78 private RawPQuery doTranslate(DNF dnfQuery) { 78 private RawPQuery doTranslate(Dnf dnfQuery) {
79 var pQuery = new RawPQuery(dnfQuery.getUniqueName()); 79 var pQuery = new RawPQuery(dnfQuery.getUniqueName());
80 pQuery.setEvaluationHints(computeHint.apply(dnfQuery)); 80 pQuery.setEvaluationHints(computeHint.apply(dnfQuery));
81 81
@@ -103,9 +103,9 @@ public class DNF2PQuery {
103 103
104 // The constructor of {@link org.eclipse.viatra.query.runtime.matchers.psystem.BasePConstraint} mutates 104 // The constructor of {@link org.eclipse.viatra.query.runtime.matchers.psystem.BasePConstraint} mutates
105 // global static state (<code>nextID</code>) without locking. Therefore, we need to synchronize before creating 105 // global static state (<code>nextID</code>) without locking. Therefore, we need to synchronize before creating
106 // any query constraints to avoid a data race. 106 // any query literals to avoid a data race.
107 synchronized (P_CONSTRAINT_LOCK) { 107 synchronized (P_CONSTRAINT_LOCK) {
108 for (DNFAnd clause : dnfQuery.getClauses()) { 108 for (DnfClause clause : dnfQuery.getClauses()) {
109 PBody body = new PBody(pQuery); 109 PBody body = new PBody(pQuery);
110 List<ExportedParameter> symbolicParameters = new ArrayList<>(); 110 List<ExportedParameter> symbolicParameters = new ArrayList<>();
111 for (var param : dnfQuery.getParameters()) { 111 for (var param : dnfQuery.getParameters()) {
@@ -114,8 +114,8 @@ public class DNF2PQuery {
114 } 114 }
115 body.setSymbolicParameters(symbolicParameters); 115 body.setSymbolicParameters(symbolicParameters);
116 pQuery.addBody(body); 116 pQuery.addBody(body);
117 for (DNFAtom constraint : clause.constraints()) { 117 for (Literal literal : clause.literals()) {
118 translateDNFAtom(constraint, body); 118 translateLiteral(literal, body);
119 } 119 }
120 } 120 }
121 } 121 }
@@ -123,34 +123,34 @@ public class DNF2PQuery {
123 return pQuery; 123 return pQuery;
124 } 124 }
125 125
126 private void translateDNFAtom(DNFAtom constraint, PBody body) { 126 private void translateLiteral(Literal literal, PBody body) {
127 if (constraint instanceof EquivalenceAtom equivalenceAtom) { 127 if (literal instanceof EquivalenceLiteral equivalenceLiteral) {
128 translateEquivalenceAtom(equivalenceAtom, body); 128 translateEquivalenceLiteral(equivalenceLiteral, body);
129 } else if (constraint instanceof RelationViewAtom relationViewAtom) { 129 } else if (literal instanceof RelationViewLiteral relationViewLiteral) {
130 translateRelationViewAtom(relationViewAtom, body); 130 translateRelationViewLiteral(relationViewLiteral, body);
131 } else if (constraint instanceof DNFCallAtom callAtom) { 131 } else if (literal instanceof DnfCallLiteral dnfCallLiteral) {
132 translateCallAtom(callAtom, body); 132 translateDnfCallLiteral(dnfCallLiteral, body);
133 } else if (constraint instanceof ConstantAtom constantAtom) { 133 } else if (literal instanceof ConstantLiteral constantLiteral) {
134 translateConstantAtom(constantAtom, body); 134 translateConstantLiteral(constantLiteral, body);
135 } else { 135 } else {
136 throw new IllegalArgumentException("Unknown constraint: " + constraint.toString()); 136 throw new IllegalArgumentException("Unknown literal: " + literal.toString());
137 } 137 }
138 } 138 }
139 139
140 private void translateEquivalenceAtom(EquivalenceAtom equivalence, PBody body) { 140 private void translateEquivalenceLiteral(EquivalenceLiteral equivalenceLiteral, PBody body) {
141 PVariable varSource = body.getOrCreateVariableByName(equivalence.left().getUniqueName()); 141 PVariable varSource = body.getOrCreateVariableByName(equivalenceLiteral.left().getUniqueName());
142 PVariable varTarget = body.getOrCreateVariableByName(equivalence.right().getUniqueName()); 142 PVariable varTarget = body.getOrCreateVariableByName(equivalenceLiteral.right().getUniqueName());
143 if (equivalence.positive()) { 143 if (equivalenceLiteral.positive()) {
144 new Equality(body, varSource, varTarget); 144 new Equality(body, varSource, varTarget);
145 } else { 145 } else {
146 new Inequality(body, varSource, varTarget); 146 new Inequality(body, varSource, varTarget);
147 } 147 }
148 } 148 }
149 149
150 private void translateRelationViewAtom(RelationViewAtom relationViewAtom, PBody body) { 150 private void translateRelationViewLiteral(RelationViewLiteral relationViewLiteral, PBody body) {
151 var substitution = translateSubstitution(relationViewAtom.getSubstitution(), body); 151 var substitution = translateSubstitution(relationViewLiteral.getSubstitution(), body);
152 var polarity = relationViewAtom.getPolarity(); 152 var polarity = relationViewLiteral.getPolarity();
153 var relationView = relationViewAtom.getTarget(); 153 var relationView = relationViewLiteral.getTarget();
154 if (polarity == CallPolarity.POSITIVE) { 154 if (polarity == CallPolarity.POSITIVE) {
155 new TypeConstraint(body, substitution, wrapView(relationView)); 155 new TypeConstraint(body, substitution, wrapView(relationView));
156 } else { 156 } else {
@@ -178,7 +178,7 @@ public class DNF2PQuery {
178 } 178 }
179 179
180 private RawPQuery doTranslateEmbeddedRelationViewPQuery(AnyRelationView relationView) { 180 private RawPQuery doTranslateEmbeddedRelationViewPQuery(AnyRelationView relationView) {
181 var embeddedPQuery = new RawPQuery(DNFUtils.generateUniqueName(relationView.name()), PVisibility.EMBEDDED); 181 var embeddedPQuery = new RawPQuery(DnfUtils.generateUniqueName(relationView.name()), PVisibility.EMBEDDED);
182 var body = new PBody(embeddedPQuery); 182 var body = new PBody(embeddedPQuery);
183 int arity = relationView.arity(); 183 int arity = relationView.arity();
184 var parameters = new ArrayList<PParameter>(arity); 184 var parameters = new ArrayList<PParameter>(arity);
@@ -204,10 +204,10 @@ public class DNF2PQuery {
204 return view2WrapperMap.computeIfAbsent(relationView, RelationViewWrapper::new); 204 return view2WrapperMap.computeIfAbsent(relationView, RelationViewWrapper::new);
205 } 205 }
206 206
207 private void translateCallAtom(DNFCallAtom callAtom, PBody body) { 207 private void translateDnfCallLiteral(DnfCallLiteral dnfCallLiteral, PBody body) {
208 var variablesTuple = translateSubstitution(callAtom.getSubstitution(), body); 208 var variablesTuple = translateSubstitution(dnfCallLiteral.getSubstitution(), body);
209 var translatedReferred = translate(callAtom.getTarget()); 209 var translatedReferred = translate(dnfCallLiteral.getTarget());
210 var polarity = callAtom.getPolarity(); 210 var polarity = dnfCallLiteral.getPolarity();
211 switch (polarity) { 211 switch (polarity) {
212 case POSITIVE -> new PositivePatternCall(body, variablesTuple, translatedReferred); 212 case POSITIVE -> new PositivePatternCall(body, variablesTuple, translatedReferred);
213 case TRANSITIVE -> new BinaryTransitiveClosure(body, variablesTuple, translatedReferred); 213 case TRANSITIVE -> new BinaryTransitiveClosure(body, variablesTuple, translatedReferred);
@@ -216,8 +216,8 @@ public class DNF2PQuery {
216 } 216 }
217 } 217 }
218 218
219 private void translateConstantAtom(ConstantAtom constantAtom, PBody body) { 219 private void translateConstantLiteral(ConstantLiteral constantLiteral, PBody body) {
220 var variable = body.getOrCreateVariableByName(constantAtom.variable().getUniqueName()); 220 var variable = body.getOrCreateVariableByName(constantLiteral.variable().getUniqueName());
221 new ConstantValue(body, variable, constantAtom.nodeId()); 221 new ConstantValue(body, variable, constantLiteral.nodeId());
222 } 222 }
223} 223}
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java
index 6a37b54a..471fdfc9 100644
--- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java
+++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java
@@ -2,10 +2,13 @@ package tools.refinery.store.query.viatra;
2 2
3import org.junit.jupiter.api.Test; 3import org.junit.jupiter.api.Test;
4import tools.refinery.store.model.ModelStore; 4import tools.refinery.store.model.ModelStore;
5import tools.refinery.store.query.DNF; 5import tools.refinery.store.query.Dnf;
6import tools.refinery.store.query.ModelQuery; 6import tools.refinery.store.query.ModelQuery;
7import tools.refinery.store.query.Variable; 7import tools.refinery.store.query.Variable;
8import tools.refinery.store.query.atom.*; 8import tools.refinery.store.query.literal.CallPolarity;
9import tools.refinery.store.query.literal.DnfCallLiteral;
10import tools.refinery.store.query.literal.EquivalenceLiteral;
11import tools.refinery.store.query.literal.RelationViewLiteral;
9import tools.refinery.store.query.view.FilteredRelationView; 12import tools.refinery.store.query.view.FilteredRelationView;
10import tools.refinery.store.query.view.KeyOnlyRelationView; 13import tools.refinery.store.query.view.KeyOnlyRelationView;
11import tools.refinery.store.representation.Symbol; 14import tools.refinery.store.representation.Symbol;
@@ -27,9 +30,9 @@ class QueryTest {
27 var personView = new KeyOnlyRelationView<>(person); 30 var personView = new KeyOnlyRelationView<>(person);
28 31
29 var p1 = new Variable("p1"); 32 var p1 = new Variable("p1");
30 var predicate = DNF.builder("TypeConstraint") 33 var predicate = Dnf.builder("TypeConstraint")
31 .parameters(p1) 34 .parameters(p1)
32 .clause(new RelationViewAtom(personView, p1)) 35 .clause(new RelationViewLiteral(personView, p1))
33 .build(); 36 .build();
34 37
35 var store = ModelStore.builder() 38 var store = ModelStore.builder()
@@ -64,12 +67,12 @@ class QueryTest {
64 67
65 var p1 = new Variable("p1"); 68 var p1 = new Variable("p1");
66 var p2 = new Variable("p2"); 69 var p2 = new Variable("p2");
67 var predicate = DNF.builder("RelationConstraint") 70 var predicate = Dnf.builder("RelationConstraint")
68 .parameters(p1, p2) 71 .parameters(p1, p2)
69 .clause( 72 .clause(
70 new RelationViewAtom(personView, p1), 73 new RelationViewLiteral(personView, p1),
71 new RelationViewAtom(personView, p2), 74 new RelationViewLiteral(personView, p2),
72 new RelationViewAtom(friendMustView, p1, p2) 75 new RelationViewLiteral(friendMustView, p1, p2)
73 ) 76 )
74 .build(); 77 .build();
75 78
@@ -111,13 +114,13 @@ class QueryTest {
111 114
112 var p1 = new Variable("p1"); 115 var p1 = new Variable("p1");
113 var p2 = new Variable("p2"); 116 var p2 = new Variable("p2");
114 var predicate = DNF.builder("RelationConstraint") 117 var predicate = Dnf.builder("RelationConstraint")
115 .parameters(p1, p2) 118 .parameters(p1, p2)
116 .clause( 119 .clause(
117 new RelationViewAtom(personView, p1), 120 new RelationViewLiteral(personView, p1),
118 new RelationViewAtom(personView, p2), 121 new RelationViewLiteral(personView, p2),
119 new RelationViewAtom(friendMustView, p1, p2), 122 new RelationViewLiteral(friendMustView, p1, p2),
120 new RelationViewAtom(friendMustView, p2, p1) 123 new RelationViewLiteral(friendMustView, p2, p1)
121 ) 124 )
122 .build(); 125 .build();
123 126
@@ -166,12 +169,12 @@ class QueryTest {
166 169
167 var p1 = new Variable("p1"); 170 var p1 = new Variable("p1");
168 var p2 = new Variable("p2"); 171 var p2 = new Variable("p2");
169 var predicate = DNF.builder("RelationConstraint") 172 var predicate = Dnf.builder("RelationConstraint")
170 .parameters(p1) 173 .parameters(p1)
171 .clause( 174 .clause(
172 new RelationViewAtom(personView, p1), 175 new RelationViewLiteral(personView, p1),
173 new RelationViewAtom(personView, p2), 176 new RelationViewLiteral(personView, p2),
174 new RelationViewAtom(friendMustView, p1, p2) 177 new RelationViewLiteral(friendMustView, p1, p2)
175 ) 178 )
176 .build(); 179 .build();
177 180
@@ -213,17 +216,17 @@ class QueryTest {
213 216
214 var p1 = new Variable("p1"); 217 var p1 = new Variable("p1");
215 var p2 = new Variable("p2"); 218 var p2 = new Variable("p2");
216 var predicate = DNF.builder("Or") 219 var predicate = Dnf.builder("Or")
217 .parameters(p1, p2) 220 .parameters(p1, p2)
218 .clause( 221 .clause(
219 new RelationViewAtom(personView, p1), 222 new RelationViewLiteral(personView, p1),
220 new RelationViewAtom(personView, p2), 223 new RelationViewLiteral(personView, p2),
221 new RelationViewAtom(friendMustView, p1, p2) 224 new RelationViewLiteral(friendMustView, p1, p2)
222 ) 225 )
223 .clause( 226 .clause(
224 new RelationViewAtom(animalView, p1), 227 new RelationViewLiteral(animalView, p1),
225 new RelationViewAtom(animalView, p2), 228 new RelationViewLiteral(animalView, p2),
226 new RelationViewAtom(friendMustView, p1, p2) 229 new RelationViewLiteral(friendMustView, p1, p2)
227 ) 230 )
228 .build(); 231 .build();
229 232
@@ -263,12 +266,12 @@ class QueryTest {
263 266
264 var p1 = new Variable("p1"); 267 var p1 = new Variable("p1");
265 var p2 = new Variable("p2"); 268 var p2 = new Variable("p2");
266 var predicate = DNF.builder("Equality") 269 var predicate = Dnf.builder("Equality")
267 .parameters(p1, p2) 270 .parameters(p1, p2)
268 .clause( 271 .clause(
269 new RelationViewAtom(personView, p1), 272 new RelationViewLiteral(personView, p1),
270 new RelationViewAtom(personView, p2), 273 new RelationViewLiteral(personView, p2),
271 new EquivalenceAtom(p1, p2) 274 new EquivalenceLiteral(p1, p2)
272 ) 275 )
273 .build(); 276 .build();
274 277
@@ -302,14 +305,14 @@ class QueryTest {
302 var p1 = new Variable("p1"); 305 var p1 = new Variable("p1");
303 var p2 = new Variable("p2"); 306 var p2 = new Variable("p2");
304 var p3 = new Variable("p3"); 307 var p3 = new Variable("p3");
305 var predicate = DNF.builder("Inequality") 308 var predicate = Dnf.builder("Inequality")
306 .parameters(p1, p2, p3) 309 .parameters(p1, p2, p3)
307 .clause( 310 .clause(
308 new RelationViewAtom(personView, p1), 311 new RelationViewLiteral(personView, p1),
309 new RelationViewAtom(personView, p2), 312 new RelationViewLiteral(personView, p2),
310 new RelationViewAtom(friendMustView, p1, p3), 313 new RelationViewLiteral(friendMustView, p1, p3),
311 new RelationViewAtom(friendMustView, p2, p3), 314 new RelationViewLiteral(friendMustView, p2, p3),
312 new EquivalenceAtom(false, p1, p2) 315 new EquivalenceLiteral(false, p1, p2)
313 ) 316 )
314 .build(); 317 .build();
315 318
@@ -346,23 +349,23 @@ class QueryTest {
346 349
347 var p1 = new Variable("p1"); 350 var p1 = new Variable("p1");
348 var p2 = new Variable("p2"); 351 var p2 = new Variable("p2");
349 var friendPredicate = DNF.builder("RelationConstraint") 352 var friendPredicate = Dnf.builder("RelationConstraint")
350 .parameters(p1, p2) 353 .parameters(p1, p2)
351 .clause( 354 .clause(
352 new RelationViewAtom(personView, p1), 355 new RelationViewLiteral(personView, p1),
353 new RelationViewAtom(personView, p2), 356 new RelationViewLiteral(personView, p2),
354 new RelationViewAtom(friendMustView, p1, p2) 357 new RelationViewLiteral(friendMustView, p1, p2)
355 ) 358 )
356 .build(); 359 .build();
357 360
358 var p3 = new Variable("p3"); 361 var p3 = new Variable("p3");
359 var p4 = new Variable("p4"); 362 var p4 = new Variable("p4");
360 var predicate = DNF.builder("PositivePatternCall") 363 var predicate = Dnf.builder("PositivePatternCall")
361 .parameters(p3, p4) 364 .parameters(p3, p4)
362 .clause( 365 .clause(
363 new RelationViewAtom(personView, p3), 366 new RelationViewLiteral(personView, p3),
364 new RelationViewAtom(personView, p4), 367 new RelationViewLiteral(personView, p4),
365 new DNFCallAtom(friendPredicate, p3, p4) 368 new DnfCallLiteral(friendPredicate, p3, p4)
366 ) 369 )
367 .build(); 370 .build();
368 371
@@ -399,12 +402,12 @@ class QueryTest {
399 402
400 var p1 = new Variable("p1"); 403 var p1 = new Variable("p1");
401 var p2 = new Variable("p2"); 404 var p2 = new Variable("p2");
402 var predicate = DNF.builder("NegativePatternCall") 405 var predicate = Dnf.builder("NegativePatternCall")
403 .parameters(p1, p2) 406 .parameters(p1, p2)
404 .clause( 407 .clause(
405 new RelationViewAtom(personView, p1), 408 new RelationViewLiteral(personView, p1),
406 new RelationViewAtom(personView, p2), 409 new RelationViewLiteral(personView, p2),
407 new RelationViewAtom(false, friendMustView, p1, p2) 410 new RelationViewLiteral(false, friendMustView, p1, p2)
408 ) 411 )
409 .build(); 412 .build();
410 413
@@ -441,23 +444,23 @@ class QueryTest {
441 444
442 var p1 = new Variable("p1"); 445 var p1 = new Variable("p1");
443 var p2 = new Variable("p2"); 446 var p2 = new Variable("p2");
444 var friendPredicate = DNF.builder("RelationConstraint") 447 var friendPredicate = Dnf.builder("RelationConstraint")
445 .parameters(p1, p2) 448 .parameters(p1, p2)
446 .clause( 449 .clause(
447 new RelationViewAtom(personView, p1), 450 new RelationViewLiteral(personView, p1),
448 new RelationViewAtom(personView, p2), 451 new RelationViewLiteral(personView, p2),
449 new RelationViewAtom(friendMustView, p1, p2) 452 new RelationViewLiteral(friendMustView, p1, p2)
450 ) 453 )
451 .build(); 454 .build();
452 455
453 var p3 = new Variable("p3"); 456 var p3 = new Variable("p3");
454 var p4 = new Variable("p4"); 457 var p4 = new Variable("p4");
455 var predicate = DNF.builder("NegativePatternCall") 458 var predicate = Dnf.builder("NegativePatternCall")
456 .parameters(p3, p4) 459 .parameters(p3, p4)
457 .clause( 460 .clause(
458 new RelationViewAtom(personView, p3), 461 new RelationViewLiteral(personView, p3),
459 new RelationViewAtom(personView, p4), 462 new RelationViewLiteral(personView, p4),
460 new DNFCallAtom(false, friendPredicate, p3, p4) 463 new DnfCallLiteral(false, friendPredicate, p3, p4)
461 ) 464 )
462 .build(); 465 .build();
463 466
@@ -495,11 +498,11 @@ class QueryTest {
495 var p1 = new Variable("p1"); 498 var p1 = new Variable("p1");
496 var p2 = new Variable("p2"); 499 var p2 = new Variable("p2");
497 500
498 var predicate = DNF.builder("Count") 501 var predicate = Dnf.builder("Count")
499 .parameters(p1) 502 .parameters(p1)
500 .clause( 503 .clause(
501 new RelationViewAtom(personView, p1), 504 new RelationViewLiteral(personView, p1),
502 new RelationViewAtom(false, friendMustView, p1, p2) 505 new RelationViewLiteral(false, friendMustView, p1, p2)
503 ) 506 )
504 .build(); 507 .build();
505 508
@@ -536,20 +539,20 @@ class QueryTest {
536 var p1 = new Variable("p1"); 539 var p1 = new Variable("p1");
537 var p2 = new Variable("p2"); 540 var p2 = new Variable("p2");
538 541
539 var called = DNF.builder("Called") 542 var called = Dnf.builder("Called")
540 .parameters(p1, p2) 543 .parameters(p1, p2)
541 .clause( 544 .clause(
542 new RelationViewAtom(personView, p1), 545 new RelationViewLiteral(personView, p1),
543 new RelationViewAtom(personView, p2), 546 new RelationViewLiteral(personView, p2),
544 new RelationViewAtom(friendMustView, p1, p2) 547 new RelationViewLiteral(friendMustView, p1, p2)
545 ) 548 )
546 .build(); 549 .build();
547 550
548 var predicate = DNF.builder("Count") 551 var predicate = Dnf.builder("Count")
549 .parameters(p1) 552 .parameters(p1)
550 .clause( 553 .clause(
551 new RelationViewAtom(personView, p1), 554 new RelationViewLiteral(personView, p1),
552 new DNFCallAtom(false, called, p1, p2) 555 new DnfCallLiteral(false, called, p1, p2)
553 ) 556 )
554 .build(); 557 .build();
555 558
@@ -585,12 +588,12 @@ class QueryTest {
585 588
586 var p1 = new Variable("p1"); 589 var p1 = new Variable("p1");
587 var p2 = new Variable("p2"); 590 var p2 = new Variable("p2");
588 var predicate = DNF.builder("TransitivePatternCall") 591 var predicate = Dnf.builder("TransitivePatternCall")
589 .parameters(p1, p2) 592 .parameters(p1, p2)
590 .clause( 593 .clause(
591 new RelationViewAtom(personView, p1), 594 new RelationViewLiteral(personView, p1),
592 new RelationViewAtom(personView, p2), 595 new RelationViewLiteral(personView, p2),
593 new RelationViewAtom(CallPolarity.TRANSITIVE, friendMustView, p1, p2) 596 new RelationViewLiteral(CallPolarity.TRANSITIVE, friendMustView, p1, p2)
594 ) 597 )
595 .build(); 598 .build();
596 599
@@ -626,23 +629,23 @@ class QueryTest {
626 629
627 var p1 = new Variable("p1"); 630 var p1 = new Variable("p1");
628 var p2 = new Variable("p2"); 631 var p2 = new Variable("p2");
629 var friendPredicate = DNF.builder("RelationConstraint") 632 var friendPredicate = Dnf.builder("RelationConstraint")
630 .parameters(p1, p2) 633 .parameters(p1, p2)
631 .clause( 634 .clause(
632 new RelationViewAtom(personView, p1), 635 new RelationViewLiteral(personView, p1),
633 new RelationViewAtom(personView, p2), 636 new RelationViewLiteral(personView, p2),
634 new RelationViewAtom(friendMustView, p1, p2) 637 new RelationViewLiteral(friendMustView, p1, p2)
635 ) 638 )
636 .build(); 639 .build();
637 640
638 var p3 = new Variable("p3"); 641 var p3 = new Variable("p3");
639 var p4 = new Variable("p4"); 642 var p4 = new Variable("p4");
640 var predicate = DNF.builder("TransitivePatternCall") 643 var predicate = Dnf.builder("TransitivePatternCall")
641 .parameters(p3, p4) 644 .parameters(p3, p4)
642 .clause( 645 .clause(
643 new RelationViewAtom(personView, p3), 646 new RelationViewLiteral(personView, p3),
644 new RelationViewAtom(personView, p4), 647 new RelationViewLiteral(personView, p4),
645 new DNFCallAtom(CallPolarity.TRANSITIVE, friendPredicate, p3, p4) 648 new DnfCallLiteral(CallPolarity.TRANSITIVE, friendPredicate, p3, p4)
646 ) 649 )
647 .build(); 650 .build();
648 651
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java
index 98995339..99b942d2 100644
--- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java
+++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java
@@ -2,10 +2,10 @@ package tools.refinery.store.query.viatra;
2 2
3import org.junit.jupiter.api.Test; 3import org.junit.jupiter.api.Test;
4import tools.refinery.store.model.ModelStore; 4import tools.refinery.store.model.ModelStore;
5import tools.refinery.store.query.DNF; 5import tools.refinery.store.query.Dnf;
6import tools.refinery.store.query.ModelQuery; 6import tools.refinery.store.query.ModelQuery;
7import tools.refinery.store.query.Variable; 7import tools.refinery.store.query.Variable;
8import tools.refinery.store.query.atom.RelationViewAtom; 8import tools.refinery.store.query.literal.RelationViewLiteral;
9import tools.refinery.store.query.view.KeyOnlyRelationView; 9import tools.refinery.store.query.view.KeyOnlyRelationView;
10import tools.refinery.store.representation.Symbol; 10import tools.refinery.store.representation.Symbol;
11import tools.refinery.store.tuple.Tuple; 11import tools.refinery.store.tuple.Tuple;
@@ -20,9 +20,9 @@ class QueryTransactionTest {
20 var personView = new KeyOnlyRelationView<>(person); 20 var personView = new KeyOnlyRelationView<>(person);
21 21
22 var p1 = new Variable("p1"); 22 var p1 = new Variable("p1");
23 var predicate = DNF.builder("TypeConstraint") 23 var predicate = Dnf.builder("TypeConstraint")
24 .parameters(p1) 24 .parameters(p1)
25 .clause(new RelationViewAtom(personView, p1)) 25 .clause(new RelationViewLiteral(personView, p1))
26 .build(); 26 .build();
27 27
28 var store = ModelStore.builder() 28 var store = ModelStore.builder()