Skip to content

Package: ObjectPropertyFieldResultMapper

ObjectPropertyFieldResultMapper

nameinstructionbranchcomplexitylinemethod
ObjectPropertyFieldResultMapper(FieldResult, FieldSpecification)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
ObjectPropertyFieldResultMapper(FieldSpecification)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$map$0(UnitOfWork, Object, Object)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
map(ResultRow, Object, UnitOfWork)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
resolveValue(UnitOfWork, Object)
M: 0 C: 21
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) 2022 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.model.annotations.FieldResult;
18: import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
19: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
20: import cz.cvut.kbss.jopa.sessions.UnitOfWork;
21: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
22: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
23: import cz.cvut.kbss.ontodriver.iteration.ResultRow;
24:
25: import java.util.Optional;
26:
27: /**
28: * Mapping SPARQL SELECT results to object property fields.
29: * <p>
30: * This means that the referenced instance has to be loaded (unless the field is plain identifier).
31: */
32: class ObjectPropertyFieldResultMapper extends FieldResultMapper {
33:
34: ObjectPropertyFieldResultMapper(FieldResult fieldResult, FieldSpecification<?, ?> fieldSpec) {
35: super(fieldResult, fieldSpec);
36: }
37:
38: ObjectPropertyFieldResultMapper(FieldSpecification<?, ?> fieldSpec) {
39: super(fieldSpec);
40: }
41:
42: @Override
43: void map(ResultRow resultRow, Object target, UnitOfWork uow) {
44: final Optional<Object> id = getVariableValue(resultRow);
45: id.ifPresent(idValue -> {
46: final Object value = resolveValue(uow, idValue);
47: EntityPropertiesUtils.setFieldValue(getFieldSpecification().getJavaField(), target, value);
48: });
49: }
50:
51: private Object resolveValue(UnitOfWork uow, Object id) {
52:• if (IdentifierTransformer.isValidIdentifierType(getFieldSpecification().getJavaType())) {
53: return IdentifierTransformer.transformToIdentifier(id, getFieldSpecification().getJavaType());
54: }
55: return uow.readObject(getFieldSpecification().getJavaType(), id, new EntityDescriptor());
56: }
57: }