DATAMONGO-1865 - Polishing.
Adapt to collection name retrieval during query execution. Slightly reword documentation and JavaDoc. Original pull request: #530.
This commit is contained in:
@@ -179,7 +179,7 @@ public abstract class AbstractMongoQuery implements RepositoryQuery {
|
|||||||
protected abstract boolean isDeleteQuery();
|
protected abstract boolean isDeleteQuery();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return weather the query has an explicit limit set.
|
* Return whether the query has an explicit limit set.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* @since 2.0.4
|
* @since 2.0.4
|
||||||
|
|||||||
@@ -68,11 +68,10 @@ public abstract class AbstractReactiveMongoQuery implements RepositoryQuery {
|
|||||||
this.operations = operations;
|
this.operations = operations;
|
||||||
this.instantiators = new EntityInstantiators();
|
this.instantiators = new EntityInstantiators();
|
||||||
|
|
||||||
ReturnedType returnedType = method.getResultProcessor().getReturnedType();
|
MongoEntityMetadata<?> metadata = method.getEntityInformation();
|
||||||
|
Class<?> type = metadata.getCollectionEntity().getType();
|
||||||
|
|
||||||
this.findOperationWithProjection = operations//
|
this.findOperationWithProjection = operations.query(type);
|
||||||
.query(returnedType.getDomainType())//
|
|
||||||
.inCollection(method.getEntityInformation().getCollectionName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -214,7 +213,7 @@ public abstract class AbstractReactiveMongoQuery implements RepositoryQuery {
|
|||||||
protected abstract boolean isDeleteQuery();
|
protected abstract boolean isDeleteQuery();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return weather the query has an explicit limit set.
|
* Return whether the query has an explicit limit set.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* @since 2.0.4
|
* @since 2.0.4
|
||||||
|
|||||||
@@ -1181,7 +1181,7 @@ public abstract class AbstractPersonRepositoryIntegrationTests {
|
|||||||
|
|
||||||
@Test // DATAMONGO-1865
|
@Test // DATAMONGO-1865
|
||||||
public void findFirstEntityReturnsFirstResultEvenForNonUniqueMatches() {
|
public void findFirstEntityReturnsFirstResultEvenForNonUniqueMatches() {
|
||||||
repository.findFirstBy();
|
assertThat(repository.findFirstBy()).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1865
|
@Test(expected = IncorrectResultSizeDataAccessException.class) // DATAMONGO-1865
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ public class ReactiveStringBasedMongoQueryUnitTests {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
when(operations.query(any())).thenReturn(reactiveFind);
|
when(operations.query(any())).thenReturn(reactiveFind);
|
||||||
when(reactiveFind.inCollection(anyString())).thenReturn(reactiveFind);
|
|
||||||
|
|
||||||
this.converter = new MappingMongoConverter(factory, new MongoMappingContext());
|
this.converter = new MappingMongoConverter(factory, new MongoMappingContext());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ Mark Pollack; Thomas Risberg; Oliver Gierke; Costin Leau; Jon Brisbin; Thomas Da
|
|||||||
:toc-placement!:
|
:toc-placement!:
|
||||||
:spring-data-commons-docs: ../../../../spring-data-commons/src/main/asciidoc
|
:spring-data-commons-docs: ../../../../spring-data-commons/src/main/asciidoc
|
||||||
|
|
||||||
(C) 2008-2017 The original authors.
|
(C) 2008-2018 The original authors.
|
||||||
|
|
||||||
NOTE: _Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically._
|
NOTE: _Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically._
|
||||||
|
|
||||||
|
|||||||
@@ -147,8 +147,8 @@ public interface PersonRepository extends PagingAndSortingRepository<Person, Str
|
|||||||
----
|
----
|
||||||
<1> The method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of `{"lastname" : lastname}`.
|
<1> The method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of `{"lastname" : lastname}`.
|
||||||
<2> Applies pagination to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance and we will automatically page the query accordingly.
|
<2> Applies pagination to a query. Just equip your method signature with a `Pageable` parameter and let the method return a `Page` instance and we will automatically page the query accordingly.
|
||||||
<3> Shows that you can query based on properties which are not a primitive type. Errors with `IncorrectResultSizeDataAccessException` if more than one match found.
|
<3> Shows that you can query based on properties which are not a primitive type. Throws `IncorrectResultSizeDataAccessException` if more than one match found.
|
||||||
<4> Uses the `First` keyword to restrict the query to the very first result. Unlike <3> this method does not error if more than one match found.
|
<4> Uses the `First` keyword to restrict the query to the very first result. Unlike <3> this method does not throw an exception if more than one match was found.
|
||||||
<5> Uses a Java 8 `Stream` which reads and converts individual elements while iterating the stream.
|
<5> Uses a Java 8 `Stream` which reads and converts individual elements while iterating the stream.
|
||||||
====
|
====
|
||||||
|
|
||||||
|
|||||||
@@ -64,10 +64,10 @@ public interface ReactivePersonRepository extends ReactiveSortingRepository<Pers
|
|||||||
}
|
}
|
||||||
----
|
----
|
||||||
<1> The method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of `{"lastname" : lastname}`.
|
<1> The method shows a query for all people with the given lastname. The query will be derived parsing the method name for constraints which can be concatenated with `And` and `Or`. Thus the method name will result in a query expression of `{"lastname" : lastname}`.
|
||||||
<2> The method shows a query for all people with the given firstname once the firstname becomes available via the given `Publisher`.
|
<2> The method shows a query for all people with the given firstname once the firstname is emitted via the given `Publisher`.
|
||||||
<3> Use `Pageable` to pass on offset and sorting parameters to the database.
|
<3> Use `Pageable` to pass on offset and sorting parameters to the database.
|
||||||
<4> Find a single entity for given criteria. Errors on non unique results.
|
<4> Find a single entity for given criteria. Completes with `IncorrectResultSizeDataAccessException` on non unique results.
|
||||||
<5> Unless <4> the first entity is returned no matter what.
|
<5> Unless <4> the first entity is always emitted even if the query yields more result documents.
|
||||||
====
|
====
|
||||||
|
|
||||||
For JavaConfig use the `@EnableReactiveMongoRepositories` annotation. The annotation carries the very same attributes like the namespace element. If no base package is configured the infrastructure will scan the package of the annotated configuration class.
|
For JavaConfig use the `@EnableReactiveMongoRepositories` annotation. The annotation carries the very same attributes like the namespace element. If no base package is configured the infrastructure will scan the package of the annotated configuration class.
|
||||||
|
|||||||
Reference in New Issue
Block a user