Skip to content

Package: ManagedTypeChangeDetector

ManagedTypeChangeDetector

nameinstructionbranchcomplexitylinemethod
ManagedTypeChangeDetector(MetamodelProvider)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
hasChanges(Object, Object)
M: 2 C: 30
94%
M: 5 C: 7
58%
M: 4 C: 3
43%
M: 0 C: 5
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2016 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.sessions.change;
16:
17: import cz.cvut.kbss.jopa.sessions.MetamodelProvider;
18: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
19:
20: public class ManagedTypeChangeDetector implements ChangeDetector {
21:
22: private final MetamodelProvider metamodelProvider;
23:
24: ManagedTypeChangeDetector(MetamodelProvider metamodelProvider) {
25: this.metamodelProvider = metamodelProvider;
26: }
27:
28: @Override
29: public boolean hasChanges(Object clone, Object original) {
30: final Object idOrig = EntityPropertiesUtils.getIdentifier(original, metamodelProvider.getMetamodel());
31: final Object idClone = EntityPropertiesUtils.getIdentifier(clone, metamodelProvider.getMetamodel());
32:
33:• if (idOrig == null && idClone != null || idOrig != null && idClone == null) {
34: return true;
35: }
36:• return idClone != null && !idClone.equals(idOrig);
37: }
38: }