1515 */
1616package org .springframework .data .mongodb .core .convert ;
1717
18+ import static org .springframework .data .mongodb .core .convert .ReferenceLookupDelegate .*;
1819import static org .springframework .util .ReflectionUtils .*;
1920
2021import java .io .Serializable ;
2122import java .lang .reflect .Method ;
2223
23- import javax .annotation .Nonnull ;
24- import javax .annotation .Nullable ;
25-
2624import org .aopalliance .intercept .MethodInterceptor ;
2725import org .aopalliance .intercept .MethodInvocation ;
26+
2827import org .springframework .aop .framework .ProxyFactory ;
2928import org .springframework .cglib .proxy .Callback ;
3029import org .springframework .cglib .proxy .Enhancer ;
3130import org .springframework .cglib .proxy .Factory ;
3231import org .springframework .cglib .proxy .MethodProxy ;
33- import org .springframework .data .mongodb .core .convert .ReferenceResolver .LookupFunction ;
34- import org .springframework .data .mongodb .core .convert .ReferenceResolver .ResultConversionFunction ;
32+ import org .springframework .data .mongodb .core .convert .ReferenceResolver .MongoEntityReader ;
3533import org .springframework .data .mongodb .core .mapping .MongoPersistentProperty ;
34+ import org .springframework .lang .Nullable ;
3635import org .springframework .objenesis .ObjenesisStd ;
3736import org .springframework .util .ReflectionUtils ;
3837
3938/**
4039 * @author Christoph Strobl
4140 */
42- class LazyLoadingProxyGenerator {
41+ class LazyLoadingProxyFactory {
4342
4443 private final ObjenesisStd objenesis ;
45- private final ReferenceReader referenceReader ;
44+ private final ReferenceLookupDelegate lookupDelegate ;
4645
47- public LazyLoadingProxyGenerator ( ReferenceReader referenceReader ) {
46+ public LazyLoadingProxyFactory ( ReferenceLookupDelegate lookupDelegate ) {
4847
49- this .referenceReader = referenceReader ;
48+ this .lookupDelegate = lookupDelegate ;
5049 this .objenesis = new ObjenesisStd (true );
5150 }
5251
5352 public Object createLazyLoadingProxy (MongoPersistentProperty property , Object source , LookupFunction lookupFunction ,
54- ResultConversionFunction resultConversionFunction ) {
53+ MongoEntityReader entityReader ) {
5554
5655 Class <?> propertyType = property .getType ();
57- LazyLoadingInterceptor interceptor = new LazyLoadingInterceptor (property , source , referenceReader , lookupFunction ,
58- resultConversionFunction );
56+ LazyLoadingInterceptor interceptor = new LazyLoadingInterceptor (property , source , lookupDelegate , lookupFunction ,
57+ entityReader );
5958
6059 if (!propertyType .isInterface ()) {
6160
@@ -97,13 +96,13 @@ private Class<?> getEnhancedTypeFor(Class<?> type) {
9796 public static class LazyLoadingInterceptor
9897 implements MethodInterceptor , org .springframework .cglib .proxy .MethodInterceptor , Serializable {
9998
100- private final ReferenceReader referenceReader ;
101- MongoPersistentProperty property ;
99+ private final ReferenceLookupDelegate referenceLookupDelegate ;
100+ private final MongoPersistentProperty property ;
102101 private volatile boolean resolved ;
103- private @ org . springframework . lang . Nullable Object result ;
104- private Object source ;
105- private LookupFunction lookupFunction ;
106- private ResultConversionFunction resultConversionFunction ;
102+ private @ Nullable Object result ;
103+ private final Object source ;
104+ private final LookupFunction lookupFunction ;
105+ private final MongoEntityReader entityReader ;
107106
108107 private final Method INITIALIZE_METHOD , TO_DBREF_METHOD , FINALIZE_METHOD , GET_SOURCE_METHOD ;
109108
@@ -118,22 +117,23 @@ public static class LazyLoadingInterceptor
118117 }
119118 }
120119
121- public LazyLoadingInterceptor (MongoPersistentProperty property , Object source , ReferenceReader reader ,
122- LookupFunction lookupFunction , ResultConversionFunction resultConversionFunction ) {
120+ public LazyLoadingInterceptor (MongoPersistentProperty property , Object source , ReferenceLookupDelegate reader ,
121+ LookupFunction lookupFunction , MongoEntityReader entityReader ) {
123122
124123 this .property = property ;
125124 this .source = source ;
126- this .referenceReader = reader ;
125+ this .referenceLookupDelegate = reader ;
127126 this .lookupFunction = lookupFunction ;
128- this .resultConversionFunction = resultConversionFunction ;
127+ this .entityReader = entityReader ;
129128 }
130129
131130 @ Nullable
132131 @ Override
133- public Object invoke (@ Nonnull MethodInvocation invocation ) throws Throwable {
132+ public Object invoke (MethodInvocation invocation ) throws Throwable {
134133 return intercept (invocation .getThis (), invocation .getMethod (), invocation .getArguments (), null );
135134 }
136135
136+ @ Nullable
137137 @ Override
138138 public Object intercept (Object o , Method method , Object [] args , MethodProxy proxy ) throws Throwable {
139139
@@ -180,6 +180,7 @@ public Object intercept(Object o, Method method, Object[] args, MethodProxy prox
180180 return method .invoke (target , args );
181181 }
182182
183+ @ Nullable
183184 private Object ensureResolved () {
184185
185186 if (!resolved ) {
@@ -190,7 +191,7 @@ private Object ensureResolved() {
190191 return this .result ;
191192 }
192193
193- private String proxyToString (Object source ) {
194+ private String proxyToString (@ Nullable Object source ) {
194195
195196 StringBuilder description = new StringBuilder ();
196197 if (source != null ) {
@@ -203,7 +204,7 @@ private String proxyToString(Object source) {
203204 return description .toString ();
204205 }
205206
206- private boolean proxyEquals (@ org . springframework . lang . Nullable Object proxy , Object that ) {
207+ private boolean proxyEquals (@ Nullable Object proxy , Object that ) {
207208
208209 if (!(that instanceof LazyLoadingProxy )) {
209210 return false ;
@@ -216,11 +217,11 @@ private boolean proxyEquals(@org.springframework.lang.Nullable Object proxy, Obj
216217 return proxyToString (proxy ).equals (that .toString ());
217218 }
218219
219- private int proxyHashCode (@ org . springframework . lang . Nullable Object proxy ) {
220+ private int proxyHashCode (@ Nullable Object proxy ) {
220221 return proxyToString (proxy ).hashCode ();
221222 }
222223
223- @ org . springframework . lang . Nullable
224+ @ Nullable
224225 private synchronized Object resolve () {
225226
226227 if (resolved ) {
@@ -238,7 +239,7 @@ private synchronized Object resolve() {
238239 // property.getOwner() != null ? property.getOwner().getName() : "unknown", property.getName());
239240 // }
240241
241- return referenceReader .readReference (property , source , lookupFunction , resultConversionFunction );
242+ return referenceLookupDelegate .readReference (property , source , lookupFunction , entityReader );
242243
243244 } catch (RuntimeException ex ) {
244245 throw ex ;
@@ -254,4 +255,5 @@ private synchronized Object resolve() {
254255 }
255256 }
256257 }
258+
257259}
0 commit comments