Do not override existing limit in R2dbcEntityTemplate.selectOne.
Closes #758
This commit is contained in:
@@ -91,6 +91,7 @@ import org.springframework.util.Assert;
|
||||
* @author Bogdan Ilchyshyn
|
||||
* @author Jens Schauder
|
||||
* @author Jose Luis Leon
|
||||
* @author Robert Heim
|
||||
* @since 1.1
|
||||
*/
|
||||
public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAware, ApplicationContextAware {
|
||||
@@ -448,7 +449,8 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
|
||||
*/
|
||||
@Override
|
||||
public <T> Mono<T> selectOne(Query query, Class<T> entityClass) throws DataAccessException {
|
||||
return doSelect(query.limit(2), entityClass, getTableName(entityClass), entityClass, RowsFetchSpec::one);
|
||||
return doSelect(query.getLimit() != -1 ? query : query.limit(2), entityClass, getTableName(entityClass),
|
||||
entityClass, RowsFetchSpec::one);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -641,11 +643,9 @@ public class R2dbcEntityTemplate implements R2dbcEntityOperations, BeanFactoryAw
|
||||
}
|
||||
|
||||
return statement.returnGeneratedValues(dataAccessStrategy.renderForGeneratedValues(identifierColumns.get(0)));
|
||||
})
|
||||
.map(this.dataAccessStrategy.getConverter().populateIdIfNecessary(entity)) //
|
||||
}).map(this.dataAccessStrategy.getConverter().populateIdIfNecessary(entity)) //
|
||||
.all() //
|
||||
.last(entity)
|
||||
.flatMap(saved -> maybeCallAfterSave(saved, outboundRow, tableName));
|
||||
.last(entity).flatMap(saved -> maybeCallAfterSave(saved, outboundRow, tableName));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -68,6 +68,7 @@ import org.springframework.util.CollectionUtils;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Jose Luis Leon
|
||||
* @author Robert Heim
|
||||
*/
|
||||
public class R2dbcEntityTemplateUnitTests {
|
||||
|
||||
@@ -202,6 +203,23 @@ public class R2dbcEntityTemplateUnitTests {
|
||||
assertThat(statement.getBindings()).hasSize(1).containsEntry(0, Parameter.from("Walter"));
|
||||
}
|
||||
|
||||
@Test // gh-758
|
||||
void shouldSelectOneDoNotOverrideExistingLimit() {
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("SELECT"), Collections.emptyList());
|
||||
|
||||
entityTemplate
|
||||
.selectOne(Query.query(Criteria.where("name").is("Walter")).sort(Sort.by("name")).limit(1), Person.class) //
|
||||
.as(StepVerifier::create) //
|
||||
.verifyComplete();
|
||||
|
||||
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("SELECT"));
|
||||
|
||||
assertThat(statement.getSql())
|
||||
.isEqualTo("SELECT person.* FROM person WHERE person.THE_NAME = $1 ORDER BY person.THE_NAME ASC LIMIT 1");
|
||||
assertThat(statement.getBindings()).hasSize(1).containsEntry(0, Parameter.from("Walter"));
|
||||
}
|
||||
|
||||
@Test // gh-220
|
||||
void shouldUpdateByQuery() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user