From aa9ad225064f5adf612f1f97f48a8188c8dffe8d Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Tue, 12 Mar 2019 13:07:40 +0100 Subject: [PATCH] #495 - Polish R2DBC example. Upgrade to R2DBC Arabba M7 and Spring Data R2DBC snapshots. Switched configuration to use H2 instead of Postgres. Changed query definition in Spring Data repository to use named parameters instead of database specific placeholders. --- .../r2dbc/basics/CustomerRepository.java | 2 +- .../CustomerRepositoryIntegrationTests.java | 1 + .../basics/InfrastructureConfiguration.java | 31 +++++-------------- r2dbc/pom.xml | 29 +++++++++++------ 4 files changed, 29 insertions(+), 34 deletions(-) diff --git a/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/CustomerRepository.java b/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/CustomerRepository.java index 42332462..1f1d30af 100644 --- a/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/CustomerRepository.java +++ b/r2dbc/example/src/main/java/example/springdata/r2dbc/basics/CustomerRepository.java @@ -25,6 +25,6 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository; */ interface CustomerRepository extends ReactiveCrudRepository { - @Query("select id, firstname, lastname from customer c where c.lastname = $1") + @Query("select id, firstname, lastname from customer c where c.lastname = :lastname") Flux findByLastnameLike(String 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 8037f2a7..6cda04a4 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 @@ -54,6 +54,7 @@ public class CustomerRepositoryIntegrationTests { .fetch() // .rowsUpdated() // .as(StepVerifier::create) // + .expectNextCount(1) // .verifyComplete()); } diff --git a/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/InfrastructureConfiguration.java b/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/InfrastructureConfiguration.java index 06e36a95..7cc52fdf 100644 --- a/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/InfrastructureConfiguration.java +++ b/r2dbc/example/src/test/java/example/springdata/r2dbc/basics/InfrastructureConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 the original author or authors. + * Copyright 2018-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,13 @@ */ package example.springdata.r2dbc.basics; -import io.r2dbc.postgresql.PostgresqlConnectionConfiguration; -import io.r2dbc.postgresql.PostgresqlConnectionFactory; - -import javax.annotation.PreDestroy; +import io.r2dbc.h2.H2ConnectionConfiguration; +import io.r2dbc.h2.H2ConnectionFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration; import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; -import org.testcontainers.containers.PostgreSQLContainer; /** * @author Oliver Gierke @@ -34,27 +31,15 @@ import org.testcontainers.containers.PostgreSQLContainer; @EnableR2dbcRepositories class InfrastructureConfiguration extends AbstractR2dbcConfiguration { - private PostgreSQLContainer postgres = new PostgreSQLContainer(); - @Bean @Override - public PostgresqlConnectionFactory connectionFactory() { + public H2ConnectionFactory connectionFactory() { - postgres.start(); - - PostgresqlConnectionConfiguration config = PostgresqlConnectionConfiguration.builder() // - .host(postgres.getContainerIpAddress()) // - .port(postgres.getFirstMappedPort()) // - .database(postgres.getDatabaseName()) // - .username(postgres.getUsername()) // - .password(postgres.getPassword()) // + H2ConnectionConfiguration config = H2ConnectionConfiguration.builder() // + .inMemory("test-database2") // + .option("DB_CLOSE_DELAY=-1") // .build(); - return new PostgresqlConnectionFactory(config); - } - - @PreDestroy - void shutdown() { - postgres.stop(); + return new H2ConnectionFactory(config); } } diff --git a/r2dbc/pom.xml b/r2dbc/pom.xml index 2ac8e4e7..91b64a33 100644 --- a/r2dbc/pom.xml +++ b/r2dbc/pom.xml @@ -21,35 +21,43 @@ - Californium-SR3 - Moore-M1 + 1.4.197 + + + + io.r2dbc + r2dbc-bom + Arabba-M7 + pom + import + + + + org.springframework.data spring-data-r2dbc - 1.0.0.M1 + 1.0.0.BUILD-SNAPSHOT io.r2dbc r2dbc-spi - 1.0.0.M6 io.r2dbc - r2dbc-postgresql - 1.0.0.M6 + r2dbc-h2 test - org.testcontainers - postgresql - 1.9.1 + com.h2database + h2 @@ -77,7 +85,8 @@ spring-data-next - Moore-BUILD-SNAPSHOT + Moore-BUILD-SNAPSHOT +