Skip to content

Package: OneLevelCascadeExplorer

OneLevelCascadeExplorer

nameinstructionbranchcomplexitylinemethod
OneLevelCascadeExplorer()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
exploreCascaded(Attribute, Object)
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
exploreNonCascaded(Attribute, Object)
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%
start(AbstractEntityManager, Object, CascadeType)
M: 6 C: 45
88%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 2 C: 12
86%
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.model;
16:
17: import cz.cvut.kbss.jopa.exceptions.OWLPersistenceException;
18: import cz.cvut.kbss.jopa.model.annotations.CascadeType;
19: import cz.cvut.kbss.jopa.model.metamodel.Attribute;
20: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
21:
22: import java.util.Arrays;
23: import java.util.List;
24:
25: public abstract class OneLevelCascadeExplorer {
26:
27:         private CascadeType ct;
28:
29:         public void start(final AbstractEntityManager pc, final Object o, CascadeType ct) {
30:                 this.ct = ct;
31:
32:                 final EntityType<?> a = pc.getMetamodel().entity(o.getClass());
33:•                for (final Attribute<?, ?> at : a.getAttributes()) {
34:
35:                         final List<CascadeType> cTypes = Arrays
36:                                         .asList(at.getCascadeTypes());
37:
38:                         try {
39:•                                if (!cTypes.contains(CascadeType.ALL)
40:•                                                && !cTypes.contains(this.ct)) {
41:                                         exploreNonCascaded(at, o);
42:                                 } else {
43:                                         exploreCascaded(at, o);
44:                                 }
45:                         } catch (Exception e) {
46:                                 throw new OWLPersistenceException(e);
47:                         }
48:                 }
49:         }
50:
51:         protected void exploreCascaded(final Attribute<?, ?> at,
52:                         final Object o) throws IllegalAccessException {
53:                 // empty body
54:         }
55:
56:         protected void exploreNonCascaded(final Attribute<?, ?> at,
57:                         final Object o) throws IllegalAccessException {
58:                 // empty body                
59:         }
60: }