Skip to contentPackage: VariableResult
VariableResult
Coverage
1: /**
2: * Copyright (C) 2020 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.Retention;
18: import java.lang.annotation.RetentionPolicy;
19: import java.lang.annotation.Target;
20:
21: /**
22: * Used in conjunction with the {@link SparqlResultSetMapping} annotation or {@link ConstructorResult} annotation to map
23: * a column of the SELECT list of a SPARQL query.
24: * <p>
25: * The name element references the name of a variable in the SELECT list. Scalar result types can be included in the
26: * query result by specifying this annotation in the metadata. If the variable is not bound in the result, {@code null}
27: * is returned.
28: * <p>
29: * Example:
30: * <pre>
31: * <code>
32: * Query q = em.createNativeQuery("SELECT ?uri ?label ?comment WHERE {" +
33: * "?uri a <http://onto.fel.cvut.cz/ontologies/jopa/Example> ;" +
34: * "rdfs:label ?label ;" +
35: * "rdfs:comment ?comment ." +
36: * "}", "ExampleResults");
37: * </code>
38: * </pre>
39: * <p>
40: * <pre>
41: * <code>
42: * {@literal @}SparqlResultSetMapping(name="ExampleResults",
43: * classes={
44: * {@literal @}ConstructorResult(targetClass=cz.cvut.kbss.jopa.Example, variables={
45: * {@literal @}VariableResult(name="uri"),
46: * {@literal @}VariableResult(name="label"),
47: * {@literal @}VariableResult(name="comment")
48: * }
49: * }
50: * )
51: * </code>
52: * </pre>
53: *
54: * @see SparqlResultSetMapping
55: */
56: @Target(value = {})
57: @Retention(RetentionPolicy.RUNTIME)
58: public @interface VariableResult {
59:
60: /**
61: * (Required) The name of a variable in the SELECT clause of a SPARQL query.
62: */
63: String name();
64:
65: /**
66: * (Optional) The Java type to which the variable mapping type is to be mapped.
67: * <p>
68: * If the type element is not specified, the default OntoDriver type mapping for the variable mapping will be used.
69: */
70: Class<?> type() default void.class;
71: }