Package: OneLevelRemoveCascadeExplorer
OneLevelRemoveCascadeExplorer
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
OneLevelRemoveCascadeExplorer(Consumer) |
|
|
|
|
|
||||||||||||||||||||
exploreCascaded(Attribute, Object) |
|
|
|
|
|
Coverage
1: package cz.cvut.kbss.jopa.model;
2:
3: import cz.cvut.kbss.jopa.model.metamodel.Attribute;
4: import cz.cvut.kbss.jopa.proxy.lazy.LazyLoadingProxy;
5: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
6: import cz.cvut.kbss.jopa.utils.JOPALazyUtils;
7:
8: import java.util.Collection;
9: import java.util.HashSet;
10: import java.util.function.Consumer;
11:
12: public class OneLevelRemoveCascadeExplorer extends OneLevelCascadeExplorer {
13:
14: private final Consumer<Object> removeOperation;
15:
16: public OneLevelRemoveCascadeExplorer(Consumer<Object> removeOperation) {
17: this.removeOperation = removeOperation;
18: }
19:
20: @Override
21: protected void exploreCascaded(Attribute<?, ?> at, Object o) {
22: Object attVal = EntityPropertiesUtils.getAttributeValue(at, o);
23:• if (attVal == null) {
24: return;
25: }
26:• if (JOPALazyUtils.isLazyLoadingProxy(attVal)) {
27: attVal = ((LazyLoadingProxy<?>) attVal).triggerLazyLoading();
28: }
29:• if (at.isCollection()) {
30:• for (final Object ox2 : new HashSet<>((Collection<?>) attVal)) {
31: removeOperation.accept(ox2);
32: }
33: } else {
34: removeOperation.accept(attVal);
35: }
36: }
37: }