Skip to content

Package: Sparql

Sparql

Coverage

1: /**
2: * Copyright (C) 2023 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.model.annotations;
16:
17: import java.lang.annotation.*;
18:
19: /**
20: * This annotation can be used for creating SPARQL queries directly on repository fields.
21: * <p>
22: * The field and query parameters cannot be of a primitive type.
23: * <p>
24: * Example:
25: * <pre>
26: * <code>
27: * @Sparql("PREFIX jopa:<http://krizik.felk.cvut.cz/ontologies/jopa/>\n" +
28: * "SELECT ?stringAttribute WHERE {" +
29: * "?this jopa:attributes#B-stringAttribute ?stringAttribute}")
30: * private String stringQueryAttribute;
31: * </code>
32: * </pre>
33: */
34: @Documented
35: @Retention(RetentionPolicy.RUNTIME)
36: @Target(ElementType.FIELD)
37: public @interface Sparql {
38:
39: /**
40: * A native SPARQL query including any prefixes and parameters.
41: */
42: String query();
43:
44: /**
45: * Whether to allow referencing other entity attributes in the query.
46: * <p>
47: * If enabled, the provider will attempt to replace variables with names matching entity attributes with the
48: * attribute values.
49: * <p>
50: * Note that lazily loaded attribute values may not be used.
51: *
52: * @return {@code true} if variables referencing other entity attributes should be replaced in the query with the
53: * attribute values, {@code false} otherwise
54: */
55: boolean enableReferencingAttributes() default true;
56:
57: /**
58: * If {@code FetchType.LAZY} is specified the attribute will not be initialized during entity construction but
59: * rather only when it is required by a getter method.
60: */
61: FetchType fetchType() default FetchType.EAGER;
62: }