aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/backend/ResultProviderRequestor.java
blob: 6ec6d53e07bfb2497437e81e45741748b4e0c507 (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
/*******************************************************************************
 * Copyright (c) 2010-2018, Gabor Bergmann, IncQuery Labs Ltd.
 * 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.matchers.backend;

import tools.refinery.viatra.runtime.matchers.context.IQueryResultProviderAccess;
import tools.refinery.viatra.runtime.matchers.psystem.IQueryReference;
import tools.refinery.viatra.runtime.matchers.psystem.PConstraint;

/**
 * Uniform way of requesting result providers for pattern calls within queries.
 * Intended users are query backends, for calling other backends to deliver results of dependee queries.
 * 
 * @author Gabor Bergmann
 * @since 2.1
 */
public class ResultProviderRequestor {
    IQueryBackend callerBackend;
    IQueryResultProviderAccess resultProviderAccess;
    IQueryBackendHintProvider hintProvider;
    ICallDelegationStrategy delegationStrategy;
    QueryEvaluationHint callerHint;
    QueryEvaluationHint universalOverride;
    
    
    /**
     * @param callerBackend the actual backend evaluating the calling pattern.  
     * @param resultProviderAccess
     * @param hintProvider
     * @param delegationStrategy
     * @param callerHint  a hint under which the calling pattern is evaluated, 
     * @param universalOverride if non-null, overrides the hint with extra options <i>after</i> the {@link ICallDelegationStrategy}
     */
    public ResultProviderRequestor(IQueryBackend callerBackend, IQueryResultProviderAccess resultProviderAccess,
            IQueryBackendHintProvider hintProvider, ICallDelegationStrategy delegationStrategy,
            QueryEvaluationHint callerHint, QueryEvaluationHint universalOverride) {
        super();
        this.callerBackend = callerBackend;
        this.resultProviderAccess = resultProviderAccess;
        this.hintProvider = hintProvider;
        this.delegationStrategy = delegationStrategy;
        this.callerHint = callerHint;
        this.universalOverride = universalOverride;
    }




    /**
     * 
     * @param call a {@link PConstraint} in a query that calls another query.
     * @param spotOverride if non-null, overrides the hint with extra options <i>after</i> the {@link ICallDelegationStrategy} 
     * and the universal override specified in the constructor
     * @return the obtained result provider
     */
    public IQueryResultProvider requestResultProvider(IQueryReference call, QueryEvaluationHint spotOverride) {
        QueryEvaluationHint hints = 
                delegationStrategy.transformHints(call, callerHint, callerBackend, hintProvider);
        
        if (universalOverride != null)
            hints = hints.overrideBy(universalOverride);
        
        if (spotOverride != null)
            hints = hints.overrideBy(spotOverride);
        
        return resultProviderAccess.getResultProvider(call.getReferredQuery(), hints);
    }

}