Skip to content

Package: ConstructorResult

ConstructorResult

Coverage

1: /**
2: * Copyright (C) 2022 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 to map the SELECT clause of a SPARQL query to
23: * a constructor.
24: * <p>
25: * Applies a constructor for the target class, passing in as arguments values from the specified variables. All
26: * variables corresponding to arguments of the intended constructor must be specified using the {@code variables}
27: * element of the {@code ConstructorResult} annotation in the same order as that of the argument list of the
28: * constructor. Any entities returned as constructor results will be in either the new or detached state, depending on
29: * whether a primary key is retrieved for the constructed object.
30: * <p>
31: * Example:
32: * <pre>
33: * <code>
34: * Query q = em.createNativeQuery("SELECT ?uri ?label ?comment WHERE {" +
35: * "?uri a <http://onto.fel.cvut.cz/ontologies/jopa/Example> ;" +
36: * "rdfs:label ?label ;" +
37: * "rdfs:comment ?comment ." +
38: * "}", "ExampleResults");
39: * </code>
40: * </pre>
41: *
42: * <pre>
43: * <code>
44: * {@literal @}SparqlResultSetMapping(name="ExampleResults",
45: * classes={
46: * {@literal @}ConstructorResult(targetClass=cz.cvut.kbss.jopa.Example, variables={
47: * {@literal @}VariableResult(name="uri"),
48: * {@literal @}VariableResult(name="label"),
49: * {@literal @}VariableResult(name="comment")
50: * }
51: * }
52: * )
53: * </code>
54: * </pre>
55: *
56: * @see SparqlResultSetMapping
57: * @see VariableResult
58: */
59: @Target(value = {})
60: @Retention(RetentionPolicy.RUNTIME)
61: public @interface ConstructorResult {
62:
63: /**
64: * (Required) The class whose constructor is to be invoked.
65: */
66: Class<?> targetClass();
67:
68: /**
69: * (Required) The mapping of variables in the SELECT list to the arguments of the intended constructor, in order.
70: */
71: VariableResult[] variables();
72: }