Skip to content

Package: Sparql

Sparql

Coverage

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