Skip to content

Commit b77e21b

Browse files
committed
DATAMONGO-1245 - Update documentation for Query by Example.
1 parent ff60457 commit b77e21b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/main/asciidoc/reference/query-by-example.adoc

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33

44
== Introduction
55

6-
This chapter will give you an introduction to Query by Example and will explain how to use example specifications.
6+
This chapter will give you an introduction to Query by Example and explain how to use example specifications.
77

88
Query by Example (QBE) is a user-friendly querying technique with a simple interface. It allows dynamic query creation and does not require to write queries containing field names. In fact, Query by Example does not require to write queries using store-specific query languages at all.
99

1010
== Usage
1111

12-
An `Example` takes a data object (usually the entity object or a subtype of it) and a specification how to match properties. You can use Query by Example in the `MongoTemplate` and within `Repositories`.
12+
An `Example` takes a data object (usually the domain object object or a subtype of it) and a specification how to match properties. You can use Query by Example with the `MongoTemplate` and with Repositories.
1313

1414
Query by Example is suited for several use-cases but also comes with limitations:
1515

1616
**When to use**
1717

1818
* Querying your data store with a set of static or dynamic constraints
19-
* Frequent refactoring of the entities without worrying about breaking existing queries
19+
* Frequent refactoring of the domain objects without worrying about breaking existing queries
2020
* Works independently from the data store API
2121

2222
**Limitations**
2323

2424
* Query predicates are combined using the `AND` keyword
2525
* No support for nested/grouped property constraints like `firstname = ?0 or (firstname = ?1 and lastname = ?2)`
26-
* Limited to starts/contains/ends/regex matching for strings and exact matching for other property types
26+
* Only supports starts/contains/ends/regex matching for strings and exact matching for other property types
2727

2828

29-
Before getting started with Query by Example you need to have your entities set up.
29+
Before getting started with Query by Example you need to have your interface to the data store set up.
3030

31-
.Sample Person entity
31+
.Sample Person object
3232
====
3333
[source,java]
3434
----
@@ -45,9 +45,9 @@ public class Person {
4545
----
4646
====
4747

48-
We have a quite simple entity here that is mapped to the data store. You can use this entity to create an Example specification. By default, fields having `null` values are ignored, and strings are matched using the store specific defaults. Examples can be built by either using the `exampleOf` factory method or by using the <<query.by.example.builder,Example builder>>. Once the `Example` is constructed it becomes immutable.
48+
This is a simple domain object. You can use it to create an Example specification. By default, fields having `null` values are ignored, and strings are matched using the store specific defaults. Examples can be built by either using the `exampleOf` factory method or by using the <<query.by.example.builder,Example builder>>. Once the `Example` is constructed it becomes immutable.
4949

50-
.The first Example specification
50+
.Simple Example specification
5151
====
5252
[source,xml]
5353
----
@@ -57,15 +57,15 @@ person.setFirstname("Dave"); <2>
5757
5858
Example<Person> example = Example.exampleOf(person); <3>
5959
----
60-
<1> Create a new instance of the entity
60+
<1> Create a new instance of the domain object
6161
<2> Set the properties to query
6262
<3> Create an `Example`
6363
====
6464

6565

66-
NOTE: Property names of the sample object must correlate with the property names of the queried entity.
66+
NOTE: Property names of the sample object must correlate with the property names of the queried domain object.
6767

68-
.Query by Example using the MongoTemplate
68+
.Query by Example using MongoTemplate
6969
====
7070
[source,xml]
7171
----
@@ -78,20 +78,20 @@ public List<Person> findPeople(Person sampleObject) {
7878
----
7979
====
8080

81-
The `findByExample` method accepts either the sample object or an `Example` object to query the data store. Spring Data uses the `Example` to create and execute a query.
81+
`MongoTemplate.findByExample` accepts either the sample object or an `Example` object to create and execute a query.
8282

8383

84-
.Query by Example using the Repositories
84+
.Query by Example using a Repository
8585
====
8686
[source, java]
8787
----
8888
public interface MongoRepository<Person, String> {
8989
90-
<S extends T> List<T> findAllByExample(Example<S> example);
90+
<S extends Person> List<Person> findAllByExample(Example<S> example);
9191
92-
<S extends T> List<T> findAllByExample(Example<S> example, Sort sort);
92+
<S extends Person> List<Person> findAllByExample(Example<S> example, Sort sort);
9393
94-
<S extends T> Page<T> findAllByExample(Example<S> example, Pageable pageable);
94+
<S extends Person> Page<Person> findAllByExample(Example<S> example, Pageable pageable);
9595
9696
// … more functionality omitted.
9797
}
@@ -120,10 +120,10 @@ Example.newExampleOf(person)
120120
----
121121
====
122122

123-
Property specifier accepts property names and property paths separated by dots that are contained within the sample object. A `PropertySpecifier` allows setting string matching options, case-sensitivity,
123+
Property specifier accepts property names (e.g. "firstname" and "lastname"). You can navigate by chaining properties together with dots ("address.city"). You can tune it with matching options and case sensitivity.
124124

125125
[cols="1,2", options="header"]
126-
.Supported string matching options of `StringMatcher`
126+
.`StringMatcher` options
127127
|===
128128
| Matching
129129
| Logical result

0 commit comments

Comments
 (0)