Skip to contentMethod: processClass(Class)
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.metamodel;
19:
20: import cz.cvut.kbss.jopa.model.annotations.NamedNativeQueries;
21: import cz.cvut.kbss.jopa.model.annotations.NamedNativeQuery;
22: import cz.cvut.kbss.jopa.query.NamedQueryManager;
23:
24: class NamedNativeQueryProcessor {
25:
26: private final NamedQueryManager queryManager = new NamedQueryManager();
27:
28: /**
29: * Discovers named native queries declared on the specified class.
30: * <p>
31: * The queries (if found) are added to the {@code NamedQueryManager}, which was passed to this class in constructor.
32: *
33: * @param cls The class to process
34: */
35: <T> void processClass(Class<T> cls) {
36: final NamedNativeQueries queries = cls.getAnnotation(NamedNativeQueries.class);
37:• if (queries != null) {
38:• for (NamedNativeQuery q : queries.value()) {
39: processQuery(q);
40: }
41: }
42: final NamedNativeQuery nq = cls.getAnnotation(NamedNativeQuery.class);
43:• if (nq != null) {
44: processQuery(nq);
45: }
46: }
47:
48: private void processQuery(NamedNativeQuery query) {
49: queryManager.addNamedQuery(query.name(), query.query());
50: }
51:
52: NamedQueryManager getQueryManager() {
53: return queryManager;
54: }
55: }