diff options
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java')
4 files changed, 23 insertions, 32 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQuery.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQuery.java deleted file mode 100644 index 3fff6f2e..00000000 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQuery.java +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.query.viatra; | ||
7 | |||
8 | import tools.refinery.store.adapter.ModelAdapterBuilderFactory; | ||
9 | import tools.refinery.store.model.ModelStoreBuilder; | ||
10 | import tools.refinery.store.query.ModelQuery; | ||
11 | import tools.refinery.store.query.viatra.internal.ViatraModelQueryBuilderImpl; | ||
12 | |||
13 | public final class ViatraModelQuery extends ModelAdapterBuilderFactory<ViatraModelQueryAdapter, | ||
14 | ViatraModelQueryStoreAdapter, ViatraModelQueryBuilder> { | ||
15 | public static final ViatraModelQuery ADAPTER = new ViatraModelQuery(); | ||
16 | |||
17 | private ViatraModelQuery() { | ||
18 | super(ViatraModelQueryAdapter.class, ViatraModelQueryStoreAdapter.class, ViatraModelQueryBuilder.class); | ||
19 | extendsAdapter(ModelQuery.ADAPTER); | ||
20 | } | ||
21 | |||
22 | @Override | ||
23 | public ViatraModelQueryBuilder createBuilder(ModelStoreBuilder storeBuilder) { | ||
24 | return new ViatraModelQueryBuilderImpl(storeBuilder); | ||
25 | } | ||
26 | } | ||
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryAdapter.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryAdapter.java index 411e251e..12c93f62 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryAdapter.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/ViatraModelQueryAdapter.java | |||
@@ -6,8 +6,13 @@ | |||
6 | package tools.refinery.store.query.viatra; | 6 | package tools.refinery.store.query.viatra; |
7 | 7 | ||
8 | import tools.refinery.store.query.ModelQueryAdapter; | 8 | import tools.refinery.store.query.ModelQueryAdapter; |
9 | import tools.refinery.store.query.viatra.internal.ViatraModelQueryBuilderImpl; | ||
9 | 10 | ||
10 | public interface ViatraModelQueryAdapter extends ModelQueryAdapter { | 11 | public interface ViatraModelQueryAdapter extends ModelQueryAdapter { |
11 | @Override | 12 | @Override |
12 | ViatraModelQueryStoreAdapter getStoreAdapter(); | 13 | ViatraModelQueryStoreAdapter getStoreAdapter(); |
14 | |||
15 | static ViatraModelQueryBuilder builder() { | ||
16 | return new ViatraModelQueryBuilderImpl(); | ||
17 | } | ||
13 | } | 18 | } |
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 310171e8..931a07aa 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 | |||
@@ -50,5 +50,5 @@ public interface ViatraModelQueryBuilder extends ModelQueryBuilder { | |||
50 | ViatraModelQueryBuilder hint(Dnf dnf, QueryEvaluationHint queryEvaluationHint); | 50 | ViatraModelQueryBuilder hint(Dnf dnf, QueryEvaluationHint queryEvaluationHint); |
51 | 51 | ||
52 | @Override | 52 | @Override |
53 | ViatraModelQueryStoreAdapter createStoreAdapter(ModelStore store); | 53 | ViatraModelQueryStoreAdapter build(ModelStore store); |
54 | } | 54 | } |
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 44ed1505..ce2467b4 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 | |||
@@ -25,7 +25,8 @@ import tools.refinery.store.query.viatra.internal.pquery.Dnf2PQuery; | |||
25 | import java.util.*; | 25 | import java.util.*; |
26 | import java.util.function.Function; | 26 | import java.util.function.Function; |
27 | 27 | ||
28 | public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder implements ViatraModelQueryBuilder { | 28 | public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder<ViatraModelQueryStoreAdapterImpl> |
29 | implements ViatraModelQueryBuilder { | ||
29 | private ViatraQueryEngineOptions.Builder engineOptionsBuilder; | 30 | private ViatraQueryEngineOptions.Builder engineOptionsBuilder; |
30 | private QueryEvaluationHint defaultHint = new QueryEvaluationHint(Map.of( | 31 | private QueryEvaluationHint defaultHint = new QueryEvaluationHint(Map.of( |
31 | // Use a cost function that ignores the initial (empty) model but allows higher arity input keys. | 32 | // Use a cost function that ignores the initial (empty) model but allows higher arity input keys. |
@@ -35,8 +36,7 @@ public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder imp | |||
35 | private final Set<AnyQuery> vacuousQueries = new LinkedHashSet<>(); | 36 | private final Set<AnyQuery> vacuousQueries = new LinkedHashSet<>(); |
36 | private final Map<AnyQuery, IQuerySpecification<RawPatternMatcher>> querySpecifications = new LinkedHashMap<>(); | 37 | private final Map<AnyQuery, IQuerySpecification<RawPatternMatcher>> querySpecifications = new LinkedHashMap<>(); |
37 | 38 | ||
38 | public ViatraModelQueryBuilderImpl(ModelStoreBuilder storeBuilder) { | 39 | public ViatraModelQueryBuilderImpl() { |
39 | super(storeBuilder); | ||
40 | engineOptionsBuilder = new ViatraQueryEngineOptions.Builder() | 40 | engineOptionsBuilder = new ViatraQueryEngineOptions.Builder() |
41 | .withDefaultBackend(ReteBackendFactory.INSTANCE) | 41 | .withDefaultBackend(ReteBackendFactory.INSTANCE) |
42 | .withDefaultCachingBackend(ReteBackendFactory.INSTANCE) | 42 | .withDefaultCachingBackend(ReteBackendFactory.INSTANCE) |
@@ -45,36 +45,42 @@ public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder imp | |||
45 | 45 | ||
46 | @Override | 46 | @Override |
47 | public ViatraModelQueryBuilder engineOptions(ViatraQueryEngineOptions engineOptions) { | 47 | public ViatraModelQueryBuilder engineOptions(ViatraQueryEngineOptions engineOptions) { |
48 | checkNotConfigured(); | ||
48 | engineOptionsBuilder = new ViatraQueryEngineOptions.Builder(engineOptions); | 49 | engineOptionsBuilder = new ViatraQueryEngineOptions.Builder(engineOptions); |
49 | return this; | 50 | return this; |
50 | } | 51 | } |
51 | 52 | ||
52 | @Override | 53 | @Override |
53 | public ViatraModelQueryBuilder defaultHint(QueryEvaluationHint queryEvaluationHint) { | 54 | public ViatraModelQueryBuilder defaultHint(QueryEvaluationHint queryEvaluationHint) { |
55 | checkNotConfigured(); | ||
54 | defaultHint = defaultHint.overrideBy(queryEvaluationHint); | 56 | defaultHint = defaultHint.overrideBy(queryEvaluationHint); |
55 | return this; | 57 | return this; |
56 | } | 58 | } |
57 | 59 | ||
58 | @Override | 60 | @Override |
59 | public ViatraModelQueryBuilder backend(IQueryBackendFactory queryBackendFactory) { | 61 | public ViatraModelQueryBuilder backend(IQueryBackendFactory queryBackendFactory) { |
62 | checkNotConfigured(); | ||
60 | engineOptionsBuilder.withDefaultBackend(queryBackendFactory); | 63 | engineOptionsBuilder.withDefaultBackend(queryBackendFactory); |
61 | return this; | 64 | return this; |
62 | } | 65 | } |
63 | 66 | ||
64 | @Override | 67 | @Override |
65 | public ViatraModelQueryBuilder cachingBackend(IQueryBackendFactory queryBackendFactory) { | 68 | public ViatraModelQueryBuilder cachingBackend(IQueryBackendFactory queryBackendFactory) { |
69 | checkNotConfigured(); | ||
66 | engineOptionsBuilder.withDefaultCachingBackend(queryBackendFactory); | 70 | engineOptionsBuilder.withDefaultCachingBackend(queryBackendFactory); |
67 | return this; | 71 | return this; |
68 | } | 72 | } |
69 | 73 | ||
70 | @Override | 74 | @Override |
71 | public ViatraModelQueryBuilder searchBackend(IQueryBackendFactory queryBackendFactory) { | 75 | public ViatraModelQueryBuilder searchBackend(IQueryBackendFactory queryBackendFactory) { |
76 | checkNotConfigured(); | ||
72 | engineOptionsBuilder.withDefaultSearchBackend(queryBackendFactory); | 77 | engineOptionsBuilder.withDefaultSearchBackend(queryBackendFactory); |
73 | return this; | 78 | return this; |
74 | } | 79 | } |
75 | 80 | ||
76 | @Override | 81 | @Override |
77 | public ViatraModelQueryBuilder query(AnyQuery query) { | 82 | public ViatraModelQueryBuilder query(AnyQuery query) { |
83 | checkNotConfigured(); | ||
78 | if (querySpecifications.containsKey(query) || vacuousQueries.contains(query)) { | 84 | if (querySpecifications.containsKey(query) || vacuousQueries.contains(query)) { |
79 | // Ignore duplicate queries. | 85 | // Ignore duplicate queries. |
80 | return this; | 86 | return this; |
@@ -103,20 +109,26 @@ public class ViatraModelQueryBuilderImpl extends AbstractModelAdapterBuilder imp | |||
103 | 109 | ||
104 | @Override | 110 | @Override |
105 | public ViatraModelQueryBuilder computeHint(Function<Dnf, QueryEvaluationHint> computeHint) { | 111 | public ViatraModelQueryBuilder computeHint(Function<Dnf, QueryEvaluationHint> computeHint) { |
112 | checkNotConfigured(); | ||
106 | dnf2PQuery.setComputeHint(computeHint); | 113 | dnf2PQuery.setComputeHint(computeHint); |
107 | return this; | 114 | return this; |
108 | } | 115 | } |
109 | 116 | ||
110 | @Override | 117 | @Override |
111 | public ViatraModelQueryBuilder hint(Dnf dnf, QueryEvaluationHint queryEvaluationHint) { | 118 | public ViatraModelQueryBuilder hint(Dnf dnf, QueryEvaluationHint queryEvaluationHint) { |
119 | checkNotConfigured(); | ||
112 | dnf2PQuery.hint(dnf, queryEvaluationHint); | 120 | dnf2PQuery.hint(dnf, queryEvaluationHint); |
113 | return this; | 121 | return this; |
114 | } | 122 | } |
115 | 123 | ||
116 | @Override | 124 | @Override |
117 | public ViatraModelQueryStoreAdapterImpl createStoreAdapter(ModelStore store) { | 125 | public void doConfigure(ModelStoreBuilder storeBuilder) { |
118 | validateSymbols(store); | ||
119 | dnf2PQuery.assertNoUnusedHints(); | 126 | dnf2PQuery.assertNoUnusedHints(); |
127 | } | ||
128 | |||
129 | @Override | ||
130 | public ViatraModelQueryStoreAdapterImpl doBuild(ModelStore store) { | ||
131 | validateSymbols(store); | ||
120 | return new ViatraModelQueryStoreAdapterImpl(store, buildEngineOptions(), dnf2PQuery.getSymbolViews(), | 132 | return new ViatraModelQueryStoreAdapterImpl(store, buildEngineOptions(), dnf2PQuery.getSymbolViews(), |
121 | Collections.unmodifiableMap(querySpecifications), Collections.unmodifiableSet(vacuousQueries)); | 133 | Collections.unmodifiableMap(querySpecifications), Collections.unmodifiableSet(vacuousQueries)); |
122 | } | 134 | } |