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