Browse Source
Added LazyLoadingProxy interface that will be implemented by every LazyLoading-proxy that is created by the DefaultDbRefResolver. Clients can now cast those proxies to this interface and call it's methods initialize a proxy explicitly or to get the referenced DBRef if possible. We now keep a reference to the DBRef that lead to the creation of a LazyLoadingProxy in order to be able to reuse it in case one assigns the proxy to a field that should be a DBRef. This avoids unnecessary conversion. Previously saving of proxies wasn't possible since the mapping infrastructure did not know how to extract the entity information from the proxy. We now either store the DBRef backed by the proxy directly or we initialize the proxy first and use the result of LazyLoadingProxy.initialize(). Original pull request: #151.pull/155/head
5 changed files with 172 additions and 10 deletions
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
/* |
||||
* Copyright 2014 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
package org.springframework.data.mongodb.core.convert; |
||||
|
||||
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver.LazyLoadingInterceptor; |
||||
|
||||
import com.mongodb.DBRef; |
||||
|
||||
/** |
||||
* Allows direct interaction with the underlying {@link LazyLoadingInterceptor}. |
||||
* |
||||
* @author Thomas Darimont |
||||
* @since 1.5 |
||||
*/ |
||||
public interface LazyLoadingProxy { |
||||
|
||||
/** |
||||
* Initializes the proxy and returns the wrapped value. |
||||
* |
||||
* @return |
||||
* @since 1.5 |
||||
*/ |
||||
Object initialize(); |
||||
|
||||
/** |
||||
* Returns the {@link DBRef} represented by this {@link LazyLoadingProxy}, may be null. |
||||
* |
||||
* @return |
||||
* @since 1.5 |
||||
*/ |
||||
DBRef toDBRef(); |
||||
} |
||||
Loading…
Reference in new issue