diff --git a/jpa/query-by-example/pom.xml b/jpa/query-by-example/pom.xml
index 0a2ee143..351caaf8 100644
--- a/jpa/query-by-example/pom.xml
+++ b/jpa/query-by-example/pom.xml
@@ -10,5 +10,9 @@
spring-data-jpa-query-by-example
Spring Data JPA - Query-by-Example (QBE)
+
+
+ Hopper-BUILD-SNAPSHOT
+
diff --git a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/SpecialUser.java b/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/SpecialUser.java
index 5b46915b..8b54418a 100644
--- a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/SpecialUser.java
+++ b/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/SpecialUser.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.jpa.querybyexample;
import lombok.Data;
@@ -25,6 +24,7 @@ import javax.persistence.Entity;
* Sample class that extends {@link User}.
*
* @author Mark Paluch
+ * @author Oliver Gierke
*/
@Entity
@Data
diff --git a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/User.java b/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/User.java
index fc5d7a1a..c8862a57 100644
--- a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/User.java
+++ b/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/User.java
@@ -15,36 +15,27 @@
*/
package example.springdata.jpa.querybyexample;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.RequiredArgsConstructor;
+
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
/**
* Sample user class.
*
* @author Mark Paluch
+ * @author Oliver Gierke
*/
@Entity
@Data
-@NoArgsConstructor
+@NoArgsConstructor(force = true)
+@RequiredArgsConstructor
public class User {
- @Id @GeneratedValue //
- private Long id;
- private String firstname;
- private String lastname;
- private Integer age;
-
- public User(String firstname, String lastname, Integer age) {
-
- super();
-
- this.firstname = firstname;
- this.lastname = lastname;
- this.age = age;
- }
-
+ private @Id @GeneratedValue Long id;
+ private final String firstname, lastname;
+ private final Integer age;
}
diff --git a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/UserRepository.java b/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/UserRepository.java
index f5decc44..4f648d6b 100644
--- a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/UserRepository.java
+++ b/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/UserRepository.java
@@ -24,6 +24,4 @@ import org.springframework.data.repository.query.QueryByExampleExecutor;
*
* @author Mark Paluch
*/
-public interface UserRepository extends CrudRepository, QueryByExampleExecutor {
-
-}
+public interface UserRepository extends CrudRepository, QueryByExampleExecutor {}
diff --git a/jpa/query-by-example/src/main/resources/application.properties b/jpa/query-by-example/src/main/resources/application.properties
deleted file mode 100644
index d98d035f..00000000
--- a/jpa/query-by-example/src/main/resources/application.properties
+++ /dev/null
@@ -1 +0,0 @@
-spring.datasource.separator=/;
\ No newline at end of file
diff --git a/jpa/query-by-example/src/main/resources/logback.xml b/jpa/query-by-example/src/main/resources/logback.xml
deleted file mode 100644
index 40a8f339..00000000
--- a/jpa/query-by-example/src/main/resources/logback.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
- %d %5p %40.40c:%4L - %m%n
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java
similarity index 61%
rename from jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java
rename to jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java
index 2f3006ff..390f1390 100644
--- a/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java
+++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java
@@ -15,18 +15,11 @@
*/
package example.springdata.jpa.querybyexample;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.orm.jpa.EntityScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author Mark Paluch
+ * @author Oliver Gierke
*/
-@Configuration
-@EnableAutoConfiguration
-@EntityScan(basePackageClasses = { ApplicationConfiguration.class })
-@EnableJpaAuditing
-public class ApplicationConfiguration {
-
-}
+@SpringBootApplication
+public class ApplicationConfiguration {}
diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java
index 1d8f2cf4..04784ba8 100644
--- a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java
+++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java
@@ -13,13 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.jpa.querybyexample;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.*;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.startsWith;
import org.junit.Before;
import org.junit.Test;
@@ -27,14 +24,15 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleSpec;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
/**
- * Integration test showing the usage of JPA Query-by-Example support through Spring Data repositories.
+ * Integration test showing the usage of JPA Query-by-Example support through Spring Data repositories and entities
+ * using inheritance.
*
* @author Mark Paluch
+ * @author Oliver Gierke
*/
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@@ -56,38 +54,18 @@ public class UserRepositoryInheritanceIntegrationTests {
}
/**
- * @see DATAJPA-218
+ * @see #153
*/
@Test
- public void countBySimpleExample() {
-
- Example example = Example.of(new SpecialUser(null, "White", null));
-
- assertThat(repository.count(example), is(3L));
+ public void countByExample() {
+ assertThat(repository.count(Example.of(new User(null, "White", null))), is(3L));
}
/**
- * @see DATAJPA-218
+ * @see #153
*/
@Test
- public void countUserByTypedExample() {
-
- Example example = Example.of(new SpecialUser(null, "White", null), //
- ExampleSpec.typed(User.class));
-
- assertThat(repository.count(example), is(3L));
+ public void countSubtypesByExample() {
+ assertThat(repository.count(Example.of(new SpecialUser(null, "White", null))), is(2L));
}
-
- /**
- * @see DATAJPA-218
- */
- @Test
- public void countSpecialUserByTypedExample() {
-
- Example example = Example.of(new SpecialUser(null, "White", null), //
- ExampleSpec.typed(SpecialUser.class));
-
- assertThat(repository.count(example), is(2L));
- }
-
}
diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java
index 4a784f2b..8f0f43fb 100644
--- a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java
+++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java
@@ -17,8 +17,9 @@ package example.springdata.jpa.querybyexample;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.*;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.startsWith;
+import static org.springframework.data.domain.ExampleMatcher.*;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
import org.junit.Before;
import org.junit.Test;
@@ -26,7 +27,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleSpec;
+import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
@@ -34,101 +35,104 @@ import org.springframework.transaction.annotation.Transactional;
* Integration test showing the usage of JPA Query-by-Example support through Spring Data repositories.
*
* @author Mark Paluch
+ * @author Oliver Gierke
*/
+@SuppressWarnings("unused")
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
@SpringApplicationConfiguration(classes = ApplicationConfiguration.class)
public class UserRepositoryIntegrationTests {
- @Autowired
- UserRepository repository;
+ @Autowired UserRepository repository;
- User skyler, walter, flynn, marie, hank;
+ User skyler, walter, flynn, marie, hank;
- @Before
- public void setUp() {
+ @Before
+ public void setUp() {
- repository.deleteAll();
+ repository.deleteAll();
- this.skyler = repository.save(new User("Skyler", "White", 45));
- this.walter = repository.save(new User("Walter", "White", 50));
- this.flynn = repository.save(new User("Walter Jr. (Flynn)", "White", 17));
- this.marie = repository.save(new User("Marie", "Schrader", 38));
- this.hank = repository.save(new User("Hank", "Schrader", 43));
- }
+ this.skyler = repository.save(new User("Skyler", "White", 45));
+ this.walter = repository.save(new User("Walter", "White", 50));
+ this.flynn = repository.save(new User("Walter Jr. (Flynn)", "White", 17));
+ this.marie = repository.save(new User("Marie", "Schrader", 38));
+ this.hank = repository.save(new User("Hank", "Schrader", 43));
+ }
- /**
- * @see DATAJPA-218
- */
- @Test
- public void countBySimpleExample() {
+ /**
+ * @see #153
+ */
+ @Test
+ public void countBySimpleExample() {
- Example example = Example.of(new User(null, "White", null));
+ Example example = Example.of(new User(null, "White", null));
- assertThat(repository.count(example), is(3L));
- }
+ assertThat(repository.count(example), is(3L));
+ }
- /**
- * @see DATAJPA-218
- */
- @Test
- public void ignorePropertiesAndMatchByAge() {
+ /**
+ * @see #153
+ */
+ @Test
+ public void ignorePropertiesAndMatchByAge() {
- ExampleSpec exampleSpec = ExampleSpec.untyped(). //
- withIgnorePaths("firstname", "lastname");
+ Example example = Example.of(flynn, matching().//
+ withIgnorePaths("firstname", "lastname"));
- assertThat(repository.findOne(Example.of(flynn, exampleSpec)), is(flynn));
- }
+ assertThat(repository.findOne(example), is(flynn));
+ }
- /**
- * @see DATAJPA-218
- */
- @Test
- public void substringMatching() {
+ /**
+ * @see #153
+ */
+ @Test
+ public void substringMatching() {
- ExampleSpec exampleSpec = ExampleSpec.untyped().//
- withStringMatcherEnding();
+ Example example = Example.of(new User("er", null, null), matching().//
+ withStringMatcher(StringMatcher.ENDING));
- assertThat(repository.findAll(Example.of(new User("er", null, null), exampleSpec)), hasItems(skyler, walter));
- }
+ assertThat(repository.findAll(example), hasItems(skyler, walter));
+ }
- /**
- * @see DATAJPA-218
- */
- @Test
- public void matchStartingStringsIgnoreCase() {
+ /**
+ * @see #153
+ */
+ @Test
+ public void matchStartingStringsIgnoreCase() {
- ExampleSpec exampleSpec = ExampleSpec.untyped(). //
- withIgnorePaths("age").//
- withMatcher("firstname", startsWith()).//
- withMatcher("lastname", ignoreCase());
+ Example example = Example.of(new User("Walter", "WHITE", null),
+ matching().//
+ withIgnorePaths("age").//
+ withMatcher("firstname", startsWith()).//
+ withMatcher("lastname", ignoreCase()));
- assertThat(repository.findAll(Example.of(new User("Walter", "WHITE", null), exampleSpec)), hasItems(flynn, walter));
- }
+ assertThat(repository.findAll(example), hasItems(flynn, walter));
+ }
- /**
- * @see DATAJPA-218
- */
- @Test
- public void configuringMatchersUsingLambdas() {
+ /**
+ * @see #153
+ */
+ @Test
+ public void configuringMatchersUsingLambdas() {
- ExampleSpec exampleSpec = ExampleSpec.untyped().withIgnorePaths("age"). //
- withMatcher("firstname", matcher -> matcher.startsWith()). //
- withMatcher("lastname", matcher -> matcher.ignoreCase());
+ Example example = Example.of(new User("Walter", "WHITE", null),
+ matching().//
+ withIgnorePaths("age").//
+ withMatcher("firstname", matcher -> matcher.startsWith()).//
+ withMatcher("lastname", matcher -> matcher.ignoreCase()));
- assertThat(repository.findAll(Example.of(new User("Walter", "WHITE", null), exampleSpec)), hasItems(flynn, walter));
- }
+ assertThat(repository.findAll(example), hasItems(flynn, walter));
+ }
- /**
- * @see DATAJPA-218
- */
- @Test
- public void valueTransformer() {
+ /**
+ * @see #153
+ */
+ @Test
+ public void valueTransformer() {
- ExampleSpec exampleSpec = ExampleSpec.untyped(). //
- withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)));
-
- assertThat(repository.findAll(Example.of(new User(null, "White", 99), exampleSpec)), hasItems(walter));
- }
+ Example example = Example.of(new User(null, "White", 99), matching(). //
+ withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
+ assertThat(repository.findAll(example), hasItems(walter));
+ }
}
diff --git a/mongodb/query-by-example/pom.xml b/mongodb/query-by-example/pom.xml
index a0652f4c..f723882d 100644
--- a/mongodb/query-by-example/pom.xml
+++ b/mongodb/query-by-example/pom.xml
@@ -11,4 +11,8 @@
spring-data-mongodb-query-by-example
Spring Data MongoDB - Query-by-Example (QBE)
+
+ Hopper-BUILD-SNAPSHOT
+
+
diff --git a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Contact.java b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Contact.java
index 90d4651e..c8aaf681 100644
--- a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Contact.java
+++ b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Contact.java
@@ -13,30 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.mongodb.querybyexample;
-import lombok.Data;
-import lombok.RequiredArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.ToString;
import org.bson.types.ObjectId;
-import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
- * Sample contact class.
- *
- * @author Mark Paluch
+ * @author Oliver Gierke
*/
-@Data
-@RequiredArgsConstructor
-@Document(collection = "collectionStoringTwoTypes")
-public class Contact {
-
- @Id //
- private ObjectId id;
- private final String firstname;
- private final String lastname;
- private final Integer age;
+@Document(collection = "contacts")
+@EqualsAndHashCode
+@ToString
+public abstract class Contact {
+ private @Getter ObjectId id;
}
diff --git a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ContactRepository.java b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ContactRepository.java
index 6c7083e5..3b949379 100644
--- a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ContactRepository.java
+++ b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ContactRepository.java
@@ -13,18 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.mongodb.querybyexample;
+import org.bson.types.ObjectId;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;
/**
- * Simple repository interface for {@link Contact} instances. The interface implements {@link QueryByExampleExecutor} and
- * allows execution of methods accepting {@link org.springframework.data.domain.Example}.
- *
- * @author Mark Paluch
+ * Repository interface for {@link Contact} and sub-types.
+ *
+ * @author Oliver Gierke
*/
-public interface ContactRepository extends CrudRepository, QueryByExampleExecutor {
-
-}
+public interface ContactRepository extends CrudRepository, QueryByExampleExecutor {}
diff --git a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/User.java b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Person.java
similarity index 74%
rename from mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/User.java
rename to mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Person.java
index 56b84fe7..fc6db79f 100644
--- a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/User.java
+++ b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Person.java
@@ -13,31 +13,24 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.mongodb.querybyexample;
-import lombok.Data;
-import lombok.NoArgsConstructor;
+import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.bson.types.ObjectId;
-import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* Sample user class.
*
* @author Mark Paluch
+ * @author Oliver Gierke
*/
-@Data
+@Getter
@RequiredArgsConstructor
-@Document(collection = "collectionStoringTwoTypes")
-public class User {
+@Document(collection = "contacts")
+public class Person extends Contact {
- @Id //
- private ObjectId id;
- private final String firstname;
- private final String lastname;
+ private final String firstname, lastname;
private final Integer age;
-
}
diff --git a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Relative.java b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Relative.java
new file mode 100644
index 00000000..ad6f0979
--- /dev/null
+++ b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/Relative.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package example.springdata.mongodb.querybyexample;
+
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
+import org.springframework.data.mongodb.core.mapping.Document;
+
+/**
+ * Sample contact class.
+ *
+ * @author Mark Paluch
+ * @author Oliver Gierke
+ */
+@Getter
+@RequiredArgsConstructor
+@Document(collection = "contacts")
+public class Relative extends Contact {
+
+ private final String firstname, lastname;
+ private final Integer age;
+}
diff --git a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/RelativeRepository.java b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/RelativeRepository.java
new file mode 100644
index 00000000..c713f074
--- /dev/null
+++ b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/RelativeRepository.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package example.springdata.mongodb.querybyexample;
+
+import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+/**
+ * Simple repository interface for {@link Relative} instances. The interface implements {@link QueryByExampleExecutor}
+ * and allows execution of methods accepting {@link org.springframework.data.domain.Example}.
+ *
+ * @author Mark Paluch
+ */
+public interface RelativeRepository extends CrudRepository, QueryByExampleExecutor {}
diff --git a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/UserRepository.java b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/UserRepository.java
index 14241543..1bf27719 100644
--- a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/UserRepository.java
+++ b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/UserRepository.java
@@ -13,18 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.mongodb.querybyexample;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.QueryByExampleExecutor;
/**
- * Simple repository interface for {@link User} instances. The interface implements {@link QueryByExampleExecutor} and
+ * Simple repository interface for {@link Person} instances. The interface implements {@link QueryByExampleExecutor} and
* allows execution of methods accepting {@link org.springframework.data.domain.Example}.
*
* @author Mark Paluch
*/
-public interface UserRepository extends CrudRepository, QueryByExampleExecutor {
-
-}
+public interface UserRepository extends CrudRepository, QueryByExampleExecutor {}
diff --git a/mongodb/query-by-example/src/main/resources/logback.xml b/mongodb/query-by-example/src/main/resources/logback.xml
deleted file mode 100644
index 40a8f339..00000000
--- a/mongodb/query-by-example/src/main/resources/logback.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
- %d %5p %40.40c:%4L - %m%n
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java
similarity index 94%
rename from mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java
rename to mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java
index 3b121ff6..6993de3f 100644
--- a/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java
+++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.mongodb.querybyexample;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@@ -22,6 +21,4 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @author Mark Paluch
*/
@SpringBootApplication
-public class ApplicationConfiguration {
-
-}
+public class ApplicationConfiguration {}
diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java
index b3a87af6..01105e34 100644
--- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java
+++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.mongodb.querybyexample;
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
+import static org.springframework.data.domain.ExampleMatcher.*;
import org.junit.Before;
import org.junit.Test;
@@ -26,16 +27,16 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleSpec;
-import org.springframework.data.domain.ExampleSpec.StringMatcher;
+import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.data.mongodb.core.MongoOperations;
-import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
- * Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories for a case where two domain types are stored in one collection.
+ * Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories for a case
+ * where two domain types are stored in one collection.
*
* @author Mark Paluch
+ * @author Oliver Gierke
* @soundtrack Paul van Dyk - VONYC Sessions Episode 496 with guest Armin van Buuren
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -46,69 +47,55 @@ public class ContactRepositoryIntegrationTests {
@Autowired ContactRepository contactRepository;
@Autowired MongoOperations mongoOperations;
- User skyler, walter, flynn;
- Contact marie, hank;
+ Person skyler, walter, flynn;
+ Relative marie, hank;
@Before
public void setUp() {
- userRepository.deleteAll();
+ contactRepository.deleteAll();
- this.skyler = userRepository.save(new User("Skyler", "White", 45));
- this.walter = userRepository.save(new User("Walter", "White", 50));
- this.flynn = userRepository.save(new User("Walter Jr. (Flynn)", "White", 17));
- this.marie = contactRepository.save(new Contact("Marie", "Schrader", 38));
- this.hank = contactRepository.save(new Contact("Hank", "Schrader", 43));
+ this.skyler = contactRepository.save(new Person("Skyler", "White", 45));
+ this.walter = contactRepository.save(new Person("Walter", "White", 50));
+ this.flynn = contactRepository.save(new Person("Walter Jr. (Flynn)", "White", 17));
+ this.marie = contactRepository.save(new Relative("Marie", "Schrader", 38));
+ this.hank = contactRepository.save(new Relative("Hank", "Schrader", 43));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
- public void countUsersByUntypedExample() {
+ public void countByConcreteSubtypeExample() {
- Example example = Example.of(new User(null, null, null));
-
- // the count is 5 because untyped examples do not restrict the type
- assertThat(userRepository.count(example), is(5L));
- assertThat(mongoOperations.count(new Query(), "collectionStoringTwoTypes"), is(5L));
- }
-
- /**
- * @see DATAMONGO-1245
- */
- @Test
- public void countByTypedExample() {
-
- Example example = Example.of(new User(null, null, null), ExampleSpec.typed(User.class));
+ Example example = Example.of(new Person(null, null, null));
assertThat(userRepository.count(example), is(3L));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
- public void findAllUsersBySimpleExample() {
+ public void findAllPersonsBySimpleExample() {
- Example example = Example.of(new User(".*", null, null), //
- ExampleSpec.typed(User.class).withStringMatcher(StringMatcher.REGEX));
+ Example example = Example.of(new Person(".*", null, null), //
+ matching().withStringMatcher(StringMatcher.REGEX));
assertThat(userRepository.findAll(example), containsInAnyOrder(skyler, walter, flynn));
assertThat(userRepository.findAll(example), not(containsInAnyOrder(hank, marie)));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
- public void findAllContactsBySimpleExample() {
+ public void findAllRelativesBySimpleExample() {
- Example example = Example.of(new Contact(".*", null, null), //
- ExampleSpec.typed(Contact.class).withStringMatcher(StringMatcher.REGEX));
+ Example example = Example.of(new Relative(".*", null, null), //
+ matching().withStringMatcher(StringMatcher.REGEX));
assertThat(contactRepository.findAll(example), containsInAnyOrder(hank, marie));
assertThat(contactRepository.findAll(example), not(containsInAnyOrder(skyler, walter, flynn)));
}
-
}
diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java
index fb2a2bde..b403b49b 100644
--- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java
+++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java
@@ -18,8 +18,11 @@ package example.springdata.mongodb.querybyexample;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.*;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.startsWith;
+import static org.springframework.data.domain.ExampleMatcher.*;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
+import static org.springframework.data.mongodb.core.query.Criteria.*;
+import static org.springframework.data.mongodb.core.query.Query.*;
import org.junit.Before;
import org.junit.Test;
@@ -27,8 +30,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleSpec;
-import org.springframework.data.domain.TypedExampleSpec;
+import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -37,25 +39,27 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories.
*
* @author Mark Paluch
+ * @author Oliver Gierke
*/
+@SuppressWarnings("unused")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ApplicationConfiguration.class)
public class MongoOperationsIntegrationTests {
@Autowired MongoOperations operations;
- User skyler, walter, flynn, marie, hank;
+ Person skyler, walter, flynn, marie, hank;
@Before
public void setUp() {
- operations.remove(new Query(), User.class);
+ operations.remove(new Query(), Person.class);
- this.skyler = new User("Skyler", "White", 45);
- this.walter = new User("Walter", "White", 50);
- this.flynn = new User("Walter Jr. (Flynn)", "White", 17);
- this.marie = new User("Marie", "Schrader", 38);
- this.hank = new User("Hank", "Schrader", 43);
+ this.skyler = new Person("Skyler", "White", 45);
+ this.walter = new Person("Walter", "White", 50);
+ this.flynn = new Person("Walter Jr. (Flynn)", "White", 17);
+ this.marie = new Person("Marie", "Schrader", 38);
+ this.hank = new Person("Hank", "Schrader", 43);
operations.save(this.skyler);
operations.save(this.walter);
@@ -65,78 +69,79 @@ public class MongoOperationsIntegrationTests {
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void ignoreNullProperties() {
- assertThat(operations.findByExample(new User(null, null, 17)), hasItems(flynn));
+ Query query = query(byExample(new Person(null, null, 17)));
+
+ assertThat(operations.find(query, Person.class), hasItems(flynn));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void substringMatching() {
- TypedExampleSpec exampleSpec = ExampleSpec.typed(User.class).//
- withStringMatcherEnding();
+ Example example = Example.of(new Person("er", null, null), matching().//
+ withStringMatcher(StringMatcher.ENDING));
- assertThat(operations.findByExample(Example.of(new User("er", null, null), exampleSpec)), hasItems(skyler, walter));
+ assertThat(operations.find(query(byExample(example)), Person.class), hasItems(skyler, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #154
*/
@Test
public void regexMatching() {
- TypedExampleSpec exampleSpec = ExampleSpec.typed(User.class).//
- withMatcher("firstname", matcher -> matcher.regex());
+ Example example = Example.of(new Person("(Skyl|Walt)er", null, null), matching().//
+ withMatcher("firstname", matcher -> matcher.regex()));
- assertThat(operations.findByExample(Example.of(new User("(Skyl|Walt)er", null, null), exampleSpec)),
- hasItems(skyler, walter));
+ assertThat(operations.find(query(byExample(example)), Person.class), hasItems(skyler, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void matchStartingStringsIgnoreCase() {
- TypedExampleSpec exampleSpec = ExampleSpec.typed(User.class). //
- withIgnorePaths("age").//
- withMatcher("firstname", startsWith()).//
- withMatcher("lastname", ignoreCase());
+ Example example = Example.of(new Person("Walter", "WHITE", null),
+ matching(). //
+ withIgnorePaths("age").//
+ withMatcher("firstname", startsWith()).//
+ withMatcher("lastname", ignoreCase()));
- assertThat(operations.findByExample(Example.of(new User("Walter", "WHITE", null), exampleSpec)),
- hasItems(flynn, walter));
+ assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void configuringMatchersUsingLambdas() {
- TypedExampleSpec exampleSpec = ExampleSpec.typed(User.class).withIgnorePaths("age"). //
- withMatcher("firstname", matcher -> matcher.startsWith()). //
- withMatcher("lastname", matcher -> matcher.ignoreCase());
+ Example example = Example.of(new Person("Walter", "WHITE", null),
+ matching().//
+ withIgnorePaths("age"). //
+ withMatcher("firstname", matcher -> matcher.startsWith()). //
+ withMatcher("lastname", matcher -> matcher.ignoreCase()));
- assertThat(operations.findByExample(Example.of(new User("Walter", "WHITE", null), exampleSpec)),
- hasItems(flynn, walter));
+ assertThat(operations.find(query(byExample(example)), Person.class), hasItems(flynn, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void valueTransformer() {
- TypedExampleSpec exampleSpec = ExampleSpec.typed(User.class). //
- withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)));
+ Example example = Example.of(new Person(null, "White", 99), matching(). //
+ withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
- assertThat(operations.findByExample(Example.of(new User(null, "White", 99), exampleSpec)), hasItems(walter));
+ assertThat(operations.find(query(byExample(example)), Person.class), hasItems(walter));
}
-
}
diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java
index 575fb2b2..a5cb5ea9 100644
--- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java
+++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package example.springdata.mongodb.querybyexample;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.ignoreCase;
-import static org.springframework.data.domain.ExampleSpec.GenericPropertyMatchers.startsWith;
+import static org.springframework.data.domain.ExampleMatcher.*;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith;
import org.junit.Before;
import org.junit.Test;
@@ -27,119 +27,122 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleSpec;
+import org.springframework.data.domain.ExampleMatcher.StringMatcher;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories.
*
* @author Mark Paluch
+ * @author Oliver Gierke
*/
+@SuppressWarnings("unused")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = ApplicationConfiguration.class)
public class UserRepositoryIntegrationTests {
@Autowired UserRepository repository;
- User skyler, walter, flynn, marie, hank;
+ Person skyler, walter, flynn, marie, hank;
@Before
public void setUp() {
repository.deleteAll();
- this.skyler = repository.save(new User("Skyler", "White", 45));
- this.walter = repository.save(new User("Walter", "White", 50));
- this.flynn = repository.save(new User("Walter Jr. (Flynn)", "White", 17));
- this.marie = repository.save(new User("Marie", "Schrader", 38));
- this.hank = repository.save(new User("Hank", "Schrader", 43));
+ this.skyler = repository.save(new Person("Skyler", "White", 45));
+ this.walter = repository.save(new Person("Walter", "White", 50));
+ this.flynn = repository.save(new Person("Walter Jr. (Flynn)", "White", 17));
+ this.marie = repository.save(new Person("Marie", "Schrader", 38));
+ this.hank = repository.save(new Person("Hank", "Schrader", 43));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void countBySimpleExample() {
- Example example = Example.of(new User(null, "White", null));
+ Example example = Example.of(new Person(null, "White", null));
assertThat(repository.count(example), is(3L));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void ignorePropertiesAndMatchByAge() {
- ExampleSpec exampleSpec = ExampleSpec.untyped(). //
- withIgnorePaths("firstname", "lastname");
+ Example example = Example.of(flynn, matching(). //
+ withIgnorePaths("firstname", "lastname"));
- assertThat(repository.findOne(Example.of(flynn, exampleSpec)), is(flynn));
+ assertThat(repository.findOne(example), is(flynn));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void substringMatching() {
- ExampleSpec exampleSpec = ExampleSpec.untyped().//
- withStringMatcherEnding();
+ Example example = Example.of(new Person("er", null, null), matching().//
+ withStringMatcher(StringMatcher.ENDING));
- assertThat(repository.findAll(Example.of(new User("er", null, null), exampleSpec)), hasItems(skyler, walter));
+ assertThat(repository.findAll(example), hasItems(skyler, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void regexMatching() {
- ExampleSpec exampleSpec = ExampleSpec.untyped().//
- withMatcher("firstname", matcher -> matcher.regex());
+ Example example = Example.of(new Person("(Skyl|Walt)er", null, null), matching().//
+ withMatcher("firstname", matcher -> matcher.regex()));
- assertThat(repository.findAll(Example.of(new User("(Skyl|Walt)er", null, null), exampleSpec)),
- hasItems(skyler, walter));
+ assertThat(repository.findAll(example), hasItems(skyler, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void matchStartingStringsIgnoreCase() {
- ExampleSpec exampleSpec = ExampleSpec.untyped(). //
- withIgnorePaths("age").//
- withMatcher("firstname", startsWith()).//
- withMatcher("lastname", ignoreCase());
+ Example example = Example.of(new Person("Walter", "WHITE", null),
+ matching().//
+ withIgnorePaths("age").//
+ withMatcher("firstname", startsWith()).//
+ withMatcher("lastname", ignoreCase()));
- assertThat(repository.findAll(Example.of(new User("Walter", "WHITE", null), exampleSpec)), hasItems(flynn, walter));
+ assertThat(repository.findAll(example), hasItems(flynn, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void configuringMatchersUsingLambdas() {
- ExampleSpec exampleSpec = ExampleSpec.untyped().withIgnorePaths("age"). //
- withMatcher("firstname", matcher -> matcher.startsWith()). //
- withMatcher("lastname", matcher -> matcher.ignoreCase());
+ Example example = Example.of(new Person("Walter", "WHITE", null),
+ matching().//
+ withIgnorePaths("age").//
+ withMatcher("firstname", matcher -> matcher.startsWith()).//
+ withMatcher("lastname", matcher -> matcher.ignoreCase()));
- assertThat(repository.findAll(Example.of(new User("Walter", "WHITE", null), exampleSpec)), hasItems(flynn, walter));
+ assertThat(repository.findAll(example), hasItems(flynn, walter));
}
/**
- * @see DATAMONGO-1245
+ * @see #153
*/
@Test
public void valueTransformer() {
- ExampleSpec exampleSpec = ExampleSpec.untyped(). //
- withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)));
+ Example example = Example.of(new Person(null, "White", 99), matching(). //
+ withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
- assertThat(repository.findAll(Example.of(new User(null, "White", 99), exampleSpec)), hasItems(walter));
+ assertThat(repository.findAll(example), hasItems(walter));
}
-
}