Skip to content

Package: IndirectCollection

IndirectCollection

nameinstructionbranchcomplexitylinemethod
IndirectCollection()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
IndirectCollection(Object, Field, UnitOfWorkImpl)
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
persistChange()
M: 4 C: 20
83%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 4
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: * Copyright (C) 2023 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.adapters;
16:
17: import cz.cvut.kbss.jopa.sessions.UnitOfWorkImpl;
18:
19: import java.lang.reflect.Field;
20:
21: /**
22: * Wraps a collection so that calls to modifying operations are intercepted and reported to the persistence context (if necessary).
23: * @param <T> Type of the wrapped object
24: */
25: public abstract class IndirectCollection<T> implements IndirectWrapper {
26:
27: protected final transient Object owner;
28: protected final transient Field field;
29: protected final transient UnitOfWorkImpl persistenceContext;
30:
31: protected IndirectCollection() {
32: owner = null;
33: field = null;
34: persistenceContext = null;
35: }
36:
37: /**
38: * Create new indirect collection from the specified data.
39: * <p>
40: * The owner can be null, the persistence context not.
41: *
42: * @param owner Owner of the indirect collection
43: * @param f The field holding this collection
44: * @param persistenceContext Persistence context the owner belongs to
45: * @throws NullPointerException If the persistence context is null
46: */
47: protected IndirectCollection(Object owner, Field f, UnitOfWorkImpl persistenceContext) {
48:• if (persistenceContext == null) {
49: throw new NullPointerException("Null passed in as persistenceContext.");
50: }
51: this.owner = owner;
52: this.field = f;
53: this.persistenceContext = persistenceContext;
54: }
55:
56: protected void persistChange() {
57:• assert persistenceContext != null;
58:• if (persistenceContext.isInTransaction() && !persistenceContext.isInCommit()) {
59: persistenceContext.attributeChanged(owner, field);
60: }
61: }
62:
63: /**
64: * The returned type is determined by the instance type parameter.
65: *
66: * @return The collection wrapped in this indirect collection
67: */
68: @Override
69: public abstract T unwrap();
70: }