Skip to content

Package: DetachedValueMerger

DetachedValueMerger

nameinstructionbranchcomplexitylinemethod
DetachedValueMerger(UnitOfWork)
M: 4 C: 33
89%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 8
100%
M: 0 C: 1
100%
getMerger(FieldSpecification)
M: 0 C: 28
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
mergeValue(Object, ChangeRecord, Descriptor)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.sessions.merge;
19:
20: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
21: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
22: import cz.cvut.kbss.jopa.sessions.UnitOfWork;
23: import cz.cvut.kbss.jopa.sessions.change.ChangeRecord;
24:
25: import java.util.Collection;
26: import java.util.Map;
27:
28: public class DetachedValueMerger implements ValueMerger {
29:
30: private final UnitOfWork uow;
31:
32: private final ValueMerger defaultValueMerger;
33: private final ManagedTypeValueMerger managedTypeMerger;
34: private final CollectionValueMerger collectionMerger;
35: private final MapValueMerger mapValueMerger;
36:
37: public DetachedValueMerger(UnitOfWork uow) {
38:• assert uow != null;
39: this.uow = uow;
40: this.defaultValueMerger = new DefaultValueMerger();
41: this.managedTypeMerger = new ManagedTypeValueMerger(uow);
42: this.collectionMerger = new CollectionValueMerger(uow, managedTypeMerger);
43: this.mapValueMerger = new MapValueMerger();
44: }
45:
46: @Override
47: public void mergeValue(Object target, ChangeRecord changeRecord, Descriptor attributeDescriptor) {
48: getMerger(changeRecord.getAttribute()).mergeValue(target, changeRecord, attributeDescriptor);
49: }
50:
51: private ValueMerger getMerger(FieldSpecification<?, ?> att) {
52:• if (uow.isEntityType(att.getJavaType())) {
53: return managedTypeMerger;
54:• } else if (Collection.class.isAssignableFrom(att.getJavaType())) {
55: return collectionMerger;
56:• } else if (Map.class.isAssignableFrom(att.getJavaType())) {
57: return mapValueMerger;
58: } else {
59: return defaultValueMerger;
60: }
61: }
62: }