Skip to content

Package: ResultSetMappingManager

ResultSetMappingManager

nameinstructionbranchcomplexitylinemethod
ResultSetMappingManager()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addMapper(String, SparqlResultMapper)
M: 0 C: 32
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getMapper(String)
M: 0 C: 25
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

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.query;
16:
17: import cz.cvut.kbss.jopa.query.mapper.SparqlResultMapper;
18:
19: import java.util.HashMap;
20: import java.util.Map;
21: import java.util.Objects;
22:
23: /**
24: * Manages result set mappers, which are used to transform query result sets to output based on {@link
25: * cz.cvut.kbss.jopa.model.annotations.SparqlResultSetMapping}.
26: */
27: public class ResultSetMappingManager {
28:
29: private final Map<String, SparqlResultMapper> mappers = new HashMap<>();
30:
31: /**
32: * Adds the specified mapper to this manager, so that it can be used later.
33: *
34: * @param mappingName Named of the mapping for which the mapper is added
35: * @param mapper The mapper to register
36: * @throws IllegalArgumentException If a mapping with the same name already exists
37: */
38: public void addMapper(String mappingName, SparqlResultMapper mapper) {
39: Objects.requireNonNull(mappingName);
40: Objects.requireNonNull(mapper);
41:• if (mappers.containsKey(mappingName)) {
42: throw new IllegalArgumentException("Mapping " + mappingName + " already exists in this persistence unit.");
43: }
44: mappers.put(mappingName, mapper);
45: }
46:
47: /**
48: * Gets mapper for the specified mapping name.
49: *
50: * @param mappingName Name of the mapping
51: * @return Matching mapper
52: * @throws IllegalArgumentException If there is no mapper for such mapping
53: */
54: public SparqlResultMapper getMapper(String mappingName) {
55:• if (!mappers.containsKey(mappingName)) {
56: throw new IllegalArgumentException("Mapping " + mappingName + " not found in this persistence unit.");
57: }
58: return mappers.get(mappingName);
59: }
60: }