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