Merge Java 8 samples into basic one.

This commit is contained in:
Mark Paluch
2021-04-28 10:57:59 +02:00
parent 20dfd398c8
commit b44dc3dea1
24 changed files with 44 additions and 286 deletions

View File

@@ -16,11 +16,13 @@
package example.springdata.mongodb.customer;
import java.util.List;
import java.util.stream.Stream;
import org.springframework.data.domain.Sort;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.CrudRepository;
/**
@@ -47,4 +49,7 @@ public interface CustomerRepository extends CrudRepository<Customer, String> {
* @return
*/
GeoResults<Customer> findByAddressLocationNear(Point point, Distance distance);
@Query("{}")
Stream<Customer> findAllByCustomQueryWithStream();
}

View File

@@ -19,6 +19,7 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
@@ -82,6 +83,17 @@ public class CustomerRepositoryIntegrationTest {
assertThat(result.get(1), is(oliver));
}
/**
* Test case to show the usage of Java {@link Stream}.
*/
@Test
public void findCustomersAsStream() {
try (Stream<Customer> result = repository.findAllByCustomQueryWithStream()) {
result.forEach(System.out::println);
}
}
/**
* Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of a reference point.
*/