#421 - Suppress results for suspended query methods returning kotlin.Unit.
We now discard results for suspended query methods if the return type is kotlin.Unit. Related ticket: DATACMNS-1779 Original pull request: #422.
This commit is contained in:
@@ -34,6 +34,7 @@ import org.springframework.data.repository.query.ParameterAccessor;
|
||||
import org.springframework.data.repository.query.RepositoryQuery;
|
||||
import org.springframework.data.repository.query.ResultProcessor;
|
||||
import org.springframework.data.repository.query.ReturnedType;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -136,7 +137,7 @@ public abstract class AbstractR2dbcQuery implements RepositoryQuery {
|
||||
});
|
||||
}
|
||||
|
||||
if (Void.class.isAssignableFrom(returnedType.getReturnedType())) {
|
||||
if (ReflectionUtils.isVoid(returnedType.getReturnedType())) {
|
||||
return (q, t, c) -> q.rowsUpdated().then();
|
||||
}
|
||||
|
||||
@@ -152,7 +153,7 @@ public abstract class AbstractR2dbcQuery implements RepositoryQuery {
|
||||
|
||||
/**
|
||||
* Returns whether this query is a modifying one.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* @since 1.1
|
||||
*/
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.data.relational.core.sql.SqlIdentifier;
|
||||
import org.springframework.data.relational.repository.query.DtoInstantiatingConverter;
|
||||
import org.springframework.data.repository.query.ResultProcessor;
|
||||
import org.springframework.data.repository.query.ReturnedType;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -97,7 +98,7 @@ interface R2dbcQueryExecution {
|
||||
return source;
|
||||
}
|
||||
|
||||
if (Void.class == returnedType.getReturnedType()) {
|
||||
if (ReflectionUtils.isVoid(returnedType.getReturnedType())) {
|
||||
|
||||
if (source instanceof Mono) {
|
||||
return ((Mono<?>) source).then();
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2020 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
|
||||
*
|
||||
* https://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 org.springframework.data.r2dbc.repository
|
||||
|
||||
import io.r2dbc.spi.test.MockResult
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.r2dbc.core.DatabaseClient
|
||||
import org.springframework.data.r2dbc.core.DefaultReactiveDataAccessStrategy
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate
|
||||
import org.springframework.data.r2dbc.dialect.PostgresDialect
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory
|
||||
import org.springframework.data.r2dbc.testing.StatementRecorder
|
||||
import org.springframework.data.repository.kotlin.CoroutineCrudRepository
|
||||
|
||||
/**
|
||||
* Unit tests for [CoroutineCrudRepository].
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class CoroutineRepositoryUnitTests {
|
||||
|
||||
lateinit var client: DatabaseClient
|
||||
lateinit var entityTemplate: R2dbcEntityTemplate
|
||||
lateinit var recorder: StatementRecorder
|
||||
lateinit var repositoryFactory: R2dbcRepositoryFactory
|
||||
|
||||
@BeforeEach
|
||||
fun before() {
|
||||
recorder = StatementRecorder.newInstance()
|
||||
client = DatabaseClient.builder().connectionFactory(recorder)
|
||||
.dataAccessStrategy(DefaultReactiveDataAccessStrategy(PostgresDialect.INSTANCE)).build()
|
||||
entityTemplate = R2dbcEntityTemplate(client)
|
||||
repositoryFactory = R2dbcRepositoryFactory(entityTemplate)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun shouldIssueDeleteQuery() {
|
||||
|
||||
val result = MockResult.builder().rowsUpdated(2).build()
|
||||
recorder.addStubbing({ s: String -> s.startsWith("DELETE") }, result)
|
||||
|
||||
val repository = repositoryFactory.getRepository(PersonRepository::class.java)
|
||||
|
||||
runBlocking {
|
||||
repository.deleteUserAssociation(2)
|
||||
}
|
||||
}
|
||||
|
||||
interface PersonRepository : CoroutineCrudRepository<Person, Long> {
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE FROM person WHERE id = :id ")
|
||||
suspend fun deleteUserAssociation(userId: Int)
|
||||
}
|
||||
|
||||
|
||||
data class Person(@Id var id: Long, var name: String)
|
||||
}
|
||||
Reference in New Issue
Block a user