Skip to content

Package: EntityResult

EntityResult

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 to map the SELECT clause of a SPARQL query to
23: * an entity result.
24: * <p>
25: * If this annotation is used, the SPARQL statement should select all of the variables that are mapped to the entity
26: * object. This should include attributes of related entities. The results obtained when insufficient data is available
27: * are undefined.
28: * <p>
29: * Example:
30: * <pre>
31: * <code>
32: * Query q = em.createNativeQuery(
33: * "SELECT ?uri, ?quantity, ?item, ?label, ?description "+
34: * "WHERE {
35: * ?uri a <http://onto.fel.cvut.cz/ontologies/jopa/Order> ;
36: * <http://onto.fel.cvut.cz/ontologies/ufo/has_part> ?item .
37: * ?item a <http://onto.fel.cvut.cz/ontologies/jopa/Order> ;
38: * rdfs:label ?label;
39: * rdfs:comment ?description .
40: * }", "OrderItemResults");
41: * {@literal @}SparqlResultSetMapping(name="OrderItemResults",
42: * entities={
43: * {@literal @}EntityResult(entityClass=cz.cvut.kbss.jopa.Order.class),
44: * {@literal @}EntityResult(entityClass=cz.cvut.kbss.jopa.Item.class)
45: * })
46: * </code>
47: * </pre>
48: *
49: * @see SparqlResultSetMapping
50: */
51: @Target({})
52: @Retention(value = RetentionPolicy.RUNTIME)
53: public @interface EntityResult {
54:
55: /**
56: * The class of the result.
57: */
58: Class<?> entityClass();
59:
60: /**
61: * Maps the variables specified in the SELECT list of the query to the properties or fields of the entity class.
62: */
63: FieldResult[] fields() default {};
64: }