/driver-core/src/main/com/mongodb/client/model/changestream/FullDocumentBeforeChange.java

https://github.com/jyemin/mongo-java-driver · Java · 84 lines · 24 code · 11 blank · 49 comment · 2 complexity · d6045798c15997ac828cef1ab30ca637 MD5 · raw file

  1. /*
  2. * Copyright 2008-present MongoDB, Inc.
  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. package com.mongodb.client.model.changestream;
  17. import static com.mongodb.assertions.Assertions.assertNotNull;
  18. import static java.lang.String.format;
  19. /**
  20. * Change Stream fullDocumentBeforeChange configuration.
  21. *
  22. * <p>
  23. * Determines what to return for update operations when using a Change Stream. Defaults to {@link FullDocumentBeforeChange#DEFAULT}.
  24. * </p>
  25. *
  26. * @since 4.7
  27. * @mongodb.server.release 6.0
  28. */
  29. public enum FullDocumentBeforeChange {
  30. /**
  31. * The default value
  32. */
  33. DEFAULT("default"),
  34. /**
  35. * Configures the change stream to not include the pre-image of the modified document.
  36. */
  37. OFF("off"),
  38. /**
  39. * Configures the change stream to return the pre-image of the modified document for replace, update, and delete change events if it
  40. * is available.
  41. */
  42. WHEN_AVAILABLE("whenAvailable"),
  43. /**
  44. * The same behavior as {@link #WHEN_AVAILABLE} except that an error is raised by the server if the pre-image is not available.
  45. */
  46. REQUIRED("required");
  47. private final String value;
  48. /**
  49. * The string value.
  50. *
  51. * @return the string value
  52. */
  53. public String getValue() {
  54. return value;
  55. }
  56. FullDocumentBeforeChange(final String value) {
  57. this.value = value;
  58. }
  59. /**
  60. * Returns the FullDocumentBeforeChange from the string value.
  61. *
  62. * @param value the string value.
  63. * @return the full document before change
  64. */
  65. public static FullDocumentBeforeChange fromString(final String value) {
  66. assertNotNull(value);
  67. for (FullDocumentBeforeChange fullDocumentBeforeChange : FullDocumentBeforeChange.values()) {
  68. if (value.equals(fullDocumentBeforeChange.value)) {
  69. return fullDocumentBeforeChange;
  70. }
  71. }
  72. throw new IllegalArgumentException(format("'%s' is not a valid FullDocumentBeforeChange", value));
  73. }}