#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:
@@ -25,6 +25,6 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
|||||||
*/
|
*/
|
||||||
interface CustomerRepository extends ReactiveCrudRepository<Customer, Long> {
|
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);
|
Flux<Customer> findByLastnameLike(String lastname);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class CustomerRepositoryIntegrationTests {
|
|||||||
.fetch() //
|
.fetch() //
|
||||||
.rowsUpdated() //
|
.rowsUpdated() //
|
||||||
.as(StepVerifier::create) //
|
.as(StepVerifier::create) //
|
||||||
|
.expectNextCount(1) //
|
||||||
.verifyComplete());
|
.verifyComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,16 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package example.springdata.r2dbc.basics;
|
package example.springdata.r2dbc.basics;
|
||||||
|
|
||||||
import io.r2dbc.postgresql.PostgresqlConnectionConfiguration;
|
import io.r2dbc.h2.H2ConnectionConfiguration;
|
||||||
import io.r2dbc.postgresql.PostgresqlConnectionFactory;
|
import io.r2dbc.h2.H2ConnectionFactory;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
|
||||||
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
|
||||||
import org.testcontainers.containers.PostgreSQLContainer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
@@ -34,27 +31,15 @@ import org.testcontainers.containers.PostgreSQLContainer;
|
|||||||
@EnableR2dbcRepositories
|
@EnableR2dbcRepositories
|
||||||
class InfrastructureConfiguration extends AbstractR2dbcConfiguration {
|
class InfrastructureConfiguration extends AbstractR2dbcConfiguration {
|
||||||
|
|
||||||
private PostgreSQLContainer postgres = new PostgreSQLContainer();
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@Override
|
@Override
|
||||||
public PostgresqlConnectionFactory connectionFactory() {
|
public H2ConnectionFactory connectionFactory() {
|
||||||
|
|
||||||
postgres.start();
|
H2ConnectionConfiguration config = H2ConnectionConfiguration.builder() //
|
||||||
|
.inMemory("test-database2") //
|
||||||
PostgresqlConnectionConfiguration config = PostgresqlConnectionConfiguration.builder() //
|
.option("DB_CLOSE_DELAY=-1") //
|
||||||
.host(postgres.getContainerIpAddress()) //
|
|
||||||
.port(postgres.getFirstMappedPort()) //
|
|
||||||
.database(postgres.getDatabaseName()) //
|
|
||||||
.username(postgres.getUsername()) //
|
|
||||||
.password(postgres.getPassword()) //
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return new PostgresqlConnectionFactory(config);
|
return new H2ConnectionFactory(config);
|
||||||
}
|
|
||||||
|
|
||||||
@PreDestroy
|
|
||||||
void shutdown() {
|
|
||||||
postgres.stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,35 +21,43 @@
|
|||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<reactor-bom.version>Californium-SR3</reactor-bom.version>
|
<h2.version>1.4.197</h2.version>
|
||||||
<spring-data-releasetrain.version>Moore-M1</spring-data-releasetrain.version>
|
|
||||||
</properties>
|
</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>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-r2dbc</artifactId>
|
<artifactId>spring-data-r2dbc</artifactId>
|
||||||
<version>1.0.0.M1</version>
|
<version>1.0.0.BUILD-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.r2dbc</groupId>
|
<groupId>io.r2dbc</groupId>
|
||||||
<artifactId>r2dbc-spi</artifactId>
|
<artifactId>r2dbc-spi</artifactId>
|
||||||
<version>1.0.0.M6</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.r2dbc</groupId>
|
<groupId>io.r2dbc</groupId>
|
||||||
<artifactId>r2dbc-postgresql</artifactId>
|
<artifactId>r2dbc-h2</artifactId>
|
||||||
<version>1.0.0.M6</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.testcontainers</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
<version>1.9.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -77,7 +85,8 @@
|
|||||||
<profile>
|
<profile>
|
||||||
<id>spring-data-next</id>
|
<id>spring-data-next</id>
|
||||||
<properties>
|
<properties>
|
||||||
<spring-data-releasetrain.version>Moore-BUILD-SNAPSHOT</spring-data-releasetrain.version>
|
<spring-data-releasetrain.version>Moore-BUILD-SNAPSHOT
|
||||||
|
</spring-data-releasetrain.version>
|
||||||
</properties>
|
</properties>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user