Skip to content

Package: LazyLoadingEntityProxy

LazyLoadingEntityProxy

nameinstructionbranchcomplexitylinemethod
getProxiedClass()
M: 4 C: 10
71%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 0 C: 2
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 3
100%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 1
100%
M: 0 C: 1
100%
stringify()
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
triggerLazyLoading()
M: 9 C: 25
74%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 2 C: 5
71%
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.lazy.gen;
19:
20: import cz.cvut.kbss.jopa.exception.LazyLoadingException;
21: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
22: import cz.cvut.kbss.jopa.proxy.lazy.LazyLoadingProxy;
23:
24: /**
25: * Implemented by generated lazy loading entity proxy classes.
26: * <p>
27: * It defines the default method for triggering lazy loading.
28: *
29: * @param <T> Type of the lazily-loaded value
30: */
31:•public interface LazyLoadingEntityProxy<T> extends LazyLoadingProxyPropertyAccessor<T>, LazyLoadingProxy<T> {
32:
33: @Override
34: default T triggerLazyLoading() {
35:• if (isLoaded()) {
36: return getLoadedValue();
37: }
38:• if (getPersistenceContext() == null || !getPersistenceContext().isActive()) {
39: throw new LazyLoadingException("No active persistence context is available in lazy loading proxy for attribute "
40: + getFieldSpec() + " of entity " + getOwner());
41: }
42: setValue((T) getPersistenceContext().loadEntityField(getOwner(), (FieldSpecification<? super Object, ?>) getFieldSpec()));
43: return getLoadedValue();
44: }
45:
46: /**
47: * Gets the entity class for which this is a lazy loading proxy.
48: *
49: * @return Proxied entity class
50: */
51: default Class<T> getProxiedClass() {
52:• assert getClass().getSuperclass() != null;
53: return (Class<T>) getClass().getSuperclass();
54: }
55:
56: /**
57: * Common implementation of {@link Object#toString()}.
58: *
59: * @return String representation of this proxy
60: */
61: default String stringify() {
62: return getClass().getSimpleName() + "[" + getOwner().getClass()
63: .getSimpleName() + "." + getFieldSpec().getName() + "]";
64: }
65: }