Skip to content

Commit 0ff53bd

Browse files
christophstroblmp911de
authored andcommitted
DATACMNS-1058 - Alter QueryByExampleExecutor.findOne to return Optional<S>.
We now return Optional<S> for findOne() just as we do in CrudRepository. Original pull request: #214.
1 parent 5d08bd6 commit 0ff53bd

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/main/java/org/springframework/data/repository/query/QueryByExampleExecutor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
1515
*/
1616
package org.springframework.data.repository.query;
1717

18+
import java.util.Optional;
19+
1820
import org.springframework.data.domain.Example;
1921
import org.springframework.data.domain.Page;
2022
import org.springframework.data.domain.Pageable;
@@ -25,6 +27,7 @@
2527
*
2628
* @param <T>
2729
* @author Mark Paluch
30+
* @author Christoph Strobl
2831
* @since 1.12
2932
*/
3033
public interface QueryByExampleExecutor<T> {
@@ -33,10 +36,10 @@ public interface QueryByExampleExecutor<T> {
3336
* Returns a single entity matching the given {@link Example} or {@literal null} if none was found.
3437
*
3538
* @param example can be {@literal null}.
36-
* @return a single entity matching the given {@link Example} or {@literal null} if none was found.
39+
* @return a single entity matching the given {@link Example} or {@link Optional#empty()} if none was found.
3740
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException if the Example yields more than one result.
3841
*/
39-
<S extends T> S findOne(Example<S> example);
42+
<S extends T> Optional<S> findOne(Example<S> example);
4043

4144
/**
4245
* Returns all entities matching the given {@link Example}. In case no match could be found an empty {@link Iterable}

0 commit comments

Comments
 (0)