Browse Source
This commit adds support for relational style One-To-Many references using a combination of ReadonlyProperty and @DocumentReference. It allows to link types without explicitly storing the linking values within the document itself. @Document class Publisher { @Id ObjectId id; // ... @ReadOnlyProperty @DocumentReference(lookup="{'publisherId':?#{#self._id} }") List<Book> books; } Closes: #3798 Original pull request: #3802.pull/3821/head
6 changed files with 218 additions and 19 deletions
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
/* |
||||
* Copyright 2021 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 |
||||
* |
||||
* https://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.lang.Nullable; |
||||
|
||||
/** |
||||
* The source object to resolve document references upon. Encapsulates the actual source and the reference specific |
||||
* values. |
||||
* |
||||
* @author Christoph Strobl |
||||
* @since 3.3 |
||||
*/ |
||||
public class DocumentReferenceSource { |
||||
|
||||
private final Object self; |
||||
|
||||
@Nullable private final Object targetSource; |
||||
|
||||
/** |
||||
* Create a new instance of {@link DocumentReferenceSource}. |
||||
* |
||||
* @param self the entire wrapper object holding references. Must not be {@literal null}. |
||||
* @param targetSource the reference value source. |
||||
*/ |
||||
DocumentReferenceSource(Object self, @Nullable Object targetSource) { |
||||
|
||||
this.self = self; |
||||
this.targetSource = targetSource; |
||||
} |
||||
|
||||
/** |
||||
* Get the outer document. |
||||
* |
||||
* @return never {@literal null}. |
||||
*/ |
||||
public Object getSelf() { |
||||
return self; |
||||
} |
||||
|
||||
/** |
||||
* Get the actual (property specific) reference value. |
||||
* |
||||
* @return can be {@literal null}. |
||||
*/ |
||||
@Nullable |
||||
public Object getTargetSource() { |
||||
return targetSource; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue