Package: ResultRowMapper
ResultRowMapper
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ResultRowMapper(String) |
|
|
|
|
|
||||||||||||||||||||
addMapper(SparqlResultMapper) |
|
|
|
|
|
||||||||||||||||||||
getName() |
|
|
|
|
|
||||||||||||||||||||
getRowMappers() |
|
|
|
|
|
||||||||||||||||||||
map(ResultRow, UnitOfWorkImpl) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2023 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.mapper;
16:
17: import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
18: import cz.cvut.kbss.ontodriver.iteration.ResultRow;
19:
20: import java.util.ArrayList;
21: import java.util.Collections;
22: import java.util.List;
23:
24: /**
25: * Represents a single {@link cz.cvut.kbss.jopa.model.annotations.SparqlResultSetMapping} instance.
26: * <p>
27: * This instance can contain multiple {@link SparqlResultMapper} instances, representing the individual mappings
28: * specified by the {@link cz.cvut.kbss.jopa.model.annotations.SparqlResultSetMapping}.
29: */
30: public class ResultRowMapper implements SparqlResultMapper {
31:
32: private final String name;
33:
34: private final List<SparqlResultMapper> rowMappers = new ArrayList<>();
35:
36: public ResultRowMapper(String name) {
37: this.name = name;
38: }
39:
40: /**
41: * Gets the name of the result set mapping represented by this mapper.
42: *
43: * @return Mapping name
44: */
45: public String getName() {
46: return name;
47: }
48:
49: List<SparqlResultMapper> getRowMappers() {
50: return Collections.unmodifiableList(rowMappers);
51: }
52:
53: void addMapper(SparqlResultMapper mapper) {
54: rowMappers.add(mapper);
55: }
56:
57: @Override
58: public Object map(ResultRow resultRow, UnitOfWorkImpl uow) {
59:• if (rowMappers.size() == 1) {
60: return rowMappers.get(0).map(resultRow, uow);
61: }
62: final Object[] result = new Object[rowMappers.size()];
63: int i = 0;
64:• for (SparqlResultMapper m : rowMappers) {
65: result[i++] = m.map(resultRow, uow);
66: }
67: return result;
68: }
69: }