#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.
This commit is contained in:
Oliver Drotbohm
2019-03-12 13:07:40 +01:00
parent 7b0c7a539b
commit aa9ad22506
4 changed files with 29 additions and 34 deletions

View File

@@ -25,6 +25,6 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository;
*/
interface CustomerRepository extends ReactiveCrudRepository<Customer, Long> {
@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<Customer> findByLastnameLike(String lastname);
}

View File

@@ -54,6 +54,7 @@ public class CustomerRepositoryIntegrationTests {
.fetch() //
.rowsUpdated() //
.as(StepVerifier::create) //
.expectNextCount(1) //
.verifyComplete());
}

View File

@@ -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);
}
}

View File

@@ -21,35 +21,43 @@
</modules>
<properties>
<reactor-bom.version>Californium-SR3</reactor-bom.version>
<spring-data-releasetrain.version>Moore-M1</spring-data-releasetrain.version>
<h2.version>1.4.197</h2.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-bom</artifactId>
<version>Arabba-M7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-r2dbc</artifactId>
<version>1.0.0.M1</version>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-spi</artifactId>
<version>1.0.0.M6</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>1.0.0.M6</version>
<artifactId>r2dbc-h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.9.1</version>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
@@ -77,7 +85,8 @@
<profile>
<id>spring-data-next</id>
<properties>
<spring-data-releasetrain.version>Moore-BUILD-SNAPSHOT</spring-data-releasetrain.version>
<spring-data-releasetrain.version>Moore-BUILD-SNAPSHOT
</spring-data-releasetrain.version>
</properties>
</profile>