Skip to content

Commit 8d17ddb

Browse files
christophstroblmp911de
authored andcommitted
Update QBE Documentation section.
This commit adds a note explaining scenarios suitable for an UntypedExampleMatcher. Closes: #3474 Original pull request: #3538.
1 parent 0e96ef2 commit 8d17ddb

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ public static Criteria byExample(Object example) {
124124
}
125125

126126
/**
127-
* Static factory method to create a {@link Criteria} matching an example object.
127+
* Static factory method to create a {@link Criteria} matching an example object. <br />
128+
* By default the {@link Example} uses typed matching restricting it to probe assignable types. For example, when
129+
* sticking with the default type key ({@code _class}), the query has restrictions such as
130+
* <code>_class : &#123; $in : [com.acme.Person] &#125; </code>. <br />
131+
* To avoid the above mentioned type restriction use an {@link UntypedExampleMatcher} with
132+
* {@link Example#of(Object, org.springframework.data.domain.ExampleMatcher)}.
128133
*
129134
* @param example must not be {@literal null}.
130135
* @return new instance of {@link Criteria}.

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/MongoRepository.java

+20-5
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,31 @@ public interface MongoRepository<T, ID> extends PagingAndSortingRepository<T, ID
7878
*/
7979
<S extends T> List<S> insert(Iterable<S> entities);
8080

81-
/*
82-
* (non-Javadoc)
81+
/**
82+
* Returns all entities matching the given {@link Example}. In case no match could be found an empty {@link List} is
83+
* returned. <br />
84+
* By default the {@link Example} uses typed matching restricting it to probe assignable types. For example, when
85+
* sticking with the default type key ({@code _class}), the query has restrictions such as
86+
* <code>_class : &#123; $in : [com.acme.Person] &#125;</code>. <br />
87+
* To avoid the above mentioned type restriction use an {@link org.springframework.data.mongodb.core.query.UntypedExampleMatcher} with
88+
* {@link Example#of(Object, org.springframework.data.domain.ExampleMatcher)}.
89+
*
8390
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
8491
*/
8592
@Override
8693
<S extends T> List<S> findAll(Example<S> example);
8794

88-
/*
89-
* (non-Javadoc)
90-
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
95+
/**
96+
* Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
97+
* found an empty {@link List} is returned. <br />
98+
* By default the {@link Example} uses typed matching restricting it to probe assignable types. For example, when
99+
* sticking with the default type key ({@code _class}), the query has restrictions such as
100+
* <code>_class : &#123; $in : [com.acme.Person] &#125;</code>. <br />
101+
* To avoid the above mentioned type restriction use an {@link org.springframework.data.mongodb.core.query.UntypedExampleMatcher} with
102+
* {@link Example#of(Object, org.springframework.data.domain.ExampleMatcher)}.
103+
*
104+
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example,
105+
* org.springframework.data.domain.Sort)
91106
*/
92107
@Override
93108
<S extends T> List<S> findAll(Example<S> example, Sort sort);

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/ReactiveMongoRepository.java

+23-6
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,33 @@ public interface ReactiveMongoRepository<T, ID> extends ReactiveSortingRepositor
6464
*/
6565
<S extends T> Flux<S> insert(Publisher<S> entities);
6666

67-
/*
68-
* (non-Javadoc)
69-
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
67+
/**
68+
* Returns all entities matching the given {@link Example}. In case no match could be found an empty {@link Flux} is
69+
* returned. <br />
70+
* By default the {@link Example} uses typed matching restricting it to probe assignable types. For example, when
71+
* sticking with the default type key ({@code _class}), the query has restrictions such as
72+
* <code>_class : &#123; $in : [com.acme.Person] &#125;</code>. <br />
73+
* To avoid the above mentioned type restriction use an {@link org.springframework.data.mongodb.core.query.UntypedExampleMatcher} with
74+
* {@link Example#of(Object, org.springframework.data.domain.ExampleMatcher)}.
75+
*
76+
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
7077
*/
78+
@Override
7179
<S extends T> Flux<S> findAll(Example<S> example);
7280

73-
/*
74-
* (non-Javadoc)
75-
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
81+
/**
82+
* Returns all entities matching the given {@link Example} applying the given {@link Sort}. In case no match could be
83+
* found an empty {@link Flux} is returned. <br />
84+
* By default the {@link Example} uses typed matching restricting it to probe assignable types. For example, when
85+
* sticking with the default type key ({@code _class}), the query has restrictions such as
86+
* <code>_class : &#123; $in : [com.acme.Person] &#125;</code>. <br />
87+
* To avoid the above mentioned type restriction use an {@link org.springframework.data.mongodb.core.query.UntypedExampleMatcher} with
88+
* {@link Example#of(Object, org.springframework.data.domain.ExampleMatcher)}.
89+
*
90+
* @see org.springframework.data.repository.query.ReactiveQueryByExampleExecutor#findAll(org.springframework.data.domain.Example,
91+
* org.springframework.data.domain.Sort)
7692
*/
93+
@Override
7794
<S extends T> Flux<S> findAll(Example<S> example, Sort sort);
7895

7996
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,10 @@ Query query = new Query(new Criteria().alike(example));
9797
List<Person> result = template.find(query, Person.class);
9898
----
9999
====
100+
101+
[NOTE]
102+
====
103+
`UntypedExampleMatcher` is likely the right choice for you if you are storing different entities within a single collection or opted out of writing <<mongo-template.type-mapping,type hints>>.
104+
105+
Also, keep in mind that using `@TypeAlias` requires eager initialization of the `MappingContext`. To do so, configure `initialEntitySet` to to ensure proper alias resolution for read operations.
106+
====

0 commit comments

Comments
 (0)