#250 - Throw IllegalArgumentException in StatementMapper if UPDATE contains no assignments.
We now properly throw an IllegalArgumentException. Previously, the update object was attempted to being mapped and this failed as the update object was null.
This commit is contained in:
@@ -192,15 +192,15 @@ class DefaultStatementMapper implements StatementMapper {
|
||||
BindMarkers bindMarkers = this.dialect.getBindMarkersFactory().create();
|
||||
Table table = Table.create(updateSpec.getTable());
|
||||
|
||||
if (updateSpec.getUpdate() == null || updateSpec.getUpdate().getAssignments().isEmpty()) {
|
||||
throw new IllegalArgumentException("UPDATE contains no assignments");
|
||||
}
|
||||
|
||||
BoundAssignments boundAssignments = this.updateMapper.getMappedObject(bindMarkers,
|
||||
updateSpec.getUpdate().getAssignments(), table, entity);
|
||||
|
||||
Bindings bindings;
|
||||
|
||||
if (boundAssignments.getAssignments().isEmpty()) {
|
||||
throw new IllegalStateException("UPDATE contains no assignments");
|
||||
}
|
||||
|
||||
bindings = boundAssignments.getBindings();
|
||||
|
||||
UpdateBuilder.UpdateWhere updateBuilder = StatementBuilder.update(table).set(boundAssignments.getAssignments());
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.r2dbc.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.data.r2dbc.query.Criteria.*;
|
||||
|
||||
@@ -37,6 +38,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.r2dbc.dialect.PostgresDialect;
|
||||
import org.springframework.data.r2dbc.mapping.SettableValue;
|
||||
import org.springframework.data.r2dbc.support.R2dbcExceptionTranslator;
|
||||
@@ -352,4 +354,23 @@ public class DefaultDatabaseClientUnitTests {
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // gh-250
|
||||
public void shouldThrowExceptionForSingleColumnObjectUpdate() {
|
||||
|
||||
DefaultDatabaseClient databaseClient = (DefaultDatabaseClient) DatabaseClient.builder()
|
||||
.connectionFactory(connectionFactory) //
|
||||
.dataAccessStrategy(new DefaultReactiveDataAccessStrategy(PostgresDialect.INSTANCE)) //
|
||||
.build();
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> databaseClient.update() //
|
||||
.table(IdOnly.class) //
|
||||
.using(new IdOnly()) //
|
||||
.then()).withMessageContaining("UPDATE contains no assignments");
|
||||
}
|
||||
|
||||
static class IdOnly {
|
||||
|
||||
@Id String id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user