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