aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/GenericQuerySpecification.java
blob: 5681ac1930b5d05a22be26035d0a8cc3eaabbdf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
 * Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath and Daniel Varro
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package tools.refinery.viatra.runtime.api;

import tools.refinery.viatra.runtime.api.impl.BaseQuerySpecification;
import tools.refinery.viatra.runtime.matchers.ViatraQueryRuntimeException;
import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery;
import tools.refinery.viatra.runtime.matchers.psystem.queries.PVisibility;

/**
 * This is a generic query specification for VIATRA pattern matchers, for "interpretative" query execution. 
 * Should be subclassed by query specification implementations specific to query languages.
 *
 * <p>
 * When available, consider using the pattern-specific generated matcher API instead.
 *
 * <p>
 * The created matcher will be of type {@link GenericPatternMatcher}. Matches of the pattern will be represented as
 * {@link GenericPatternMatch}.
 * 
 * <p>
 * Note for overriding (if you have your own query language or ): 
 * Derived classes should use {@link #defaultInstantiate(ViatraQueryEngine)} for implementing 
 * {@link #instantiate(ViatraQueryEngine)} if they use {@link GenericPatternMatcher} proper.
 *
 * @see GenericPatternMatcher
 * @see GenericPatternMatch
 * @see GenericMatchProcessor
 * @author Bergmann Gábor
 * @noinstantiate This class is not intended to be instantiated by end-users.
 * @since 0.9
 */
public abstract class GenericQuerySpecification<Matcher extends GenericPatternMatcher> extends
        BaseQuerySpecification<Matcher> {

    /**
     * Instantiates query specification for the given internal query representation.
     */
    public GenericQuerySpecification(PQuery wrappedPQuery) {
        super(wrappedPQuery);
    }

    @Override
    public GenericPatternMatch newEmptyMatch() {
        return GenericPatternMatch.newEmptyMatch(this);
    }

    @Override
    public GenericPatternMatch newMatch(Object... parameters) {
        return GenericPatternMatch.newMatch(this, parameters);
    }

    /**
     * Derived classes should use this implementation of {@link #instantiate(ViatraQueryEngine)} 
     * if they use {@link GenericPatternMatcher} proper.
     * @throws ViatraQueryRuntimeException
     */
    protected GenericPatternMatcher defaultInstantiate(ViatraQueryEngine engine) {
        return GenericPatternMatcher.instantiate(engine, this);
    }

    /**
     * @since 2.0
     */
    @Override
    public PVisibility getVisibility() {
        return getInternalQueryRepresentation().getVisibility();
    }

}