Skip to content

Package: ChangeTrackingIndirectCollection

ChangeTrackingIndirectCollection

nameinstructionbranchcomplexitylinemethod
ChangeTrackingIndirectCollection(Object, Field, UnitOfWork)
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: * 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.proxy.change;
19:
20: import cz.cvut.kbss.jopa.proxy.IndirectWrapper;
21: import cz.cvut.kbss.jopa.sessions.UnitOfWork;
22:
23: import java.lang.reflect.Field;
24:
25: /**
26: * Wraps a collection so that calls to modifying operations are intercepted and reported to the persistence context (if
27: * necessary).
28: *
29: * @param <T> Type of the wrapped object
30: */
31: public abstract class ChangeTrackingIndirectCollection<T> implements IndirectWrapper<T> {
32:
33: protected final transient Object owner;
34: protected final transient Field field;
35: protected final transient UnitOfWork persistenceContext;
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 ChangeTrackingIndirectCollection(Object owner, Field f, UnitOfWork 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.isFlushingChanges()) {
59: persistenceContext.attributeChanged(owner, field);
60: }
61: }
62: }