Browse Source

#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.
pull/1188/head
Mark Paluch 5 years ago
parent
commit
07be001e54
No known key found for this signature in database
GPG Key ID: 51A00FA751B91849
  1. 4
      src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperation.java
  2. 4
      src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperation.java
  3. 38
      src/test/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationUnitTests.java
  4. 40
      src/test/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperationUnitTests.java

4
src/main/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperation.java

@ -56,7 +56,7 @@ public interface ReactiveDeleteOperation { @@ -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 { @@ -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.

4
src/main/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperation.java

@ -60,7 +60,7 @@ public interface ReactiveUpdateOperation { @@ -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 { @@ -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}.

38
src/test/java/org/springframework/data/r2dbc/core/ReactiveDeleteOperationUnitTests.java

@ -51,13 +51,49 @@ public class ReactiveDeleteOperationUnitTests { @@ -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() //

40
src/test/java/org/springframework/data/r2dbc/core/ReactiveUpdateOperationUnitTests.java

@ -52,13 +52,51 @@ public class ReactiveUpdateOperationUnitTests { @@ -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")) //

Loading…
Cancel
Save