Java 16 migration for R2DBC examples.

See #606.
This commit is contained in:
Mark Paluch
2021-04-28 10:14:45 +02:00
parent 75e2763054
commit a4c9302780
10 changed files with 83 additions and 76 deletions

View File

@@ -15,8 +15,7 @@
*/
package example.springdata.r2dbc.basics;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.Objects;
import org.springframework.data.annotation.Id;
@@ -25,15 +24,26 @@ import org.springframework.data.annotation.Id;
*
* @author Mark Paluch
*/
@Data
@AllArgsConstructor
class Person {
@Id Integer id;
String firstname, lastname;
Integer age;
record Person(@Id Integer id, String firstname, String lastname, Integer age) {
boolean hasId() {
return id != null;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Person person)) {
return false;
}
return Objects.equals(firstname, person.firstname) && Objects.equals(lastname, person.lastname)
&& Objects.equals(age, person.age);
}
@Override
public int hashCode() {
return Objects.hash(firstname, lastname, age);
}
}

View File

@@ -52,7 +52,7 @@ class PersonRepositoryIntegrationTests {
Hooks.onOperatorDebug();
List<String> statements = Arrays.asList(//
var statements = Arrays.asList(//
"DROP TABLE IF EXISTS person;",
"CREATE TABLE person (id SERIAL PRIMARY KEY, firstname VARCHAR(100) NOT NULL, lastname VARCHAR(100) NOT NULL, age INTEGER NOT NULL);");
@@ -75,7 +75,7 @@ class PersonRepositoryIntegrationTests {
@Test
void countBySimpleExample() {
Example<Person> example = Example.of(new Person(null, null, "White", null));
var example = Example.of(new Person(null, null, "White", null));
people.count(example).as(StepVerifier::create) //
.expectNext(3L) //
@@ -85,7 +85,7 @@ class PersonRepositoryIntegrationTests {
@Test
void ignorePropertiesAndMatchByAge() {
Example<Person> example = Example.of(flynn, matching(). //
var example = Example.of(flynn, matching(). //
withIgnorePaths("firstname", "lastname"));
people.findOne(example) //
@@ -97,7 +97,7 @@ class PersonRepositoryIntegrationTests {
@Test
void substringMatching() {
Example<Person> example = Example.of(new Person(null, "er", null, null), matching(). //
var example = Example.of(new Person(null, "er", null, null), matching(). //
withStringMatcher(StringMatcher.ENDING));
people.findAll(example).collectList() //
@@ -111,7 +111,7 @@ class PersonRepositoryIntegrationTests {
@Test
void matchStartingStringsIgnoreCase() {
Example<Person> example = Example.of(new Person(null, "Walter", "WHITE", null), matching(). //
var example = Example.of(new Person(null, "Walter", "WHITE", null), matching(). //
withIgnorePaths("age"). //
withMatcher("firstname", startsWith()). //
withMatcher("lastname", ignoreCase()));
@@ -127,7 +127,7 @@ class PersonRepositoryIntegrationTests {
@Test
void configuringMatchersUsingLambdas() {
Example<Person> example = Example.of(new Person(null, "Walter", "WHITE", null), matching(). //
var example = Example.of(new Person(null, "Walter", "WHITE", null), matching(). //
withIgnorePaths("age"). //
withMatcher("firstname", GenericPropertyMatcher::startsWith). //
withMatcher("lastname", GenericPropertyMatcher::ignoreCase));
@@ -143,7 +143,7 @@ class PersonRepositoryIntegrationTests {
@Test
void valueTransformer() {
Example<Person> example = Example.of(new Person(null, null, "White", 99), matching(). //
var example = Example.of(new Person(null, null, "White", 99), matching(). //
withMatcher("age", matcher -> matcher.transform(value -> Optional.of(50))));
people.findAll(example).collectList() //