You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DATAMONGO-1726 - Add oneValue() and firstValue() to FluentMongoOperations returning nullable types.
We leave the choice of using Optional open by also providing terminating find operation methods that return null instead of Optional.
Original pull request: spring-projects#475.
Copy file name to clipboardExpand all lines: spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ExecutableFindOperationSupport.java
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -104,27 +104,27 @@ public TerminatingFindOperation<T> matching(Query query) {
104
104
}
105
105
106
106
@Override
107
-
publicOptional<T> one() {
107
+
publicToneValue() {
108
108
109
109
List<T> result = doFind(newDelegatingQueryCursorPreparer(getCursorPreparer(query, null)).limit(2));
110
110
111
111
if (ObjectUtils.isEmpty(result)) {
112
-
returnOptional.empty();
112
+
returnnull;
113
113
}
114
114
115
115
if (result.size() > 1) {
116
116
thrownewIncorrectResultSizeDataAccessException("Query " + asString() + " returned non unique result.", 1);
117
117
}
118
118
119
-
returnOptional.of(result.iterator().next());
119
+
returnresult.iterator().next();
120
120
}
121
121
122
122
@Override
123
-
publicOptional<T> first() {
123
+
publicTfirstValue() {
124
124
125
125
List<T> result = doFind(newDelegatingQueryCursorPreparer(getCursorPreparer(query, null)).limit(1));
Copy file name to clipboardExpand all lines: spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ExecutableFindOperationSupportTests.java
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -140,6 +140,30 @@ public void findByTooManyResults() {
0 commit comments