forked from mongodb/mongo-java-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance pre-and post-image support for change streams (mongodb#926)
Change stream watch helpers now accept "whenAvailable" and "required" for the fullDocument option. Additionally, a new fullDocumentBeforeChange option is introduced, which accepts "whenAvailable" and "required". Change events may now include a "fullDocumentBeforeChange" response field. JAVA-4468
- Loading branch information
Showing
24 changed files
with
1,325 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
driver-core/src/main/com/mongodb/client/model/changestream/FullDocumentBeforeChange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* 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 com.mongodb.client.model.changestream; | ||
|
||
import static com.mongodb.assertions.Assertions.assertNotNull; | ||
import static java.lang.String.format; | ||
|
||
/** | ||
* Change Stream fullDocumentBeforeChange configuration. | ||
* | ||
* <p> | ||
* Determines what to return for update operations when using a Change Stream. Defaults to {@link FullDocumentBeforeChange#DEFAULT}. | ||
* </p> | ||
* | ||
* @since 4.7 | ||
* @mongodb.server.release 6.0 | ||
*/ | ||
public enum FullDocumentBeforeChange { | ||
/** | ||
* The default value | ||
*/ | ||
DEFAULT("default"), | ||
|
||
/** | ||
* Configures the change stream to not include the pre-image of the modified document. | ||
*/ | ||
OFF("off"), | ||
|
||
/** | ||
* Configures the change stream to return the pre-image of the modified document for replace, update, and delete change events if it | ||
* is available. | ||
*/ | ||
WHEN_AVAILABLE("whenAvailable"), | ||
|
||
/** | ||
* The same behavior as {@link #WHEN_AVAILABLE} except that an error is raised by the server if the pre-image is not available. | ||
*/ | ||
REQUIRED("required"); | ||
|
||
|
||
private final String value; | ||
|
||
/** | ||
* The string value. | ||
* | ||
* @return the string value | ||
*/ | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
FullDocumentBeforeChange(final String value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Returns the FullDocumentBeforeChange from the string value. | ||
* | ||
* @param value the string value. | ||
* @return the full document before change | ||
*/ | ||
public static FullDocumentBeforeChange fromString(final String value) { | ||
assertNotNull(value); | ||
for (FullDocumentBeforeChange fullDocumentBeforeChange : FullDocumentBeforeChange.values()) { | ||
if (value.equals(fullDocumentBeforeChange.value)) { | ||
return fullDocumentBeforeChange; | ||
} | ||
} | ||
throw new IllegalArgumentException(format("'%s' is not a valid FullDocumentBeforeChange", value)); | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.