#410 - Make it possible to write delete/update operations without using matching.
Fluent operations now allow statement execution without the need to specify a Query object allowing for shorter statements.
This commit is contained in:
@@ -56,7 +56,7 @@ public interface ReactiveDeleteOperation {
|
||||
/**
|
||||
* Table override (optional).
|
||||
*/
|
||||
interface DeleteWithTable {
|
||||
interface DeleteWithTable extends TerminatingDelete {
|
||||
|
||||
/**
|
||||
* Explicitly set the {@link String name} of the table on which to perform the delete.
|
||||
@@ -88,7 +88,7 @@ public interface ReactiveDeleteOperation {
|
||||
/**
|
||||
* Required {@link Query filter}.
|
||||
*/
|
||||
interface DeleteWithQuery {
|
||||
interface DeleteWithQuery extends TerminatingDelete {
|
||||
|
||||
/**
|
||||
* Define the {@link Query} used to filter elements in the delete.
|
||||
|
||||
@@ -60,7 +60,7 @@ public interface ReactiveUpdateOperation {
|
||||
/**
|
||||
* Table override (optional).
|
||||
*/
|
||||
interface UpdateWithTable {
|
||||
interface UpdateWithTable extends TerminatingUpdate {
|
||||
|
||||
/**
|
||||
* Explicitly set the {@link String name} of the table on which to perform the update.
|
||||
@@ -92,7 +92,7 @@ public interface ReactiveUpdateOperation {
|
||||
/**
|
||||
* Define a {@link Query} used as the filter for the {@link Update}.
|
||||
*/
|
||||
interface UpdateWithQuery {
|
||||
interface UpdateWithQuery extends TerminatingUpdate {
|
||||
|
||||
/**
|
||||
* Filter rows to update by the given {@link Query}.
|
||||
|
||||
@@ -51,13 +51,49 @@ public class ReactiveDeleteOperationUnitTests {
|
||||
entityTemplate = new R2dbcEntityTemplate(client);
|
||||
}
|
||||
|
||||
@Test // gh-220
|
||||
@Test // gh-410
|
||||
public void shouldDelete() {
|
||||
|
||||
MockResult result = MockResult.builder().rowsUpdated(1).build();
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("DELETE"), result);
|
||||
|
||||
entityTemplate.delete(Person.class) //
|
||||
.all() //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
|
||||
|
||||
assertThat(statement.getSql()).isEqualTo("DELETE FROM person");
|
||||
}
|
||||
|
||||
@Test // gh-410
|
||||
public void shouldDeleteWithTable() {
|
||||
|
||||
MockResult result = MockResult.builder().rowsUpdated(1).build();
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("DELETE"), result);
|
||||
|
||||
entityTemplate.delete(Person.class) //
|
||||
.from("table").all() //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("DELETE"));
|
||||
|
||||
assertThat(statement.getSql()).isEqualTo("DELETE FROM table");
|
||||
}
|
||||
|
||||
@Test // gh-220
|
||||
public void shouldDeleteWithQuery() {
|
||||
|
||||
MockResult result = MockResult.builder().rowsUpdated(1).build();
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("DELETE"), result);
|
||||
|
||||
entityTemplate.delete(Person.class) //
|
||||
.matching(query(where("name").is("Walter"))) //
|
||||
.all() //
|
||||
|
||||
@@ -52,13 +52,51 @@ public class ReactiveUpdateOperationUnitTests {
|
||||
entityTemplate = new R2dbcEntityTemplate(client);
|
||||
}
|
||||
|
||||
@Test // gh-220
|
||||
@Test // gh-410
|
||||
public void shouldUpdate() {
|
||||
|
||||
MockResult result = MockResult.builder().rowsUpdated(1).build();
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("UPDATE"), result);
|
||||
|
||||
entityTemplate.update(Person.class) //
|
||||
.apply(Update.update("name", "Heisenberg")) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
|
||||
|
||||
assertThat(statement.getSql()).isEqualTo("UPDATE person SET THE_NAME = $1");
|
||||
assertThat(statement.getBindings()).hasSize(1).containsEntry(0, SettableValue.from("Heisenberg"));
|
||||
}
|
||||
|
||||
@Test // gh-410
|
||||
public void shouldUpdateWithTable() {
|
||||
|
||||
MockResult result = MockResult.builder().rowsUpdated(1).build();
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("UPDATE"), result);
|
||||
|
||||
entityTemplate.update(Person.class) //
|
||||
.inTable("table").apply(Update.update("name", "Heisenberg")) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StatementRecorder.RecordedStatement statement = recorder.getCreatedStatement(s -> s.startsWith("UPDATE"));
|
||||
|
||||
assertThat(statement.getSql()).isEqualTo("UPDATE table SET THE_NAME = $1");
|
||||
assertThat(statement.getBindings()).hasSize(1).containsEntry(0, SettableValue.from("Heisenberg"));
|
||||
}
|
||||
|
||||
@Test // gh-220
|
||||
public void shouldUpdateWithQuery() {
|
||||
|
||||
MockResult result = MockResult.builder().rowsUpdated(1).build();
|
||||
|
||||
recorder.addStubbing(s -> s.startsWith("UPDATE"), result);
|
||||
|
||||
entityTemplate.update(Person.class) //
|
||||
.matching(query(where("name").is("Walter"))) //
|
||||
.apply(Update.update("name", "Heisenberg")) //
|
||||
|
||||
Reference in New Issue
Block a user