diff --git a/pom.xml b/pom.xml index 5ce20450..11dcdefa 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ 16 1.11.0 1.15.3 + 1.5.0 1.1.3 UTF-8 diff --git a/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/Customer.java b/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/Customer.java index fd5fce88..daa8391f 100644 --- a/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/Customer.java +++ b/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/Customer.java @@ -15,22 +15,32 @@ */ package example.springdata.r2dbc.basics; -import lombok.AllArgsConstructor; -import lombok.Data; +import java.util.Objects; import org.springframework.data.annotation.Id; /** * @author Oliver Gierke */ -@Data -@AllArgsConstructor -class Customer { - - @Id Integer id; - String firstname, lastname; +record Customer(@Id Integer id, String firstname, String lastname) { boolean hasId() { return id != null; } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Customer customer)) { + return false; + } + return Objects.equals(firstname, customer.firstname) && Objects.equals(lastname, customer.lastname); + } + + @Override + public int hashCode() { + return Objects.hash(firstname, lastname); + } } diff --git a/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/TransactionalService.java b/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/TransactionalService.java index ace6878a..f7249e51 100644 --- a/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/TransactionalService.java +++ b/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/TransactionalService.java @@ -42,7 +42,7 @@ class TransactionalService { return repository.save(customer).map(it -> { - if (it.firstname.equals("Dave")) { + if (it.firstname().equals("Dave")) { throw new IllegalStateException(); } else { return it; diff --git a/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/ApplicationConfiguration.java b/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/ApplicationConfiguration.java index 7dcd7d7d..4bbc05b7 100644 --- a/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/ApplicationConfiguration.java +++ b/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/ApplicationConfiguration.java @@ -39,7 +39,7 @@ class ApplicationConfiguration { return (customer, sqlIdentifier) -> { - if (customer.getId() == null) { + if (customer.id() == null) { return databaseClient.sql("SELECT primary_key.nextval") // .map(row -> row.get(0, Long.class)) // @@ -54,7 +54,7 @@ class ApplicationConfiguration { @Bean ConnectionFactoryInitializer initializer(ConnectionFactory connectionFactory) { - ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer(); + var initializer = new ConnectionFactoryInitializer(); initializer.setConnectionFactory(connectionFactory); initializer.setDatabasePopulator(new ResourceDatabasePopulator(new ByteArrayResource(("CREATE SEQUENCE primary_key;" + "DROP TABLE IF EXISTS customer;" diff --git a/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/Customer.java b/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/Customer.java index 7062b48b..228b6863 100644 --- a/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/Customer.java +++ b/r2dbc/example/src/main/java/example/springdata/r2dbc/entitycallback/Customer.java @@ -15,20 +15,14 @@ */ package example.springdata.r2dbc.entitycallback; -import lombok.AllArgsConstructor; -import lombok.Value; -import lombok.With; - import org.springframework.data.annotation.Id; /** * @author Mark Paluch */ -@Value -@AllArgsConstructor -@With -class Customer { +record Customer(@Id Long id, String firstname, String lastname) { - @Id Long id; - String firstname, lastname; + public Customer withId(long id) { + return new Customer(id, firstname, lastname); + } } diff --git a/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/CustomerRepositoryIntegrationTests.java b/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/CustomerRepositoryIntegrationTests.java index 57ed6d07..5e569de2 100644 --- a/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/CustomerRepositoryIntegrationTests.java +++ b/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/CustomerRepositoryIntegrationTests.java @@ -20,32 +20,29 @@ import reactor.test.StepVerifier; import java.io.IOException; import java.util.Arrays; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.r2dbc.core.DatabaseClient; -import org.springframework.test.context.junit4.SpringRunner; /** * @author Oliver Gierke */ -@RunWith(SpringRunner.class) @SpringBootTest(classes = InfrastructureConfiguration.class) -public class CustomerRepositoryIntegrationTests { +class CustomerRepositoryIntegrationTests { @Autowired CustomerRepository customers; @Autowired DatabaseClient database; - @Before - public void setUp() { + @BeforeEach + void setUp() { Hooks.onOperatorDebug(); - List statements = Arrays.asList(// + var statements = Arrays.asList(// "DROP TABLE IF EXISTS customer;", "CREATE TABLE customer ( id SERIAL PRIMARY KEY, firstname VARCHAR(100) NOT NULL, lastname VARCHAR(100) NOT NULL);"); @@ -58,31 +55,31 @@ public class CustomerRepositoryIntegrationTests { } @Test - public void executesFindAll() throws IOException { + void executesFindAll() throws IOException { - Customer dave = new Customer(null, "Dave", "Matthews"); - Customer carter = new Customer(null, "Carter", "Beauford"); + var dave = new Customer(null, "Dave", "Matthews"); + var carter = new Customer(null, "Carter", "Beauford"); insertCustomers(dave, carter); customers.findAll() // .as(StepVerifier::create) // - .assertNext(dave::equals) // - .assertNext(carter::equals) // + .expectNext(dave) // + .expectNext(carter) // .verifyComplete(); } @Test - public void executesAnnotatedQuery() throws IOException { + void executesAnnotatedQuery() throws IOException { - Customer dave = new Customer(null, "Dave", "Matthews"); - Customer carter = new Customer(null, "Carter", "Beauford"); + var dave = new Customer(null, "Dave", "Matthews"); + var carter = new Customer(null, "Carter", "Beauford"); insertCustomers(dave, carter); customers.findByLastname("Matthews") // .as(StepVerifier::create) // - .assertNext(dave::equals) // + .expectNext(dave) // .verifyComplete(); } diff --git a/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/TransactionalServiceIntegrationTests.java b/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/TransactionalServiceIntegrationTests.java index e8b31e94..f3fe9869 100644 --- a/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/TransactionalServiceIntegrationTests.java +++ b/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/TransactionalServiceIntegrationTests.java @@ -21,13 +21,12 @@ import reactor.test.StepVerifier; import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.r2dbc.core.DatabaseClient; -import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests for {@link TransactionalService}. @@ -35,20 +34,19 @@ import org.springframework.test.context.junit4.SpringRunner; * @author Oliver Drotbohm * @soundtrack Shame - Tedeschi Trucks Band (Signs) */ -@RunWith(SpringRunner.class) @SpringBootTest(classes = InfrastructureConfiguration.class) -public class TransactionalServiceIntegrationTests { +class TransactionalServiceIntegrationTests { @Autowired TransactionalService service; @Autowired CustomerRepository repository; @Autowired DatabaseClient database; - @Before - public void setUp() { + @BeforeEach + void setUp() { Hooks.onOperatorDebug(); - List statements = Arrays.asList(// + var statements = Arrays.asList(// "DROP TABLE IF EXISTS customer;", "CREATE TABLE customer ( id SERIAL PRIMARY KEY, firstname VARCHAR(100) NOT NULL, lastname VARCHAR(100) NOT NULL);"); @@ -61,7 +59,7 @@ public class TransactionalServiceIntegrationTests { } @Test // #500 - public void exceptionTriggersRollback() { + void exceptionTriggersRollback() { service.save(new Customer(null, "Dave", "Matthews")) // .as(StepVerifier::create) // @@ -75,7 +73,7 @@ public class TransactionalServiceIntegrationTests { } @Test // #500 - public void insertsDataTransactionally() { + void insertsDataTransactionally() { service.save(new Customer(null, "Carter", "Beauford")) // .as(StepVerifier::create) // diff --git a/r2dbc/example/src/test/java/example/springdata/r2dbc/entitycallback/CustomerRepositoryIntegrationTests.java b/r2dbc/example/src/test/java/example/springdata/r2dbc/entitycallback/CustomerRepositoryIntegrationTests.java index 7202c051..3d1ae158 100644 --- a/r2dbc/example/src/test/java/example/springdata/r2dbc/entitycallback/CustomerRepositoryIntegrationTests.java +++ b/r2dbc/example/src/test/java/example/springdata/r2dbc/entitycallback/CustomerRepositoryIntegrationTests.java @@ -21,13 +21,11 @@ import reactor.test.StepVerifier; import java.io.IOException; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.r2dbc.core.DatabaseClient; -import org.springframework.test.context.junit4.SpringRunner; /** * Integration test using {@link org.springframework.data.r2dbc.mapping.event.BeforeConvertCallback} to auto-generate an @@ -36,24 +34,23 @@ import org.springframework.test.context.junit4.SpringRunner; * @author Mark Paluch * @see ApplicationConfiguration#idGeneratingCallback(DatabaseClient) */ -@RunWith(SpringRunner.class) @SpringBootTest -public class CustomerRepositoryIntegrationTests { +class CustomerRepositoryIntegrationTests { @Autowired CustomerRepository customers; @Autowired DatabaseClient database; @Test - public void generatesIdOnInsert() throws IOException { + void generatesIdOnInsert() throws IOException { - Customer dave = new Customer(null, "Dave", "Matthews"); + var dave = new Customer(null, "Dave", "Matthews"); this.customers.save(dave) // .as(StepVerifier::create) // .assertNext(actual -> { - assertThat(dave.getId()).isNull(); // immutable before save - assertThat(actual.getId()).isNotNull(); // after save + assertThat(dave.id()).isNull(); // immutable before save + assertThat(actual.id()).isNotNull(); // after save }).verifyComplete(); } } diff --git a/r2dbc/query-by-example/src/main/java/example/springdata/r2dbc/basics/Person.java b/r2dbc/query-by-example/src/main/java/example/springdata/r2dbc/basics/Person.java index 59af2dbd..9b68627b 100644 --- a/r2dbc/query-by-example/src/main/java/example/springdata/r2dbc/basics/Person.java +++ b/r2dbc/query-by-example/src/main/java/example/springdata/r2dbc/basics/Person.java @@ -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); + } } diff --git a/r2dbc/query-by-example/src/test/java/example/springdata/r2dbc/basics/PersonRepositoryIntegrationTests.java b/r2dbc/query-by-example/src/test/java/example/springdata/r2dbc/basics/PersonRepositoryIntegrationTests.java index 080fa748..109f31f5 100644 --- a/r2dbc/query-by-example/src/test/java/example/springdata/r2dbc/basics/PersonRepositoryIntegrationTests.java +++ b/r2dbc/query-by-example/src/test/java/example/springdata/r2dbc/basics/PersonRepositoryIntegrationTests.java @@ -52,7 +52,7 @@ class PersonRepositoryIntegrationTests { Hooks.onOperatorDebug(); - List 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 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 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 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 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 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 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() //