Skip to content

Method: OneLevelCascadeExplorer()

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