Switch MongoDB samples to records.

See #606.
This commit is contained in:
Mark Paluch
2021-04-28 15:18:59 +02:00
parent b44dc3dea1
commit e565f33872
69 changed files with 395 additions and 555 deletions

View File

@@ -45,11 +45,11 @@ public class ApplicationConfiguration {
*/
public @Bean AbstractRepositoryPopulatorFactoryBean repositoryPopulator() {
ObjectMapper mapper = new ObjectMapper();
var mapper = new ObjectMapper();
mapper.addMixIn(GeoJsonPoint.class, GeoJsonPointMixin.class);
mapper.configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
Jackson2RepositoryPopulatorFactoryBean factoryBean = new Jackson2RepositoryPopulatorFactoryBean();
var factoryBean = new Jackson2RepositoryPopulatorFactoryBean();
factoryBean.setResources(new Resource[] { new ClassPathResource("starbucks-in-nyc.json") });
factoryBean.setMapper(mapper);

View File

@@ -15,7 +15,7 @@
*/
package example.springdata.mongodb.geojson;
import lombok.Data;
import lombok.Value;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.data.mongodb.core.mapping.Document;
@@ -23,26 +23,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Christoph Strobl
*/
@Data
@Document(collection = "starbucks")
public class Store {
public record Store(String id, String name, String street, String city, GeoJsonPoint location) {
String id;
String name;
String street;
String city;
/**
* {@code location} is stored in GeoJSON format.
*
* <pre>
* <code>
* {
* "type" : "Point",
* "coordinates" : [ x, y ]
* }
* </code>
* </pre>
*/
GeoJsonPoint location;
}

View File

@@ -114,11 +114,11 @@ public class StoreRepositoryTests {
@Test
public void findStoresThatIntersectGivenPolygon() {
Document geoJsonDbo = new Document();
var geoJsonDbo = new Document();
operations.getConverter().write(GEO_JSON_POLYGON, geoJsonDbo);
BasicQuery bq = new BasicQuery(
var bq = new BasicQuery(
new Document("location", new Document("$geoIntersects", new Document("$geometry", geoJsonDbo))));
operations.find(bq, Store.class).forEach(System.out::println);