Skip to content

Commit 1b4edb3

Browse files
author
Thomas Risberg
committed
DATADOC-48 added new @RelatedDocument annotation
1 parent c8eb42a commit 1b4edb3

File tree

4 files changed

+42
-8
lines changed
  • spring-data-document-core/src/main/java/org/springframework/data/document/annotation
  • spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/mapping
  • spring-data-mongodb-cross-store/src

4 files changed

+42
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2011 by the original author(s).
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.data.document.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* @author Thomas Risberg
26+
*/
27+
@Retention(RetentionPolicy.RUNTIME)
28+
@Target({
29+
ElementType.FIELD
30+
})
31+
public @interface RelatedDocument {
32+
33+
String collection() default "";
34+
35+
}

spring-data-mongodb-cross-store/src/main/java/org/springframework/data/persistence/document/mongo/MongoDocumentBacking.aj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.aspectj.lang.JoinPoint;
1313
import org.aspectj.lang.reflect.FieldSignature;
1414

1515
import org.springframework.dao.DataAccessException;
16-
import org.springframework.data.document.mongodb.mapping.Document;
16+
import org.springframework.data.document.annotation.RelatedDocument;
1717

1818
import org.springframework.data.persistence.document.DocumentBacked;
1919
import org.springframework.data.persistence.document.DocumentBackedTransactionSynchronization;
@@ -47,7 +47,7 @@ public aspect MongoDocumentBacking {
4747
declare parents : (@Entity *) implements DocumentBacked;
4848

4949
// The annotated fields that will be persisted in MongoDB rather than with JPA
50-
declare @field: @Document * (@Entity+ *).*:@Transient;
50+
declare @field: @RelatedDocument * (@Entity+ *).*:@Transient;
5151

5252
// -------------------------------------------------------------------------
5353
// Advise user-defined constructors of ChangeSetBacked objects to create a new
@@ -65,12 +65,12 @@ public aspect MongoDocumentBacking {
6565
args(cs);
6666

6767
protected pointcut entityFieldGet(DocumentBacked entity) :
68-
get(@Document * DocumentBacked+.*) &&
68+
get(@RelatedDocument * DocumentBacked+.*) &&
6969
this(entity) &&
7070
!get(* DocumentBacked.*);
7171

7272
protected pointcut entityFieldSet(DocumentBacked entity, Object newVal) :
73-
set(@Document * DocumentBacked+.*) &&
73+
set(@RelatedDocument * DocumentBacked+.*) &&
7474
this(entity) &&
7575
args(newVal) &&
7676
!set(* DocumentBacked.*);

spring-data-mongodb-cross-store/src/test/java/org/springframework/data/document/persistence/test/Person.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import javax.persistence.Entity;
44
import javax.persistence.Id;
55

6-
import org.springframework.data.document.mongodb.mapping.Document;
6+
import org.springframework.data.document.annotation.RelatedDocument;
77

88
@Entity
99
public class Person {
@@ -17,7 +17,7 @@ public class Person {
1717

1818
private java.util.Date birthDate;
1919

20-
@Document
20+
@RelatedDocument
2121
public Resume resume;
2222

2323
public Person() {

spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/mapping/Document.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
@Persistent
3030
@Retention(RetentionPolicy.RUNTIME)
3131
@Target({
32-
ElementType.TYPE,
33-
ElementType.FIELD
32+
ElementType.TYPE
3433
})
3534
public @interface Document {
3635

0 commit comments

Comments
 (0)