Skip to content

Package: ConstructorResult

ConstructorResult

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