Skip to content

Commit c1de745

Browse files
Polishing.
Update javadoc, format imports and add issue references. Original Pull Request: #4193
1 parent aa35aae commit c1de745

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ChangeStreamEvent.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ public T getBody() {
162162
return getConvertedFullDocument(raw.getFullDocument());
163163
}
164164

165+
/**
166+
* Get the potentially converted {@link ChangeStreamDocument#getFullDocumentBeforeChange() document} before being changed.
167+
*
168+
* @return {@literal null} when {@link #getRaw()} or {@link ChangeStreamDocument#getFullDocumentBeforeChange()} is
169+
* {@literal null}.
170+
* @since 4.0
171+
*/
165172
@Nullable
166173
public T getBodyBeforeChange() {
167174

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ChangeStreamOptions.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.Arrays;
2020
import java.util.Optional;
2121

22-
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
2322
import org.bson.BsonDocument;
2423
import org.bson.BsonTimestamp;
2524
import org.bson.BsonValue;
@@ -33,6 +32,7 @@
3332

3433
import com.mongodb.client.model.changestream.ChangeStreamDocument;
3534
import com.mongodb.client.model.changestream.FullDocument;
35+
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
3636

3737
/**
3838
* Options applicable to MongoDB <a href="https://docs.mongodb.com/manual/changeStreams/">Change Streams</a>. Intended
@@ -79,6 +79,7 @@ public Optional<FullDocument> getFullDocumentLookup() {
7979

8080
/**
8181
* @return {@link Optional#empty()} if not set.
82+
* @since 4.0
8283
*/
8384
public Optional<FullDocumentBeforeChange> getFullDocumentBeforeChangeLookup() {
8485
return Optional.ofNullable(fullDocumentBeforeChangeLookup);
@@ -342,6 +343,7 @@ public ChangeStreamOptionsBuilder fullDocumentLookup(FullDocument lookup) {
342343
*
343344
* @param lookup must not be {@literal null}.
344345
* @return this.
346+
* @since 4.0
345347
*/
346348
public ChangeStreamOptionsBuilder fullDocumentBeforeChangeLookup(FullDocumentBeforeChange lookup) {
347349

@@ -351,6 +353,17 @@ public ChangeStreamOptionsBuilder fullDocumentBeforeChangeLookup(FullDocumentBef
351353
return this;
352354
}
353355

356+
/**
357+
* Return the full document before being changed if it is available.
358+
*
359+
* @return this.
360+
* @since 4.0
361+
* @see #fullDocumentBeforeChangeLookup(FullDocumentBeforeChange)
362+
*/
363+
public ChangeStreamOptionsBuilder returnFullDocumentBeforeChange() {
364+
return fullDocumentBeforeChangeLookup(FullDocumentBeforeChange.WHEN_AVAILABLE);
365+
}
366+
354367
/**
355368
* Set the cluster time to resume from.
356369
*

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/messaging/ChangeStreamRequest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.time.Duration;
1919
import java.time.Instant;
2020

21-
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
2221
import org.bson.BsonValue;
2322
import org.bson.Document;
2423
import org.springframework.data.mongodb.core.ChangeStreamOptions;
@@ -31,6 +30,7 @@
3130

3231
import com.mongodb.client.model.changestream.ChangeStreamDocument;
3332
import com.mongodb.client.model.changestream.FullDocument;
33+
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
3434

3535
/**
3636
* {@link SubscriptionRequest} implementation to be used for listening to
@@ -415,7 +415,6 @@ public ChangeStreamRequestBuilder<T> startAfter(BsonValue resumeToken) {
415415
* Set the {@link FullDocument} lookup to {@link FullDocument#UPDATE_LOOKUP}.
416416
*
417417
* @return this.
418-
* @see #fullDocumentLookup(FullDocument)
419418
* @see ChangeStreamOptions#getFullDocumentLookup()
420419
* @see ChangeStreamOptionsBuilder#fullDocumentLookup(FullDocument)
421420
*/
@@ -428,8 +427,10 @@ public ChangeStreamRequestBuilder<T> fullDocumentLookup(FullDocument lookup) {
428427
}
429428

430429
/**
430+
* Set the {@link FullDocumentBeforeChange} lookup to the given value.
431+
*
431432
* @return this.
432-
* @see #fullDocumentBeforeChangeLookup(FullDocumentBeforeChange) (FullDocumentBeforeChange)
433+
* @since 4.0
433434
* @see ChangeStreamOptions#getFullDocumentBeforeChangeLookup()
434435
* @see ChangeStreamOptionsBuilder#fullDocumentBeforeChangeLookup(FullDocumentBeforeChange)
435436
*/

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/messaging/ChangeStreamTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.Set;
2424
import java.util.concurrent.TimeUnit;
2525

26-
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
2726
import org.bson.BsonDocument;
2827
import org.bson.BsonTimestamp;
2928
import org.bson.BsonValue;
@@ -53,6 +52,7 @@
5352
import com.mongodb.client.model.Collation;
5453
import com.mongodb.client.model.changestream.ChangeStreamDocument;
5554
import com.mongodb.client.model.changestream.FullDocument;
55+
import com.mongodb.client.model.changestream.FullDocumentBeforeChange;
5656

5757
/**
5858
* {@link Task} implementation for obtaining {@link ChangeStreamDocument ChangeStreamDocuments} from MongoDB.
@@ -150,7 +150,7 @@ protected MongoCursor<ChangeStreamDocument<Document>> initCursor(MongoTemplate t
150150
}
151151

152152
if (startAt != null) {
153-
iterable.startAtOperationTime(startAt);
153+
iterable = iterable.startAtOperationTime(startAt);
154154
}
155155

156156
if (collation != null) {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/messaging/Message.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public interface Message<S, T> {
5757
* The converted message body before change if available.
5858
*
5959
* @return can be {@literal null}.
60+
* @since 4.0
6061
*/
6162
@Nullable
6263
default T getBodyBeforeChange() {

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/messaging/ChangeStreamTests.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ void filterOnUpdateDescriptionElement() throws InterruptedException {
541541
assertThat(messageBodies).hasSize(2);
542542
}
543543

544-
@Test // issue/41087
544+
@Test // GH-4187
545545
@EnableIfMongoServerVersion(isGreaterThanEqual = "6.0")
546546
void readsFullDocumentBeforeChangeWhenOptionDeclaredWhenAvailable() throws InterruptedException {
547547

@@ -571,7 +571,7 @@ void readsFullDocumentBeforeChangeWhenOptionDeclaredWhenAvailable() throws Inter
571571
assertThat(messageListener.getLastMessage().getBody()).isEqualTo(jellyBelly.withAge(8));
572572
}
573573

574-
@Test // issue/41087
574+
@Test // GH-4187
575575
@EnableIfMongoServerVersion(isGreaterThanEqual = "6.0")
576576
void readsFullDocumentBeforeChangeWhenOptionDeclaredRequired() throws InterruptedException {
577577

@@ -601,7 +601,7 @@ void readsFullDocumentBeforeChangeWhenOptionDeclaredRequired() throws Interrupte
601601
assertThat(messageListener.getLastMessage().getBody()).isEqualTo(jellyBelly.withAge(8));
602602
}
603603

604-
@Test // issue/41087
604+
@Test // GH-4187
605605
@EnableIfMongoServerVersion(isGreaterThanEqual = "6.0")
606606
void readsFullDocumentBeforeChangeWhenOptionIsNotDeclared() throws InterruptedException {
607607

@@ -626,7 +626,7 @@ void readsFullDocumentBeforeChangeWhenOptionIsNotDeclared() throws InterruptedEx
626626
assertThat(messageListener.getLastMessage().getBodyBeforeChange()).isNull();
627627
}
628628

629-
@Test // issue/41087
629+
@Test // GH-4187
630630
@EnableIfMongoServerVersion(isGreaterThanEqual = "6.0")
631631
void readsFullDocumentBeforeChangeWhenOptionDeclaredDefault() throws InterruptedException {
632632

@@ -651,7 +651,7 @@ void readsFullDocumentBeforeChangeWhenOptionDeclaredDefault() throws Interrupted
651651
assertThat(messageListener.getLastMessage().getBodyBeforeChange()).isNull();
652652
}
653653

654-
@Test // issue/41087
654+
@Test // GH-4187
655655
@EnableIfMongoServerVersion(isGreaterThanEqual = "6.0")
656656
void readsFullDocumentBeforeChangeWhenOptionDeclaredOff() throws InterruptedException {
657657

@@ -676,7 +676,7 @@ void readsFullDocumentBeforeChangeWhenOptionDeclaredOff() throws InterruptedExce
676676
assertThat(messageListener.getLastMessage().getBodyBeforeChange()).isNull();
677677
}
678678

679-
@Test // issue/41087
679+
@Test // GH-4187
680680
@EnableIfMongoServerVersion(isGreaterThanEqual = "6.0")
681681
void readsFullDocumentBeforeChangeWhenOptionDeclaredWhenAvailableAndChangeStreamPreAndPostImagesDisabled()
682682
throws InterruptedException {
@@ -700,7 +700,7 @@ void readsFullDocumentBeforeChangeWhenOptionDeclaredWhenAvailableAndChangeStream
700700
assertThat(messageListener.getLastMessage().getBodyBeforeChange()).isNull();
701701
}
702702

703-
@Test // issue/41087
703+
@Test // GH-4187
704704
@EnableIfMongoServerVersion(isLessThan = "6.0")
705705
void readsFullDocumentBeforeChangeWhenOptionDeclaredRequiredAndMongoVersionIsLessThan6() throws InterruptedException {
706706

@@ -739,6 +739,7 @@ static class User {
739739
Address address;
740740

741741
User withAge(int age) {
742+
742743
User user = new User();
743744
user.id = id;
744745
user.userName = userName;

0 commit comments

Comments
 (0)