summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/Properties.java
blob: df3d120c33728306c0d09a74e9e9cae7b8bca348 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query;

import com.yahoo.search.Query;

/**
 * Object properties keyed by name which can be looked up using default values and
 * with conversion to various primitive wrapper types.
 * <p>
 * Multiple property implementations can be chained to provide unified access to properties
 * backed by multiple sources as a Chain of Responsibility.
 * <p>
 * For better performance, prefer CompoundName argument constants over Strings.
 * <p>
 * Properties can be cloned. Cloning a properties instance returns a new instance
 * which chains new instances of all chained instances. The content within each instance
 * is cloned to the extent determined appropriate by that implementation.
 * <p>
 * This base class simply passes all access on to the next in chain.
 *
 * @author bratseth
 */
public abstract class Properties extends com.yahoo.processing.request.Properties {

    @Override
    public Properties chained() { return (Properties)super.chained(); }

    @Override
    public Properties clone() {
        return (Properties)super.clone();
    }

    /** The query owning this property object.
     *  Only guaranteed to work if this instance is accessible as query.properties()
     */
    public Query getParentQuery() {
        if (chained() == null) {
            throw new RuntimeException("getParentQuery should only be called on a properties instance accessible as query.properties()");
        } else {
            return chained().getParentQuery();
        }
    }

    /**
     * Invoked during deep cloning of the parent query.
     */
    public void setParentQuery(Query query) {
        if (chained() != null)
            chained().setParentQuery(query);
    }
}