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: 24
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: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

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