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: package cz.cvut.kbss.jopa.proxy.lazy.gen;
2:
3: import cz.cvut.kbss.jopa.exception.LazyLoadingException;
4: import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
5: import cz.cvut.kbss.jopa.proxy.lazy.LazyLoadingProxy;
6:
7: /**
8: * Implemented by generated lazy loading entity proxy classes.
9: * <p>
10: * It defines the default method for triggering lazy loading.
11: *
12: * @param <T> Type of the lazily-loaded value
13: */
14:•public interface LazyLoadingEntityProxy<T> extends LazyLoadingProxyPropertyAccessor<T>, LazyLoadingProxy<T> {
15:
16: @Override
17: default T triggerLazyLoading() {
18:• if (isLoaded()) {
19: return getLoadedValue();
20: }
21:• if (getPersistenceContext() == null || !getPersistenceContext().isActive()) {
22: throw new LazyLoadingException("No active persistence context is available in lazy loading proxy for attribute "
23: + getFieldSpec() + " of entity " + getOwner());
24: }
25: setValue((T) getPersistenceContext().loadEntityField(getOwner(), (FieldSpecification<? super Object, ?>) getFieldSpec()));
26: return getLoadedValue();
27: }
28:
29: /**
30: * Gets the entity class for which this is a lazy loading proxy.
31: *
32: * @return Proxied entity class
33: */
34: default Class<T> getProxiedClass() {
35:• assert getClass().getSuperclass() != null;
36: return (Class<T>) getClass().getSuperclass();
37: }
38:
39: /**
40: * Common implementation of {@link Object#toString()}.
41: *
42: * @return String representation of this proxy
43: */
44: default String stringify() {
45: return getClass().getSimpleName() + "[" + getOwner().getClass()
46: .getSimpleName() + "." + getFieldSpec().getName() + "]";
47: }
48: }