├── .gitignore ├── src ├── test │ ├── resources │ │ ├── container-license-acceptance.txt │ │ └── logback-test.xml │ └── java │ │ └── io │ │ └── r2dbc │ │ └── client │ │ ├── MockResultBearing.java │ │ ├── BatchTest.java │ │ ├── util │ │ └── ChangeLogReportGenerator.java │ │ ├── ResultBearingTest.java │ │ ├── UpdateTest.java │ │ ├── MssqlExample.java │ │ ├── PostgresqlExample.java │ │ ├── QueryTest.java │ │ ├── MysqlExample.java │ │ ├── H2Example.java │ │ ├── R2dbcTest.java │ │ ├── Example.java │ │ └── HandleTest.java └── main │ └── java │ └── io │ └── r2dbc │ └── client │ ├── util │ ├── package-info.java │ ├── Assert.java │ └── ReactiveUtils.java │ ├── package-info.java │ ├── Batch.java │ ├── ResultBearing.java │ ├── Update.java │ ├── Query.java │ ├── R2dbc.java │ └── Handle.java ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── ci ├── builder.yml ├── release.yml ├── create-release.sh ├── release.sh ├── build.yml ├── Dockerfile ├── build.sh └── docker-lib.sh ├── NOTICE ├── CHANGELOG ├── README.md ├── mvnw.cmd ├── mvnw ├── LICENSE ├── intellij-style.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .idea 3 | target 4 | .flattened-pom.xml 5 | -------------------------------------------------------------------------------- /src/test/resources/container-license-acceptance.txt: -------------------------------------------------------------------------------- 1 | mcr.microsoft.com/mssql/server:2017-CU12 2 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/r2dbc/r2dbc-client/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.1/apache-maven-3.6.1-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar 3 | -------------------------------------------------------------------------------- /ci/builder.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: concourse/builder 8 | 9 | inputs: 10 | - name: builder 11 | 12 | outputs: 13 | - name: image 14 | 15 | caches: 16 | - path: cache 17 | 18 | run: 19 | path: build 20 | 21 | params: 22 | CONTEXT: builder/ci 23 | -------------------------------------------------------------------------------- /ci/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: r2dbc/r2dbc-client 8 | 9 | inputs: 10 | - name: r2dbc-client 11 | 12 | outputs: 13 | - name: r2dbc-client-artifactory 14 | 15 | caches: 16 | - path: maven 17 | 18 | run: 19 | path: r2dbc-client/ci/release.sh 20 | -------------------------------------------------------------------------------- /ci/create-release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | RELEASE=$1 6 | SNAPSHOT=$2 7 | 8 | ./mvnw versions:set -DnewVersion=$RELEASE -DgenerateBackupPoms=false 9 | git add . 10 | git commit --message "v$RELEASE Release" 11 | git tag -s v$RELEASE -m "v$RELEASE" 12 | 13 | git reset --hard HEAD^1 14 | ./mvnw versions:set -DnewVersion=$SNAPSHOT -DgenerateBackupPoms=false 15 | git add . 16 | git commit --message "v$SNAPSHOT Development" 17 | -------------------------------------------------------------------------------- /ci/release.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | source r2dbc-client/ci/docker-lib.sh 6 | start_docker "3" "3" "" "" 7 | 8 | [[ -d $PWD/maven && ! -d $HOME/.m2 ]] && ln -s $PWD/maven $HOME/.m2 9 | 10 | r2dbc_client_artifactory=$(pwd)/r2dbc-client-artifactory 11 | 12 | rm -rf $HOME/.m2/repository/io/r2dbc 2> /dev/null || : 13 | 14 | cd r2dbc-client 15 | ./mvnw deploy \ 16 | -DaltDeploymentRepository=distribution::default::file://${r2dbc_client_artifactory} 17 | -------------------------------------------------------------------------------- /ci/build.yml: -------------------------------------------------------------------------------- 1 | --- 2 | platform: linux 3 | 4 | image_resource: 5 | type: registry-image 6 | source: 7 | repository: r2dbc/r2dbc-client 8 | 9 | inputs: 10 | - name: r2dbc-client 11 | - name: r2dbc-h2-artifactory 12 | - name: r2dbc-mssql-artifactory 13 | - name: r2dbc-pool-artifactory 14 | - name: r2dbc-postgresql-artifactory 15 | - name: r2dbc-spi-artifactory 16 | 17 | outputs: 18 | - name: r2dbc-client-artifactory 19 | 20 | caches: 21 | - path: maven 22 | 23 | run: 24 | path: r2dbc-client/ci/build.sh 25 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Reactive Relational Database Connectivity 2 | 3 | Copyright 2017-2018 the original author or authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | https://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /ci/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk 2 | 3 | RUN apt-get update && apt-get install --no-install-recommends -y \ 4 | apt-transport-https \ 5 | ca-certificates \ 6 | curl \ 7 | gnupg2 \ 8 | software-properties-common \ 9 | && rm -rf /var/lib/apt/lists/* 10 | 11 | RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - 12 | 13 | RUN add-apt-repository \ 14 | "deb [arch=amd64] https://download.docker.com/linux/debian \ 15 | $(lsb_release -cs) \ 16 | stable" 17 | 18 | RUN apt-get update && apt-get install --no-install-recommends -y \ 19 | docker-ce \ 20 | && rm -rf /var/lib/apt/lists/* 21 | 22 | RUN mkdir -p /root/.docker \ 23 | && echo "{}" > /root/.docker/config.json 24 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Utility code used throughout the project. 19 | */ 20 | 21 | @NonNullApi 22 | package io.r2dbc.client.util; 23 | 24 | import reactor.util.annotation.NonNullApi; 25 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * The client Reactive Relational Database Connection API. 19 | */ 20 | 21 | @NonNullApi 22 | package io.r2dbc.client; 23 | 24 | import reactor.util.annotation.NonNullApi; 25 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | R2DBC Client Changelog 2 | ============================= 3 | 4 | 0.8.0.RC1 5 | ------------------ 6 | * Release 0.8.0.RC1 #62. 7 | * Upgrade to Reactor Dysprosium GA #61. 8 | * Upgrade to changed MySQL driver coordinates #60. 9 | * Remove repositories declaration from published pom #59. 10 | * Replace Jasync with r2dbc-mysql in the suite of database tests #56. 11 | * Upgrade to JAsync 1.0.6 and remove jcenter repository declaration #55. 12 | * Adapt to Statement.bind and Row.get by name #54. 13 | * Class javadoc of r2dbc mentions postgresql #53. 14 | * Adapt to SPI changes for TransactionIsolation #52. 15 | * testcontainers-java 1.12.0 #51. 16 | * 0.8.0.RC1 Changelog #48. 17 | 18 | 0.8.0.M8 19 | ------------------ 20 | * Added MySQL Example 21 | 22 | 1.0.0.M7 23 | ------------------ 24 | * Update changelong for M7 #37 25 | * ConnectionFactory Discovery #31, #32, #33 26 | * Nullability enforcement returns accurate exception #29 27 | 28 | 1.0.0.M6 29 | ------------------ 30 | * MSSQL Examples #24 31 | * H2 Examples #18 32 | * Extract Examples #19 33 | -------------------------------------------------------------------------------- /ci/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | source r2dbc-client/ci/docker-lib.sh 6 | start_docker "3" "3" "" "" 7 | 8 | [[ -d $PWD/maven && ! -d $HOME/.m2 ]] && ln -s $PWD/maven $HOME/.m2 9 | 10 | r2dbc_client_artifactory=$(pwd)/r2dbc-client-artifactory 11 | r2dbc_h2_artifactory=$(pwd)/r2dbc-h2-artifactory 12 | r2dbc_mssql_artifactory=$(pwd)/r2dbc-mssql-artifactory 13 | r2dbc_pool_artifactory=$(pwd)/r2dbc-pool-artifactory 14 | r2dbc_postgresql_artifactory=$(pwd)/r2dbc-postgresql-artifactory 15 | r2dbc_spi_artifactory=$(pwd)/r2dbc-spi-artifactory 16 | 17 | rm -rf $HOME/.m2/repository/io/r2dbc 2> /dev/null || : 18 | 19 | cd r2dbc-client 20 | ./mvnw deploy \ 21 | -DaltDeploymentRepository=distribution::default::file://${r2dbc_client_artifactory} \ 22 | -Dr2dbcH2Artifactory=file://${r2dbc_h2_artifactory} \ 23 | -Dr2dbcMssqlArtifactory=file://${r2dbc_mssql_artifactory} \ 24 | -Dr2dbcPoolArtifactory=file://${r2dbc_pool_artifactory} \ 25 | -Dr2dbcPostgresqlArtifactory=file://${r2dbc_postgresql_artifactory} \ 26 | -Dr2dbcSpiArtifactory=file://${r2dbc_spi_artifactory} 27 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | %date{HH:mm:ss.SSS} %-18thread %-55logger %msg%n 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/util/Assert.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client.util; 18 | 19 | import reactor.util.annotation.Nullable; 20 | 21 | /** 22 | * Assertion library for the implementation. 23 | */ 24 | public final class Assert { 25 | 26 | private Assert() { 27 | } 28 | 29 | /** 30 | * Checks that a specified object reference is not {@code null} and throws a customized {@link IllegalArgumentException} if it is. 31 | * 32 | * @param t the object reference to check for nullity 33 | * @param message the detail message to be used in the event that an {@link IllegalArgumentException} is thrown 34 | * @param the type of the reference 35 | * @return {@code t} if not {@code null} 36 | * @throws IllegalArgumentException if {@code t} is {code null} 37 | */ 38 | public static T requireNonNull(@Nullable T t, String message) { 39 | if (t == null) { 40 | throw new IllegalArgumentException(message); 41 | } 42 | 43 | return t; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/Batch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.client.util.Assert; 20 | import io.r2dbc.spi.Result; 21 | import org.reactivestreams.Publisher; 22 | import reactor.core.publisher.Flux; 23 | 24 | import java.util.function.Function; 25 | 26 | /** 27 | * A wrapper for a {@link io.r2dbc.spi.Batch} providing additional convenience APIs 28 | */ 29 | public final class Batch implements ResultBearing { 30 | 31 | private final io.r2dbc.spi.Batch batch; 32 | 33 | Batch(io.r2dbc.spi.Batch batch) { 34 | this.batch = Assert.requireNonNull(batch, "batch must not be null"); 35 | } 36 | 37 | /** 38 | * Add a statement to this batch. 39 | * 40 | * @param sql the statement to add 41 | * @return this {@link Batch} 42 | * @throws IllegalArgumentException if {@code sql} is {@code null} 43 | */ 44 | public Batch add(String sql) { 45 | Assert.requireNonNull(sql, "sql must not be null"); 46 | 47 | this.batch.add(sql); 48 | return this; 49 | } 50 | 51 | public Flux mapResult(Function> mappingFunction) { 52 | Assert.requireNonNull(mappingFunction, "mappingFunction must not be null"); 53 | 54 | return Flux.from(this.batch.execute()) 55 | .flatMap(mappingFunction); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "Batch{" + 61 | "batch=" + this.batch + 62 | '}'; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project is no longer being actively maintained. 2 | 3 | # Reactive Relational Database Connectivity Client (Archived) 4 | This project is an exploration of what a Java API for relational database access with [Reactive Streams][rs] might look like. It uses [Project Reactor][pr]. It uses [Jdbi][jd] as an inspiration. 5 | 6 | [jd]: http://jdbi.org 7 | [pr]: https://projectreactor.io 8 | [rs]: https://www.reactive-streams.org 9 | 10 | ## Examples 11 | A quick example of configuration and execution would look like: 12 | 13 | ```java 14 | PostgresqlConnectionConfiguration configuration = PostgresqlConnectionConfiguration.builder() 15 | .host("") 16 | .database("") 17 | .username("") 18 | .password("") 19 | .build(); 20 | 21 | R2dbc r2dbc = new R2dbc(new PostgresqlConnectionFactory(configuration)); 22 | 23 | r2dbc.inTransaction(handle -> 24 | handle.execute("INSERT INTO test VALUES ($1)", 100)) 25 | 26 | .thenMany(r2dbc.inTransaction(handle -> 27 | handle.select("SELECT value FROM test") 28 | .mapResult(result -> result.map((row, rowMetadata) -> row.get("value", Integer.class))))) 29 | 30 | .subscribe(System.out::println); 31 | ``` 32 | 33 | ## Maven 34 | Both milestone and snapshot artifacts (library, source, and javadoc) can be found in Maven repositories. 35 | 36 | ```xml 37 | 38 | io.r2dbc 39 | r2dbc-client 40 | 0.8.0.RC1 41 | 42 | ``` 43 | 44 | Artifacts can bound found at the following repositories. 45 | 46 | ### Repositories 47 | ```xml 48 | 49 | spring-snapshots 50 | Spring Snapshots 51 | https://repo.spring.io/snapshot 52 | 53 | true 54 | 55 | 56 | ``` 57 | 58 | ```xml 59 | 60 | spring-milestones 61 | Spring Milestones 62 | https://repo.spring.io/milestone 63 | 64 | false 65 | 66 | 67 | ``` 68 | 69 | ## License 70 | This project is released under version 2.0 of the [Apache License][l]. 71 | 72 | [l]: https://www.apache.org/licenses/LICENSE-2.0 73 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/MockResultBearing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.client.util.Assert; 20 | import io.r2dbc.spi.Result; 21 | import org.reactivestreams.Publisher; 22 | import reactor.core.publisher.Flux; 23 | 24 | import java.util.function.Function; 25 | 26 | public final class MockResultBearing implements ResultBearing { 27 | 28 | private final Result result; 29 | 30 | private MockResultBearing(Result result) { 31 | this.result = Assert.requireNonNull(result, "result must not be null"); 32 | } 33 | 34 | public static Builder builder() { 35 | return new Builder(); 36 | } 37 | 38 | @Override 39 | public Flux mapResult(Function> mappingFunction) { 40 | Assert.requireNonNull(mappingFunction, "mappingFunction must not be null"); 41 | 42 | return Flux.from(mappingFunction.apply(this.result)); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "MockResultBearing{" + 48 | "result=" + this.result + 49 | '}'; 50 | } 51 | 52 | public static final class Builder { 53 | 54 | private Result result; 55 | 56 | private Builder() { 57 | } 58 | 59 | public MockResultBearing build() { 60 | return new MockResultBearing(this.result); 61 | } 62 | 63 | public Builder result(Result result) { 64 | this.result = Assert.requireNonNull(result, "result must not be null"); 65 | return this; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return "Builder{" + 71 | "result=" + this.result + 72 | '}'; 73 | } 74 | 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/BatchTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.spi.test.MockBatch; 20 | import io.r2dbc.spi.test.MockResult; 21 | import org.junit.jupiter.api.Test; 22 | import reactor.core.publisher.Mono; 23 | import reactor.test.StepVerifier; 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 27 | 28 | final class BatchTest { 29 | 30 | @Test 31 | void add() { 32 | MockBatch batch = MockBatch.empty(); 33 | 34 | new Batch(batch) 35 | .add("test-query"); 36 | 37 | assertThat(batch.getSqls()).contains("test-query"); 38 | } 39 | 40 | @Test 41 | void addNoSql() { 42 | assertThatIllegalArgumentException().isThrownBy(() -> new Batch(MockBatch.empty()).add(null)) 43 | .withMessage("sql must not be null"); 44 | } 45 | 46 | @Test 47 | void constructorNoBatch() { 48 | assertThatIllegalArgumentException().isThrownBy(() -> new Batch(null)) 49 | .withMessage("batch must not be null"); 50 | } 51 | 52 | @Test 53 | void mapResult() { 54 | MockResult result = MockResult.empty(); 55 | 56 | MockBatch batch = MockBatch.builder() 57 | .result(result) 58 | .build(); 59 | 60 | new Batch(batch) 61 | .mapResult(actual -> { 62 | assertThat(actual).isSameAs(result); 63 | return Mono.just(1); 64 | }) 65 | .as(StepVerifier::create) 66 | .expectNext(1) 67 | .verifyComplete(); 68 | } 69 | 70 | @Test 71 | void mapResultNoF() { 72 | assertThatIllegalArgumentException().isThrownBy(() -> new Batch(MockBatch.empty()).mapResult(null)) 73 | .withMessage("mappingFunction must not be null"); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/util/ReactiveUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client.util; 18 | 19 | import org.reactivestreams.Publisher; 20 | import reactor.core.publisher.Flux; 21 | import reactor.core.publisher.Mono; 22 | 23 | import java.util.function.Function; 24 | import java.util.function.Supplier; 25 | 26 | /** 27 | * Utilities for working with Reactive flows. 28 | */ 29 | public final class ReactiveUtils { 30 | 31 | private ReactiveUtils() { 32 | } 33 | 34 | /** 35 | * Execute the {@link Publisher} provided by a {@link Supplier} and propagate the error that initiated this behavior. Typically used with {@link Flux#onErrorResume(Function)} and 36 | * {@link Mono#onErrorResume(Function)}. 37 | * 38 | * @param s a {@link Supplier} of a {@link Publisher} to execute when an error occurs 39 | * @param the type passing through the flow 40 | * @return a {@link Mono#error(Throwable)} with the original error 41 | * @see Flux#onErrorResume(Function) 42 | * @see Mono#onErrorResume(Function) 43 | */ 44 | public static Function> appendError(Supplier> s) { 45 | Assert.requireNonNull(s, "s must not be null"); 46 | 47 | return t -> 48 | Flux.from(s.get()) 49 | .then(Mono.error(t)); 50 | } 51 | 52 | /** 53 | * Convert a {@code Publisher} to a {@code Publisher} allowing for type passthrough behavior. 54 | * 55 | * @param s a {@link Supplier} of a {@link Publisher} to execute 56 | * @param the type passing through the flow 57 | * @return {@link Mono#empty()} of the appropriate type 58 | */ 59 | public static Mono typeSafe(Supplier> s) { 60 | Assert.requireNonNull(s, "s must not be null"); 61 | 62 | return Flux.from(s.get()) 63 | .then(Mono.empty()); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/ResultBearing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.client.util.Assert; 20 | import io.r2dbc.spi.Result; 21 | import io.r2dbc.spi.Row; 22 | import io.r2dbc.spi.RowMetadata; 23 | import org.reactivestreams.Publisher; 24 | import reactor.core.publisher.Flux; 25 | 26 | import java.util.function.BiFunction; 27 | import java.util.function.Function; 28 | 29 | /** 30 | * An interface indicating that a type returns results. 31 | */ 32 | public interface ResultBearing { 33 | 34 | /** 35 | * Transforms the {@link Result}s that are returned from execution. 36 | * 37 | * @param mappingFunction a {@link Function} used to transform each {@link Result} into a {@code Publisher} of values 38 | * @param the type of results 39 | * @return the values resulting from the {@link Result} transformation 40 | * @throws IllegalArgumentException if {@code mappingFunction} is {@code null} 41 | * @see #mapRow(Function) 42 | * @see #mapRow(BiFunction) 43 | */ 44 | Flux mapResult(Function> mappingFunction); 45 | 46 | /** 47 | * Transforms each {@link Row} and {@link RowMetadata} pair into an object. 48 | * 49 | * @param mappingFunction a {@link BiFunction} used to transform each {@link Row} and {@link RowMetadata} pair into an object 50 | * @param the type of results 51 | * @return the values resulting from the {@link Row} and {@link RowMetadata} transformation 52 | * @throws IllegalArgumentException if {@code mappingFunction} is {@code null} 53 | */ 54 | default Flux mapRow(BiFunction mappingFunction) { 55 | Assert.requireNonNull(mappingFunction, "mappingFunction must not be null"); 56 | 57 | return mapResult(result -> result.map(mappingFunction)); 58 | } 59 | 60 | /** 61 | * Transforms each {@link Row} into an object. 62 | * 63 | * @param mappingFunction a {@link Function} used to transform each {@link Row} into an object 64 | * @param the type of the results 65 | * @return the values resulting from the {@link Row} transformation 66 | * @throws IllegalArgumentException if {@code mappingFunction} is {@code null} 67 | */ 68 | default Flux mapRow(Function mappingFunction) { 69 | Assert.requireNonNull(mappingFunction, "mappingFunction must not be null"); 70 | 71 | return mapRow((row, rowMetadata) -> mappingFunction.apply(row)); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/util/ChangeLogReportGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client.util; 18 | 19 | import com.jayway.jsonpath.JsonPath; 20 | import net.minidev.json.JSONArray; 21 | import org.springframework.hateoas.IanaLinkRelations; 22 | import org.springframework.hateoas.Links; 23 | import org.springframework.http.HttpEntity; 24 | import org.springframework.http.HttpHeaders; 25 | import org.springframework.web.reactive.function.client.WebClient; 26 | 27 | import java.time.Duration; 28 | import java.util.Iterator; 29 | import java.util.List; 30 | 31 | /** 32 | * Changelog report generator. 33 | */ 34 | final class ChangeLogReportGenerator { 35 | 36 | private static final int MILESTONE_ID = 6; 37 | private static final String URI_TEMPLATE = "https://api.github.com/repos/r2dbc/r2dbc-client/issues?milestone={id}&state=closed"; 38 | 39 | public static void main(String... args) { 40 | 41 | /* 42 | * If you run into github rate limiting issues, you can always use a Github Personal Token by adding 43 | * {@code .header(HttpHeaders.AUTHORIZATION, "token your-github-token")} to the webClient call. 44 | */ 45 | 46 | WebClient webClient = WebClient.create(); 47 | 48 | HttpEntity response = webClient // 49 | .get().uri(URI_TEMPLATE, MILESTONE_ID) // 50 | .exchange() // 51 | .flatMap(clientResponse -> clientResponse.toEntity(String.class)) // 52 | .block(Duration.ofSeconds(10)); 53 | 54 | boolean keepChecking = true; 55 | boolean printHeader = true; 56 | 57 | while (keepChecking) { 58 | 59 | readPage(response.getBody(), printHeader); 60 | printHeader = false; 61 | 62 | List linksInHeader = response.getHeaders().get(HttpHeaders.LINK); 63 | Links links = linksInHeader == null ? Links.NONE : Links.parse(linksInHeader.get(0)); 64 | 65 | if (links.getLink(IanaLinkRelations.NEXT).isPresent()) { 66 | 67 | response = webClient // 68 | .get().uri(links.getRequiredLink(IanaLinkRelations.NEXT).expand().getHref()) // 69 | .exchange() // 70 | .flatMap(clientResponse -> clientResponse.toEntity(String.class)) // 71 | .block(Duration.ofSeconds(10)); 72 | 73 | } else { 74 | keepChecking = false; 75 | } 76 | } 77 | } 78 | 79 | private static void readPage(String content, boolean header) { 80 | 81 | JsonPath titlePath = JsonPath.compile("$[*].title"); 82 | JsonPath idPath = JsonPath.compile("$[*].number"); 83 | 84 | JSONArray titles = titlePath.read(content); 85 | Iterator ids = ((JSONArray) idPath.read(content)).iterator(); 86 | 87 | if (header) { 88 | System.out.println(JsonPath.read(content, "$[1].milestone.title").toString()); 89 | System.out.println("------------------"); 90 | } 91 | 92 | for (Object title : titles) { 93 | 94 | String format = String.format("* %s #%s", title, ids.next()); 95 | System.out.println(format.endsWith(".") ? format : format.concat(".")); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/ResultBearingTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.spi.Row; 20 | import io.r2dbc.spi.RowMetadata; 21 | import io.r2dbc.spi.test.MockColumnMetadata; 22 | import io.r2dbc.spi.test.MockResult; 23 | import io.r2dbc.spi.test.MockRow; 24 | import io.r2dbc.spi.test.MockRowMetadata; 25 | import org.junit.jupiter.api.Test; 26 | import reactor.test.StepVerifier; 27 | import reactor.util.function.Tuples; 28 | 29 | import java.util.function.BiFunction; 30 | import java.util.function.Function; 31 | 32 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 33 | 34 | final class ResultBearingTest { 35 | 36 | @Test 37 | void mapRowBiFunction() { 38 | MockRowMetadata rowMetadata = MockRowMetadata.builder() 39 | .columnMetadata(MockColumnMetadata.builder() 40 | .name("test-name") 41 | .nativeTypeMetadata(100) 42 | .build()) 43 | .build(); 44 | 45 | MockRow row1 = MockRow.builder() 46 | .identified("test-identifier-1", Object.class, new Object()) 47 | .build(); 48 | 49 | MockRow row2 = MockRow.builder() 50 | .identified("test-identifier-2", Object.class, new Object()) 51 | .build(); 52 | 53 | MockResultBearing resultBearing = MockResultBearing.builder() 54 | .result(MockResult.builder() 55 | .rowMetadata(rowMetadata) 56 | .row(row1, row2) 57 | .build()) 58 | .build(); 59 | 60 | resultBearing 61 | .mapRow(Tuples::of) 62 | .as(StepVerifier::create) 63 | .expectNext(Tuples.of(row1, rowMetadata)) 64 | .expectNext(Tuples.of(row2, rowMetadata)) 65 | .verifyComplete(); 66 | } 67 | 68 | @Test 69 | void mapRowBiFunctionNoF() { 70 | MockResultBearing resultBearing = MockResultBearing.builder() 71 | .result(MockResult.empty()) 72 | .build(); 73 | 74 | assertThatIllegalArgumentException().isThrownBy(() -> resultBearing.mapRow((BiFunction) null)) 75 | .withMessage("mappingFunction must not be null"); 76 | } 77 | 78 | @Test 79 | void mapRowFunction() { 80 | MockRow row1 = MockRow.builder() 81 | .identified("test-identifier-1", Object.class, new Object()) 82 | .build(); 83 | 84 | MockRow row2 = MockRow.builder() 85 | .identified("test-identifier-2", Object.class, new Object()) 86 | .build(); 87 | 88 | MockResultBearing resultBearing = MockResultBearing.builder() 89 | .result(MockResult.builder() 90 | .rowMetadata(MockRowMetadata.empty()) 91 | .row(row1, row2) 92 | .build()) 93 | .build(); 94 | 95 | resultBearing 96 | .mapRow(Function.identity()) 97 | .as(StepVerifier::create) 98 | .expectNext(row1) 99 | .expectNext(row2) 100 | .verifyComplete(); 101 | } 102 | 103 | @Test 104 | void mapRowFunctionNoF() { 105 | MockResultBearing resultBearing = MockResultBearing.builder() 106 | .result(MockResult.empty()) 107 | .build(); 108 | 109 | assertThatIllegalArgumentException().isThrownBy(() -> resultBearing.mapRow((Function) null)) 110 | .withMessage("mappingFunction must not be null"); 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/UpdateTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.spi.test.MockResult; 20 | import io.r2dbc.spi.test.MockStatement; 21 | import org.junit.jupiter.api.Test; 22 | import reactor.test.StepVerifier; 23 | 24 | import java.util.Collections; 25 | 26 | import static org.assertj.core.api.Assertions.assertThat; 27 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 28 | 29 | final class UpdateTest { 30 | 31 | @Test 32 | void add() { 33 | MockStatement statement = MockStatement.empty(); 34 | 35 | new Update(statement) 36 | .add(); 37 | 38 | assertThat(statement.isAddCalled()).isTrue(); 39 | } 40 | 41 | @Test 42 | void bind() { 43 | MockStatement statement = MockStatement.empty(); 44 | 45 | new Update(statement) 46 | .bind("test-identifier", "test-value"); 47 | 48 | assertThat(statement.getBindings()).contains(Collections.singletonMap("test-identifier", "test-value")); 49 | } 50 | 51 | @Test 52 | void bindIndex() { 53 | MockStatement statement = MockStatement.empty(); 54 | 55 | new Update(statement) 56 | .bind(100, "test-value"); 57 | 58 | assertThat(statement.getBindings()).contains(Collections.singletonMap(100, "test-value")); 59 | } 60 | 61 | @Test 62 | void bindIndexNoValue() { 63 | assertThatIllegalArgumentException().isThrownBy(() -> new Update(MockStatement.empty()).bind(100, null)) 64 | .withMessage("value must not be null"); 65 | } 66 | 67 | @Test 68 | void bindNoIdentifier() { 69 | assertThatIllegalArgumentException().isThrownBy(() -> new Update(MockStatement.empty()).bind(null, new Object())) 70 | .withMessage("identifier must not be null"); 71 | } 72 | 73 | @Test 74 | void bindNoValue() { 75 | assertThatIllegalArgumentException().isThrownBy(() -> new Update(MockStatement.empty()).bind("test-identifier", null)) 76 | .withMessage("value must not be null"); 77 | } 78 | 79 | @Test 80 | void bindNull() { 81 | MockStatement statement = MockStatement.empty(); 82 | 83 | new Update(statement) 84 | .bindNull("test-identifier", Integer.class); 85 | 86 | assertThat(statement.getBindings()).contains(Collections.singletonMap("test-identifier", Integer.class)); 87 | } 88 | 89 | @Test 90 | void bindNullNoIdentifier() { 91 | assertThatIllegalArgumentException().isThrownBy(() -> new Update(MockStatement.empty()).bindNull(null, Object.class)) 92 | .withMessage("identifier must not be null"); 93 | } 94 | 95 | @Test 96 | void bindNullNoType() { 97 | assertThatIllegalArgumentException().isThrownBy(() -> new Update(MockStatement.empty()).bindNull("test-identifier", null)) 98 | .withMessage("type must not be null"); 99 | } 100 | 101 | @Test 102 | void constructorNoStatement() { 103 | assertThatIllegalArgumentException().isThrownBy(() -> new Update(null)) 104 | .withMessage("statement must not be null"); 105 | } 106 | 107 | @Test 108 | void execute() { 109 | MockResult result = MockResult.builder() 110 | .rowsUpdated(100) 111 | .build(); 112 | 113 | MockStatement statement = MockStatement.builder() 114 | .result(result) 115 | .build(); 116 | 117 | new Update(statement) 118 | .execute() 119 | .as(StepVerifier::create) 120 | .expectNext(100) 121 | .verifyComplete(); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/Update.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.client.util.Assert; 20 | import io.r2dbc.spi.Result; 21 | import io.r2dbc.spi.Statement; 22 | import reactor.core.publisher.Flux; 23 | 24 | /** 25 | * A wrapper for a {@link Statement} providing additional convenience APIs for running updates such as {@code INSERT} and {@code DELETE}. 26 | */ 27 | public final class Update { 28 | 29 | private final Statement statement; 30 | 31 | Update(Statement statement) { 32 | this.statement = Assert.requireNonNull(statement, "statement must not be null"); 33 | } 34 | 35 | /** 36 | * Save the current binding and create a new one. 37 | * 38 | * @return this {@link Statement} 39 | */ 40 | public Update add() { 41 | this.statement.add(); 42 | return this; 43 | } 44 | 45 | /** 46 | * Bind a value. 47 | * 48 | * @param identifier the identifier to bind to 49 | * @param value the value to bind 50 | * @return this {@link Statement} 51 | * @throws IllegalArgumentException if {@code identifier} or {@code value} is {@code null} 52 | */ 53 | public Update bind(String identifier, Object value) { 54 | Assert.requireNonNull(identifier, "identifier must not be null"); 55 | Assert.requireNonNull(value, "value must not be null"); 56 | 57 | this.statement.bind(identifier, value); 58 | return this; 59 | } 60 | 61 | /** 62 | * Bind a value. 63 | * 64 | * @param index the index to bind to 65 | * @param value the value to bind 66 | * @return this {@link Statement} 67 | * @throws IllegalArgumentException if {@code identifier} or {@code value} is {@code null} 68 | */ 69 | public Update bind(int index, Object value) { 70 | Assert.requireNonNull(value, "value must not be null"); 71 | 72 | this.statement.bind(index, value); 73 | return this; 74 | } 75 | 76 | /** 77 | * Bind a {@code null} value. 78 | * 79 | * @param identifier the identifier to bind to 80 | * @param type the type of null value 81 | * @return this {@link Statement} 82 | * @throws IllegalArgumentException if {@code identifier} or {@code type} is {@code null} 83 | */ 84 | public Update bindNull(String identifier, Class type) { 85 | Assert.requireNonNull(identifier, "identifier must not be null"); 86 | Assert.requireNonNull(type, "type must not be null"); 87 | 88 | this.statement.bindNull(identifier, type); 89 | return this; 90 | } 91 | 92 | /** 93 | * Bind a {@code null} value. 94 | * 95 | * @param index the index to bind to 96 | * @param type the type of null value 97 | * @return this {@link Statement} 98 | * @throws IllegalArgumentException if {@code identifier} or {@code type} is {@code null} 99 | */ 100 | public Update bindNull(int index, Class type) { 101 | Assert.requireNonNull(type, "type must not be null"); 102 | 103 | this.statement.bindNull(index, type); 104 | return this; 105 | } 106 | 107 | /** 108 | * Executes the update and returns the number of rows that were updated. 109 | * 110 | * @return the number of rows that were updated 111 | */ 112 | public Flux execute() { 113 | return Flux 114 | .from(this.statement.execute()) 115 | .flatMap(Result::getRowsUpdated); 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | return "Update{" + 121 | "statement=" + this.statement + 122 | '}'; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/MssqlExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import com.zaxxer.hikari.HikariDataSource; 20 | import io.r2dbc.spi.ConnectionFactories; 21 | import org.junit.jupiter.api.extension.AfterAllCallback; 22 | import org.junit.jupiter.api.extension.BeforeAllCallback; 23 | import org.junit.jupiter.api.extension.ExtensionContext; 24 | import org.junit.jupiter.api.extension.RegisterExtension; 25 | import org.springframework.boot.jdbc.DataSourceBuilder; 26 | import org.springframework.jdbc.core.JdbcOperations; 27 | import org.springframework.jdbc.core.JdbcTemplate; 28 | import org.testcontainers.containers.MSSQLServerContainer; 29 | import reactor.util.annotation.Nullable; 30 | 31 | import java.io.IOException; 32 | 33 | import static io.r2dbc.mssql.MssqlConnectionFactoryProvider.MSSQL_DRIVER; 34 | 35 | final class MssqlExample implements Example { 36 | 37 | @RegisterExtension 38 | static final MssqlServerExtension SERVER = new MssqlServerExtension(); 39 | 40 | private final R2dbc r2dbc = new R2dbc(ConnectionFactories.get( 41 | String.format("r2dbc:pool:%s://%s:%s@%s:%d", MSSQL_DRIVER, SERVER.getUsername(), SERVER.getPassword(), SERVER.getHost(), SERVER.getPort()))); 42 | 43 | @Override 44 | public String getIdentifier(int index) { 45 | return String.format("P%d", index); 46 | } 47 | 48 | @Override 49 | public JdbcOperations getJdbcOperations() { 50 | JdbcOperations jdbcOperations = SERVER.getJdbcOperations(); 51 | 52 | if (jdbcOperations == null) { 53 | throw new IllegalStateException("JdbcOperations not yet initialized"); 54 | } 55 | 56 | return jdbcOperations; 57 | } 58 | 59 | @Override 60 | public String getPlaceholder(int index) { 61 | return String.format("@P%d", index); 62 | } 63 | 64 | @Override 65 | public R2dbc getR2dbc() { 66 | return this.r2dbc; 67 | } 68 | 69 | private static final class MssqlServerExtension implements BeforeAllCallback, AfterAllCallback { 70 | 71 | private final MSSQLServerContainer container = new MSSQLServerContainer<>(); 72 | 73 | private HikariDataSource dataSource; 74 | 75 | private JdbcOperations jdbcOperations; 76 | 77 | @Override 78 | public void afterAll(ExtensionContext context) { 79 | this.dataSource.close(); 80 | this.container.stop(); 81 | } 82 | 83 | @Override 84 | public void beforeAll(ExtensionContext context) throws IOException { 85 | this.container.start(); 86 | 87 | this.dataSource = DataSourceBuilder.create() 88 | .type(HikariDataSource.class) 89 | .url(this.container.getJdbcUrl()) 90 | .username(this.container.getUsername()) 91 | .password(this.container.getPassword()) 92 | .build(); 93 | 94 | this.dataSource.setMaximumPoolSize(1); 95 | 96 | this.jdbcOperations = new JdbcTemplate(this.dataSource); 97 | } 98 | 99 | String getHost() { 100 | return this.container.getContainerIpAddress(); 101 | } 102 | 103 | @Nullable 104 | JdbcOperations getJdbcOperations() { 105 | return this.jdbcOperations; 106 | } 107 | 108 | String getPassword() { 109 | return this.container.getPassword(); 110 | } 111 | 112 | int getPort() { 113 | return this.container.getMappedPort(MSSQLServerContainer.MS_SQL_SERVER_PORT); 114 | } 115 | 116 | String getUsername() { 117 | return this.container.getUsername(); 118 | } 119 | 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/Query.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.client.util.Assert; 20 | import io.r2dbc.spi.Result; 21 | import io.r2dbc.spi.Statement; 22 | import org.reactivestreams.Publisher; 23 | import reactor.core.publisher.Flux; 24 | 25 | import java.util.function.Function; 26 | 27 | /** 28 | * A wrapper for a {@link Statement} providing additional convenience APIs for running queries such as {@code SELECT}. 29 | */ 30 | public final class Query implements ResultBearing { 31 | 32 | private final Statement statement; 33 | 34 | Query(Statement statement) { 35 | this.statement = Assert.requireNonNull(statement, "statement must not be null"); 36 | } 37 | 38 | /** 39 | * Save the current binding and create a new one. 40 | * 41 | * @return this {@link Statement} 42 | */ 43 | public Query add() { 44 | this.statement.add(); 45 | return this; 46 | } 47 | 48 | /** 49 | * Bind a value. 50 | * 51 | * @param identifier the identifier to bind to 52 | * @param value the value to bind 53 | * @return this {@link Statement} 54 | * @throws IllegalArgumentException if {@code identifier} or {@code value} is {@code null} 55 | */ 56 | public Query bind(String identifier, Object value) { 57 | Assert.requireNonNull(identifier, "identifier must not be null"); 58 | Assert.requireNonNull(value, "value must not be null"); 59 | 60 | this.statement.bind(identifier, value); 61 | return this; 62 | } 63 | 64 | /** 65 | * Bind a value. 66 | * 67 | * @param index the index to bind to 68 | * @param value the value to bind 69 | * @return this {@link Statement} 70 | * @throws IllegalArgumentException if {@code identifier} or {@code value} is {@code null} 71 | */ 72 | public Query bind(int index, Object value) { 73 | Assert.requireNonNull(value, "value must not be null"); 74 | 75 | this.statement.bind(index, value); 76 | return this; 77 | } 78 | 79 | /** 80 | * Bind a {@code null} value. 81 | * 82 | * @param identifier the identifier to bind to 83 | * @param type the type of null value 84 | * @return this {@link Statement} 85 | * @throws IllegalArgumentException if {@code identifier} or {@code type} is {@code null} 86 | */ 87 | public Query bindNull(String identifier, Class type) { 88 | Assert.requireNonNull(identifier, "identifier must not be null"); 89 | Assert.requireNonNull(type, "type must not be null"); 90 | 91 | this.statement.bindNull(identifier, type); 92 | return this; 93 | } 94 | 95 | /** 96 | * Bind a {@code null} value. 97 | * 98 | * @param index the index to bind to 99 | * @param type the type of null value 100 | * @return this {@link Statement} 101 | * @throws IllegalArgumentException if {@code identifier} or {@code type} is {@code null} 102 | */ 103 | public Query bindNull(int index, Class type) { 104 | Assert.requireNonNull(type, "type must not be null"); 105 | 106 | this.statement.bindNull(index, type); 107 | return this; 108 | } 109 | 110 | public Flux mapResult(Function> mappingFunction) { 111 | Assert.requireNonNull(mappingFunction, "mappingFunction must not be null"); 112 | 113 | return Flux 114 | .from(this.statement.execute()) 115 | .flatMap(mappingFunction); 116 | } 117 | 118 | @Override 119 | public String toString() { 120 | return "Query{" + 121 | "statement=" + this.statement + 122 | '}'; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/PostgresqlExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import com.zaxxer.hikari.HikariDataSource; 20 | import io.r2dbc.spi.ConnectionFactories; 21 | import org.junit.jupiter.api.extension.AfterAllCallback; 22 | import org.junit.jupiter.api.extension.BeforeAllCallback; 23 | import org.junit.jupiter.api.extension.ExtensionContext; 24 | import org.junit.jupiter.api.extension.RegisterExtension; 25 | import org.springframework.boot.jdbc.DataSourceBuilder; 26 | import org.springframework.jdbc.core.JdbcOperations; 27 | import org.springframework.jdbc.core.JdbcTemplate; 28 | import org.testcontainers.containers.PostgreSQLContainer; 29 | import reactor.util.annotation.Nullable; 30 | 31 | import java.io.IOException; 32 | 33 | import static io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider.POSTGRESQL_DRIVER; 34 | 35 | final class PostgresqlExample implements Example { 36 | 37 | @RegisterExtension 38 | static final PostgresqlServerExtension SERVER = new PostgresqlServerExtension(); 39 | 40 | private final R2dbc r2dbc = new R2dbc(ConnectionFactories.get( 41 | String.format("r2dbc:pool:%s://%s:%s@%s:%d/%s", POSTGRESQL_DRIVER, SERVER.getUsername(), SERVER.getPassword(), SERVER.getHost(), SERVER.getPort(), SERVER.getDatabase()))); 42 | 43 | @Override 44 | public String getIdentifier(int index) { 45 | return getPlaceholder(index); 46 | } 47 | 48 | @Override 49 | public JdbcOperations getJdbcOperations() { 50 | JdbcOperations jdbcOperations = SERVER.getJdbcOperations(); 51 | 52 | if (jdbcOperations == null) { 53 | throw new IllegalStateException("JdbcOperations not yet initialized"); 54 | } 55 | 56 | return jdbcOperations; 57 | } 58 | 59 | @Override 60 | public String getPlaceholder(int index) { 61 | return String.format("$%d", index + 1); 62 | } 63 | 64 | @Override 65 | public R2dbc getR2dbc() { 66 | return this.r2dbc; 67 | } 68 | 69 | private static final class PostgresqlServerExtension implements BeforeAllCallback, AfterAllCallback { 70 | 71 | private final PostgreSQLContainer container = new PostgreSQLContainer<>("postgres:latest"); 72 | 73 | private HikariDataSource dataSource; 74 | 75 | private JdbcOperations jdbcOperations; 76 | 77 | @Override 78 | public void afterAll(ExtensionContext context) { 79 | this.dataSource.close(); 80 | this.container.stop(); 81 | } 82 | 83 | @Override 84 | public void beforeAll(ExtensionContext context) throws IOException { 85 | this.container.start(); 86 | 87 | this.dataSource = DataSourceBuilder.create() 88 | .type(HikariDataSource.class) 89 | .url(this.container.getJdbcUrl()) 90 | .username(this.container.getUsername()) 91 | .password(this.container.getPassword()) 92 | .build(); 93 | 94 | this.dataSource.setMaximumPoolSize(1); 95 | 96 | this.jdbcOperations = new JdbcTemplate(this.dataSource); 97 | } 98 | 99 | String getDatabase() { 100 | return this.container.getDatabaseName(); 101 | } 102 | 103 | String getHost() { 104 | return this.container.getContainerIpAddress(); 105 | } 106 | 107 | @Nullable 108 | JdbcOperations getJdbcOperations() { 109 | return this.jdbcOperations; 110 | } 111 | 112 | String getPassword() { 113 | return this.container.getPassword(); 114 | } 115 | 116 | int getPort() { 117 | return this.container.getMappedPort(5432); 118 | } 119 | 120 | String getUsername() { 121 | return this.container.getUsername(); 122 | } 123 | 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/QueryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.spi.test.MockResult; 20 | import io.r2dbc.spi.test.MockStatement; 21 | import org.junit.jupiter.api.Test; 22 | import reactor.core.publisher.Mono; 23 | import reactor.test.StepVerifier; 24 | 25 | import java.util.Collections; 26 | 27 | import static org.assertj.core.api.Assertions.assertThat; 28 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 29 | 30 | final class QueryTest { 31 | 32 | @Test 33 | void add() { 34 | MockStatement statement = MockStatement.empty(); 35 | 36 | new Query(statement) 37 | .add(); 38 | 39 | assertThat(statement.isAddCalled()).isTrue(); 40 | } 41 | 42 | @Test 43 | void bind() { 44 | MockStatement statement = MockStatement.empty(); 45 | 46 | new Query(statement) 47 | .bind("test-identifier", "test-value"); 48 | 49 | assertThat(statement.getBindings()).contains(Collections.singletonMap("test-identifier", "test-value")); 50 | } 51 | 52 | @Test 53 | void bindIndex() { 54 | MockStatement statement = MockStatement.empty(); 55 | 56 | new Query(statement) 57 | .bind(100, "test-value"); 58 | 59 | assertThat(statement.getBindings()).contains(Collections.singletonMap(100, "test-value")); 60 | } 61 | 62 | @Test 63 | void bindIndexNoValue() { 64 | assertThatIllegalArgumentException().isThrownBy(() -> new Query(MockStatement.empty()).bind(100, null)) 65 | .withMessage("value must not be null"); 66 | } 67 | 68 | @Test 69 | void bindNoIdentifier() { 70 | assertThatIllegalArgumentException().isThrownBy(() -> new Query(MockStatement.empty()).bind(null, new Object())) 71 | .withMessage("identifier must not be null"); 72 | } 73 | 74 | @Test 75 | void bindNoValue() { 76 | assertThatIllegalArgumentException().isThrownBy(() -> new Query(MockStatement.empty()).bind("test-identifier", null)) 77 | .withMessage("value must not be null"); 78 | } 79 | 80 | @Test 81 | void bindNull() { 82 | MockStatement statement = MockStatement.empty(); 83 | 84 | new Query(statement) 85 | .bindNull("test-identifier", Integer.class); 86 | 87 | assertThat(statement.getBindings()).contains(Collections.singletonMap("test-identifier", Integer.class)); 88 | } 89 | 90 | @Test 91 | void bindNullNoIdentifier() { 92 | assertThatIllegalArgumentException().isThrownBy(() -> new Query(MockStatement.empty()).bindNull(null, Object.class)) 93 | .withMessage("identifier must not be null"); 94 | } 95 | 96 | @Test 97 | void bindNullNoType() { 98 | assertThatIllegalArgumentException().isThrownBy(() -> new Query(MockStatement.empty()).bindNull("test-identifier", null)) 99 | .withMessage("type must not be null"); 100 | } 101 | 102 | @Test 103 | void constructorNoStatement() { 104 | assertThatIllegalArgumentException().isThrownBy(() -> new Query(null)) 105 | .withMessage("statement must not be null"); 106 | } 107 | 108 | @Test 109 | void mapResult() { 110 | MockResult result = MockResult.empty(); 111 | 112 | MockStatement statement = MockStatement.builder() 113 | .result(result) 114 | .build(); 115 | 116 | new Query(statement) 117 | .mapResult(actual -> { 118 | assertThat(actual).isSameAs(result); 119 | return Mono.just(1); 120 | }) 121 | .as(StepVerifier::create) 122 | .expectNext(1) 123 | .verifyComplete(); 124 | } 125 | 126 | @Test 127 | void mapResultNoF() { 128 | assertThatIllegalArgumentException().isThrownBy(() -> new Query(MockStatement.empty()).mapResult(null)) 129 | .withMessage("mappingFunction must not be null"); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/MysqlExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import com.zaxxer.hikari.HikariDataSource; 20 | import io.r2dbc.spi.ConnectionFactories; 21 | import org.junit.Ignore; 22 | import org.junit.jupiter.api.Test; 23 | import org.junit.jupiter.api.extension.AfterAllCallback; 24 | import org.junit.jupiter.api.extension.BeforeAllCallback; 25 | import org.junit.jupiter.api.extension.ExtensionContext; 26 | import org.junit.jupiter.api.extension.RegisterExtension; 27 | import org.springframework.boot.jdbc.DataSourceBuilder; 28 | import org.springframework.jdbc.core.JdbcOperations; 29 | import org.springframework.jdbc.core.JdbcTemplate; 30 | import org.testcontainers.containers.MySQLContainer; 31 | import reactor.util.annotation.Nullable; 32 | 33 | import static dev.miku.r2dbc.mysql.MySqlConnectionFactoryProvider.MYSQL_DRIVER; 34 | import static io.r2dbc.spi.ConnectionFactoryOptions.DATABASE; 35 | import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER; 36 | import static io.r2dbc.spi.ConnectionFactoryOptions.HOST; 37 | import static io.r2dbc.spi.ConnectionFactoryOptions.PASSWORD; 38 | import static io.r2dbc.spi.ConnectionFactoryOptions.PORT; 39 | import static io.r2dbc.spi.ConnectionFactoryOptions.USER; 40 | import static io.r2dbc.spi.ConnectionFactoryOptions.builder; 41 | 42 | final class MysqlExample implements Example { 43 | 44 | @RegisterExtension 45 | static final MysqlServerExtension SERVER = new MysqlServerExtension(); 46 | 47 | private final R2dbc r2dbc = new R2dbc(ConnectionFactories.get(builder() 48 | .option(DRIVER, MYSQL_DRIVER) 49 | .option(HOST, SERVER.getHost()) 50 | .option(PORT, SERVER.getPort()) 51 | .option(PASSWORD, SERVER.getPassword()) 52 | .option(USER, SERVER.getUsername()) 53 | .option(DATABASE, SERVER.getDatabase()) 54 | .build())); 55 | 56 | @Test 57 | @Ignore("compound statements are not supported by the driver") 58 | @Override 59 | public void compoundStatement() { 60 | } 61 | 62 | @Override 63 | public Integer getIdentifier(int index) { 64 | return index; 65 | } 66 | 67 | @Override 68 | public JdbcOperations getJdbcOperations() { 69 | JdbcOperations jdbcOperations = SERVER.getJdbcOperations(); 70 | 71 | if (jdbcOperations == null) { 72 | throw new IllegalStateException("JdbcOperations not yet initialized"); 73 | } 74 | 75 | return jdbcOperations; 76 | } 77 | 78 | @Override 79 | public String getPlaceholder(int index) { 80 | return "?"; 81 | } 82 | 83 | @Override 84 | public R2dbc getR2dbc() { 85 | return this.r2dbc; 86 | } 87 | 88 | private static final class MysqlServerExtension implements BeforeAllCallback, AfterAllCallback { 89 | 90 | private final MySQLContainer container = new MySQLContainer<>("mysql:5.7"); 91 | 92 | private HikariDataSource dataSource; 93 | 94 | private JdbcOperations jdbcOperations; 95 | 96 | @Override 97 | public void afterAll(ExtensionContext context) { 98 | this.dataSource.close(); 99 | this.container.stop(); 100 | } 101 | 102 | @Override 103 | public void beforeAll(ExtensionContext context) { 104 | this.container.start(); 105 | 106 | this.dataSource = DataSourceBuilder.create() 107 | .type(HikariDataSource.class) 108 | .url(this.container.getJdbcUrl()) 109 | .username(this.container.getUsername()) 110 | .password(this.container.getPassword()) 111 | .build(); 112 | 113 | this.dataSource.setMaximumPoolSize(1); 114 | 115 | this.jdbcOperations = new JdbcTemplate(this.dataSource); 116 | } 117 | 118 | String getDatabase() { 119 | return this.container.getDatabaseName(); 120 | } 121 | 122 | String getHost() { 123 | return this.container.getContainerIpAddress(); 124 | } 125 | 126 | @Nullable 127 | JdbcOperations getJdbcOperations() { 128 | return this.jdbcOperations; 129 | } 130 | 131 | String getPassword() { 132 | return this.container.getPassword(); 133 | } 134 | 135 | int getPort() { 136 | return this.container.getFirstMappedPort(); 137 | } 138 | 139 | String getUsername() { 140 | return this.container.getUsername(); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.5"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/H2Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import com.zaxxer.hikari.HikariDataSource; 20 | import io.r2dbc.spi.ConnectionFactories; 21 | import io.r2dbc.spi.ConnectionFactoryOptions; 22 | import org.junit.jupiter.api.Nested; 23 | import org.junit.jupiter.api.extension.AfterAllCallback; 24 | import org.junit.jupiter.api.extension.BeforeAllCallback; 25 | import org.junit.jupiter.api.extension.ExtensionContext; 26 | import org.junit.jupiter.api.extension.RegisterExtension; 27 | import org.springframework.boot.jdbc.DataSourceBuilder; 28 | import org.springframework.jdbc.core.JdbcOperations; 29 | import org.springframework.jdbc.core.JdbcTemplate; 30 | import reactor.util.annotation.Nullable; 31 | 32 | import java.util.UUID; 33 | 34 | import static io.r2dbc.h2.H2ConnectionFactoryProvider.H2_DRIVER; 35 | import static io.r2dbc.h2.H2ConnectionFactoryProvider.URL; 36 | import static io.r2dbc.spi.ConnectionFactoryOptions.DRIVER; 37 | import static io.r2dbc.spi.ConnectionFactoryOptions.PASSWORD; 38 | import static io.r2dbc.spi.ConnectionFactoryOptions.USER; 39 | 40 | final class H2Example { 41 | 42 | @RegisterExtension 43 | static final H2ServerExtension SERVER = new H2ServerExtension(); 44 | 45 | // TODO: Convert to use URI format with pool. 46 | private final R2dbc r2dbc = new R2dbc(ConnectionFactories.get(ConnectionFactoryOptions.builder() 47 | .option(DRIVER, H2_DRIVER) 48 | .option(PASSWORD, SERVER.getPassword()) 49 | .option(URL, SERVER.getUrl()) 50 | .option(USER, SERVER.getUsername()) 51 | .build())); 52 | 53 | private static final class H2ServerExtension implements BeforeAllCallback, AfterAllCallback { 54 | 55 | private final String password = UUID.randomUUID().toString(); 56 | 57 | private final String url = String.format("mem:%s", UUID.randomUUID().toString()); 58 | 59 | private final String username = UUID.randomUUID().toString(); 60 | 61 | private HikariDataSource dataSource; 62 | 63 | private JdbcOperations jdbcOperations; 64 | 65 | @Override 66 | public void afterAll(ExtensionContext context) { 67 | this.dataSource.close(); 68 | } 69 | 70 | @Override 71 | public void beforeAll(ExtensionContext context) { 72 | this.dataSource = DataSourceBuilder.create() 73 | .type(HikariDataSource.class) 74 | .url(String.format("jdbc:h2:%s;USER=%s;PASSWORD=%s;DB_CLOSE_DELAY=-1;TRACE_LEVEL_FILE=4", this.url, this.username, this.password)) 75 | .build(); 76 | 77 | this.dataSource.setMaximumPoolSize(1); 78 | 79 | this.jdbcOperations = new JdbcTemplate(this.dataSource); 80 | } 81 | 82 | @Nullable 83 | JdbcOperations getJdbcOperations() { 84 | return this.jdbcOperations; 85 | } 86 | 87 | String getPassword() { 88 | return this.password; 89 | } 90 | 91 | String getUrl() { 92 | return this.url; 93 | } 94 | 95 | String getUsername() { 96 | return this.username; 97 | } 98 | 99 | } 100 | 101 | @Nested 102 | final class JdbcStyle implements Example { 103 | 104 | @Override 105 | public Integer getIdentifier(int index) { 106 | return index; 107 | } 108 | 109 | @Override 110 | public JdbcOperations getJdbcOperations() { 111 | JdbcOperations jdbcOperations = SERVER.getJdbcOperations(); 112 | 113 | if (jdbcOperations == null) { 114 | throw new IllegalStateException("JdbcOperations not yet initialized"); 115 | } 116 | 117 | return jdbcOperations; 118 | } 119 | 120 | @Override 121 | public String getPlaceholder(int index) { 122 | return "?"; 123 | } 124 | 125 | @Override 126 | public R2dbc getR2dbc() { 127 | return r2dbc; 128 | } 129 | } 130 | 131 | @Nested 132 | final class PostgresqlStyle implements Example { 133 | 134 | @Override 135 | public String getIdentifier(int index) { 136 | return getPlaceholder(index); 137 | } 138 | 139 | @Override 140 | public JdbcOperations getJdbcOperations() { 141 | JdbcOperations jdbcOperations = SERVER.getJdbcOperations(); 142 | 143 | if (jdbcOperations == null) { 144 | throw new IllegalStateException("JdbcOperations not yet initialized"); 145 | } 146 | 147 | return jdbcOperations; 148 | } 149 | 150 | @Override 151 | public String getPlaceholder(int index) { 152 | return String.format("$%d", index + 1); 153 | } 154 | 155 | @Override 156 | public R2dbc getR2dbc() { 157 | return r2dbc; 158 | } 159 | 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/R2dbc.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.client.util.Assert; 20 | import io.r2dbc.client.util.ReactiveUtils; 21 | import io.r2dbc.spi.Connection; 22 | import io.r2dbc.spi.ConnectionFactory; 23 | import org.reactivestreams.Publisher; 24 | import reactor.core.publisher.Flux; 25 | import reactor.core.publisher.Mono; 26 | 27 | import java.util.function.Function; 28 | 29 | /** 30 | * An implementation of a Reactive Relational Database Connection Client. 31 | */ 32 | public final class R2dbc { 33 | 34 | private final ConnectionFactory connectionFactory; 35 | 36 | /** 37 | * Create a new instance of {@link R2dbc}. 38 | * 39 | * @param connectionFactory a {@link ConnectionFactory} used to create {@link Connection}s when required 40 | * @throws IllegalArgumentException if {@code connectionFactory} is {@code null} 41 | */ 42 | public R2dbc(ConnectionFactory connectionFactory) { 43 | this.connectionFactory = Assert.requireNonNull(connectionFactory, "connectionFactory must not be null"); 44 | } 45 | 46 | /** 47 | * Execute behavior within a transaction returning results. The transaction is committed if the behavior completes successfully, and rolled back it produces an error. 48 | * 49 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results 50 | * @param the type of results 51 | * @return a {@link Flux} of results 52 | * @throws IllegalArgumentException if {@code resourceFunction} is {@code null} 53 | * @see Connection#commitTransaction() 54 | * @see Connection#rollbackTransaction() 55 | */ 56 | public Flux inTransaction(Function> resourceFunction) { 57 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 58 | 59 | return withHandle(handle -> handle.inTransaction(resourceFunction)); 60 | } 61 | 62 | /** 63 | * Open a {@link Handle} and return it for use. Note that you the caller is responsible for closing the handle otherwise connections will be leaked. 64 | * 65 | * @return a new {@link Handle}, ready to use 66 | * @see Handle#close() 67 | */ 68 | public Mono open() { 69 | return Mono.from( 70 | this.connectionFactory.create()) 71 | .map(Handle::new); 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return "R2dbc{" + 77 | "connectionFactory=" + this.connectionFactory + 78 | '}'; 79 | } 80 | 81 | /** 82 | * Execute behavior with a {@link Handle} not returning results. 83 | * 84 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results. These results are discarded. 85 | * @return a {@link Mono} that execution is complete 86 | * @throws IllegalArgumentException if {@code resourceFunction} is {@code null} 87 | */ 88 | public Mono useHandle(Function> resourceFunction) { 89 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 90 | 91 | return withHandle(resourceFunction) 92 | .then(); 93 | } 94 | 95 | /** 96 | * Execute behavior within a transaction not returning results. The transaction is committed if the behavior completes successfully, and rolled back it produces an error. 97 | * 98 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results. These results are discarded. 99 | * @return a {@link Mono} that execution is complete 100 | * @throws IllegalArgumentException if {@code resourceFunction} is {@code null} 101 | * @see Connection#commitTransaction() 102 | * @see Connection#rollbackTransaction() 103 | */ 104 | public Mono useTransaction(Function> resourceFunction) { 105 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 106 | 107 | return useHandle(handle -> handle.useTransaction(resourceFunction)); 108 | } 109 | 110 | /** 111 | * Execute behavior with a {@link Handle} returning results. 112 | * 113 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results 114 | * @param the type of results 115 | * @return a {@link Flux} of results 116 | * @throws IllegalArgumentException if {@code resourceFunction} is {@code null} 117 | */ 118 | public Flux withHandle(Function> resourceFunction) { 119 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 120 | 121 | return open() 122 | .flatMapMany(handle -> Flux.from( 123 | resourceFunction.apply(handle)) 124 | .concatWith(ReactiveUtils.typeSafe(handle::close)) 125 | .onErrorResume(ReactiveUtils.appendError(handle::close))); 126 | } 127 | 128 | } 129 | -------------------------------------------------------------------------------- /ci/docker-lib.sh: -------------------------------------------------------------------------------- 1 | LOG_FILE=${LOG_FILE:-/tmp/docker.log} 2 | SKIP_PRIVILEGED=${SKIP_PRIVILEGED:-false} 3 | STARTUP_TIMEOUT=${STARTUP_TIMEOUT:-120} 4 | 5 | sanitize_cgroups() { 6 | mkdir -p /sys/fs/cgroup 7 | mountpoint -q /sys/fs/cgroup || \ 8 | mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup 9 | 10 | mount -o remount,rw /sys/fs/cgroup 11 | 12 | sed -e 1d /proc/cgroups | while read sys hierarchy num enabled; do 13 | if [ "$enabled" != "1" ]; then 14 | # subsystem disabled; skip 15 | continue 16 | fi 17 | 18 | grouping="$(cat /proc/self/cgroup | cut -d: -f2 | grep "\\<$sys\\>")" || true 19 | if [ -z "$grouping" ]; then 20 | # subsystem not mounted anywhere; mount it on its own 21 | grouping="$sys" 22 | fi 23 | 24 | mountpoint="/sys/fs/cgroup/$grouping" 25 | 26 | mkdir -p "$mountpoint" 27 | 28 | # clear out existing mount to make sure new one is read-write 29 | if mountpoint -q "$mountpoint"; then 30 | umount "$mountpoint" 31 | fi 32 | 33 | mount -n -t cgroup -o "$grouping" cgroup "$mountpoint" 34 | 35 | if [ "$grouping" != "$sys" ]; then 36 | if [ -L "/sys/fs/cgroup/$sys" ]; then 37 | rm "/sys/fs/cgroup/$sys" 38 | fi 39 | 40 | ln -s "$mountpoint" "/sys/fs/cgroup/$sys" 41 | fi 42 | done 43 | 44 | if ! test -e /sys/fs/cgroup/systemd ; then 45 | mkdir /sys/fs/cgroup/systemd 46 | mount -t cgroup -o none,name=systemd none /sys/fs/cgroup/systemd 47 | fi 48 | } 49 | 50 | start_docker() { 51 | mkdir -p /var/log 52 | mkdir -p /var/run 53 | 54 | if [ "$SKIP_PRIVILEGED" = "false" ]; then 55 | sanitize_cgroups 56 | 57 | # check for /proc/sys being mounted readonly, as systemd does 58 | if grep '/proc/sys\s\+\w\+\s\+ro,' /proc/mounts >/dev/null; then 59 | mount -o remount,rw /proc/sys 60 | fi 61 | fi 62 | 63 | local mtu=$(cat /sys/class/net/$(ip route get 8.8.8.8|awk '{ print $5 }')/mtu) 64 | local server_args="--mtu ${mtu}" 65 | local registry="" 66 | 67 | server_args="${server_args} --max-concurrent-downloads=$1 --max-concurrent-uploads=$2" 68 | 69 | for registry in $3; do 70 | server_args="${server_args} --insecure-registry ${registry}" 71 | done 72 | 73 | if [ -n "$4" ]; then 74 | server_args="${server_args} --registry-mirror $4" 75 | fi 76 | 77 | try_start() { 78 | dockerd --data-root /scratch/docker ${server_args} >$LOG_FILE 2>&1 & 79 | echo $! > /tmp/docker.pid 80 | 81 | sleep 1 82 | 83 | echo waiting for docker to come up... 84 | until docker info >/dev/null 2>&1; do 85 | sleep 1 86 | if ! kill -0 "$(cat /tmp/docker.pid)" 2>/dev/null; then 87 | return 1 88 | fi 89 | done 90 | } 91 | 92 | export server_args LOG_FILE 93 | declare -fx try_start 94 | trap stop_docker EXIT 95 | 96 | if ! timeout ${STARTUP_TIMEOUT} bash -ce 'while true; do try_start && break; done'; then 97 | echo Docker failed to start within ${STARTUP_TIMEOUT} seconds. 98 | return 1 99 | fi 100 | } 101 | 102 | stop_docker() { 103 | local pid=$(cat /tmp/docker.pid) 104 | if [ -z "$pid" ]; then 105 | return 0 106 | fi 107 | 108 | kill -TERM $pid 109 | } 110 | 111 | log_in() { 112 | local username="$1" 113 | local password="$2" 114 | local registry="$3" 115 | 116 | if [ -n "${username}" ] && [ -n "${password}" ]; then 117 | echo "${password}" | docker login -u "${username}" --password-stdin ${registry} 118 | else 119 | mkdir -p ~/.docker 120 | echo '{"credsStore":"ecr-login"}' >> ~/.docker/config.json 121 | fi 122 | } 123 | 124 | private_registry() { 125 | local repository="${1}" 126 | 127 | if echo "${repository}" | fgrep -q '/' ; then 128 | local registry="$(extract_registry "${repository}")" 129 | if echo "${registry}" | fgrep -q '.' ; then 130 | return 0 131 | fi 132 | fi 133 | 134 | return 1 135 | } 136 | 137 | extract_registry() { 138 | local repository="${1}" 139 | 140 | echo "${repository}" | cut -d/ -f1 141 | } 142 | 143 | extract_repository() { 144 | local long_repository="${1}" 145 | 146 | echo "${long_repository}" | cut -d/ -f2- 147 | } 148 | 149 | image_from_tag() { 150 | docker images --no-trunc "$1" | awk "{if (\$2 == \"$2\") print \$3}" 151 | } 152 | 153 | image_from_digest() { 154 | docker images --no-trunc --digests "$1" | awk "{if (\$3 == \"$2\") print \$4}" 155 | } 156 | 157 | certs_to_file() { 158 | local raw_ca_certs="${1}" 159 | local cert_count="$(echo $raw_ca_certs | jq -r '. | length')" 160 | 161 | for i in $(seq 0 $(expr "$cert_count" - 1)); 162 | do 163 | local cert_dir="/etc/docker/certs.d/$(echo $raw_ca_certs | jq -r .[$i].domain)" 164 | mkdir -p "$cert_dir" 165 | echo $raw_ca_certs | jq -r .[$i].cert >> "${cert_dir}/ca.crt" 166 | done 167 | } 168 | 169 | set_client_certs() { 170 | local raw_client_certs="${1}" 171 | local cert_count="$(echo $raw_client_certs | jq -r '. | length')" 172 | 173 | for i in $(seq 0 $(expr "$cert_count" - 1)); 174 | do 175 | local cert_dir="/etc/docker/certs.d/$(echo $raw_client_certs | jq -r .[$i].domain)" 176 | [ -d "$cert_dir" ] || mkdir -p "$cert_dir" 177 | echo $raw_client_certs | jq -r .[$i].cert >> "${cert_dir}/client.cert" 178 | echo $raw_client_certs | jq -r .[$i].key >> "${cert_dir}/client.key" 179 | done 180 | } 181 | 182 | docker_pull() { 183 | GREEN='\033[0;32m' 184 | RED='\033[0;31m' 185 | NC='\033[0m' # No Color 186 | 187 | pull_attempt=1 188 | max_attempts=3 189 | while [ "$pull_attempt" -le "$max_attempts" ]; do 190 | printf "Pulling ${GREEN}%s${NC}" "$1" 191 | 192 | if [ "$pull_attempt" != "1" ]; then 193 | printf " (attempt %s of %s)" "$pull_attempt" "$max_attempts" 194 | fi 195 | 196 | printf "...\n" 197 | 198 | if docker pull "$1"; then 199 | printf "\nSuccessfully pulled ${GREEN}%s${NC}.\n\n" "$1" 200 | return 201 | fi 202 | 203 | echo 204 | 205 | pull_attempt=$(expr "$pull_attempt" + 1) 206 | done 207 | 208 | printf "\n${RED}Failed to pull image %s.${NC}" "$1" 209 | exit 1 210 | } 211 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/R2dbcTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.spi.test.MockConnection; 20 | import io.r2dbc.spi.test.MockConnectionFactory; 21 | import org.junit.jupiter.api.Test; 22 | import reactor.core.publisher.Mono; 23 | import reactor.test.StepVerifier; 24 | 25 | import static org.assertj.core.api.Assertions.assertThat; 26 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 27 | 28 | final class R2dbcTest { 29 | 30 | @Test 31 | void constructorNoConnectionFactory() { 32 | assertThatIllegalArgumentException().isThrownBy(() -> new R2dbc(null)) 33 | .withMessage("connectionFactory must not be null"); 34 | } 35 | 36 | @Test 37 | void inTransaction() { 38 | MockConnection connection = MockConnection.empty(); 39 | 40 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 41 | .connection(connection) 42 | .build(); 43 | 44 | new R2dbc(connectionFactory) 45 | .inTransaction(handle -> 46 | Mono.just(100)) 47 | .as(StepVerifier::create) 48 | .expectNext(100) 49 | .verifyComplete(); 50 | 51 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 52 | assertThat(connection.isCommitTransactionCalled()).isTrue(); 53 | assertThat(connection.isCloseCalled()).isTrue(); 54 | } 55 | 56 | @Test 57 | void inTransactionError() { 58 | MockConnection connection = MockConnection.empty(); 59 | 60 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 61 | .connection(connection) 62 | .build(); 63 | 64 | Exception exception = new Exception(); 65 | 66 | new R2dbc(connectionFactory) 67 | .inTransaction(handle -> 68 | Mono.error(exception)) 69 | .as(StepVerifier::create) 70 | .verifyErrorMatches(exception::equals); 71 | 72 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 73 | assertThat(connection.isRollbackTransactionCalled()).isTrue(); 74 | assertThat(connection.isCloseCalled()).isTrue(); 75 | } 76 | 77 | @Test 78 | void inTransactionNoF() { 79 | assertThatIllegalArgumentException().isThrownBy(() -> new R2dbc(MockConnectionFactory.empty()).inTransaction(null)) 80 | .withMessage("resourceFunction must not be null"); 81 | } 82 | 83 | @Test 84 | void open() { 85 | MockConnection connection = MockConnection.empty(); 86 | 87 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 88 | .connection(connection) 89 | .build(); 90 | 91 | new R2dbc(connectionFactory) 92 | .open() 93 | .as(StepVerifier::create) 94 | .expectNextCount(1) 95 | .verifyComplete(); 96 | } 97 | 98 | @Test 99 | void useHandle() { 100 | MockConnection connection = MockConnection.empty(); 101 | 102 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 103 | .connection(connection) 104 | .build(); 105 | 106 | new R2dbc(connectionFactory) 107 | .useHandle(handle -> 108 | Mono.just(100)) 109 | .as(StepVerifier::create) 110 | .verifyComplete(); 111 | 112 | assertThat(connection.isCloseCalled()).isTrue(); 113 | } 114 | 115 | @Test 116 | void useHandleError() { 117 | MockConnection connection = MockConnection.empty(); 118 | 119 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 120 | .connection(connection) 121 | .build(); 122 | 123 | Exception exception = new Exception(); 124 | 125 | new R2dbc(connectionFactory) 126 | .useHandle(handle -> 127 | Mono.error(exception)) 128 | .as(StepVerifier::create) 129 | .verifyErrorMatches(exception::equals); 130 | 131 | assertThat(connection.isCloseCalled()).isTrue(); 132 | } 133 | 134 | @Test 135 | void useHandleNoF() { 136 | assertThatIllegalArgumentException().isThrownBy(() -> new R2dbc(MockConnectionFactory.empty()).useHandle(null)) 137 | .withMessage("resourceFunction must not be null"); 138 | } 139 | 140 | @Test 141 | void useTransaction() { 142 | MockConnection connection = MockConnection.empty(); 143 | 144 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 145 | .connection(connection) 146 | .build(); 147 | 148 | new R2dbc(connectionFactory) 149 | .useTransaction(handle -> 150 | Mono.just(100)) 151 | .as(StepVerifier::create) 152 | .verifyComplete(); 153 | 154 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 155 | assertThat(connection.isCommitTransactionCalled()).isTrue(); 156 | assertThat(connection.isCloseCalled()).isTrue(); 157 | } 158 | 159 | @Test 160 | void useTransactionError() { 161 | MockConnection connection = MockConnection.empty(); 162 | 163 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 164 | .connection(connection) 165 | .build(); 166 | 167 | Exception exception = new Exception(); 168 | 169 | new R2dbc(connectionFactory) 170 | .useTransaction(handle -> 171 | Mono.error(exception)) 172 | .as(StepVerifier::create) 173 | .verifyErrorMatches(exception::equals); 174 | 175 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 176 | assertThat(connection.isRollbackTransactionCalled()).isTrue(); 177 | assertThat(connection.isCloseCalled()).isTrue(); 178 | } 179 | 180 | @Test 181 | void useTransactionNoF() { 182 | assertThatIllegalArgumentException().isThrownBy(() -> new R2dbc(MockConnectionFactory.empty()).useTransaction(null)) 183 | .withMessage("resourceFunction must not be null"); 184 | } 185 | 186 | @Test 187 | void withHandle() { 188 | MockConnection connection = MockConnection.empty(); 189 | 190 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 191 | .connection(connection) 192 | .build(); 193 | 194 | new R2dbc(connectionFactory) 195 | .withHandle(handle -> 196 | Mono.just(100)) 197 | .as(StepVerifier::create) 198 | .expectNext(100) 199 | .verifyComplete(); 200 | 201 | assertThat(connection.isCloseCalled()).isTrue(); 202 | } 203 | 204 | @Test 205 | void withHandleError() { 206 | MockConnection connection = MockConnection.empty(); 207 | 208 | MockConnectionFactory connectionFactory = MockConnectionFactory.builder() 209 | .connection(connection) 210 | .build(); 211 | 212 | Exception exception = new Exception(); 213 | 214 | new R2dbc(connectionFactory) 215 | .withHandle(handle -> 216 | Mono.error(exception)) 217 | .as(StepVerifier::create) 218 | .verifyErrorMatches(exception::equals); 219 | 220 | assertThat(connection.isCloseCalled()).isTrue(); 221 | } 222 | 223 | @Test 224 | void withHandleNoF() { 225 | assertThatIllegalArgumentException().isThrownBy(() -> new R2dbc(MockConnectionFactory.empty()).withHandle(null)) 226 | .withMessage("resourceFunction must not be null"); 227 | } 228 | 229 | } 230 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/Example.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.mssql.util.Assert; 20 | import io.r2dbc.spi.Result; 21 | import org.junit.jupiter.api.AfterEach; 22 | import org.junit.jupiter.api.BeforeEach; 23 | import org.junit.jupiter.api.Test; 24 | import org.springframework.jdbc.core.JdbcOperations; 25 | import reactor.core.publisher.Flux; 26 | import reactor.core.publisher.Mono; 27 | import reactor.test.StepVerifier; 28 | 29 | import java.util.Arrays; 30 | import java.util.Collections; 31 | import java.util.List; 32 | import java.util.stream.IntStream; 33 | 34 | interface Example { 35 | 36 | static Mono> extractColumns(Result result) { 37 | return Flux.from(result 38 | .map((row, rowMetadata) -> row.get("value", Integer.class))) 39 | .collectList(); 40 | } 41 | 42 | static Mono> extractIds(Result result) { 43 | return Flux.from(result 44 | .map((row, rowMetadata) -> row.get("id", Integer.class))) 45 | .collectList(); 46 | } 47 | 48 | @Test 49 | default void batch() { 50 | getJdbcOperations().execute("INSERT INTO test VALUES (100)"); 51 | 52 | getR2dbc() 53 | .withHandle(handle -> handle 54 | 55 | .createBatch() 56 | .add("INSERT INTO test VALUES(200)") 57 | .add("SELECT value FROM test") 58 | .mapResult(Mono::just)) 59 | 60 | .as(StepVerifier::create) 61 | .expectNextCount(2).as("one result for each statement") 62 | .verifyComplete(); 63 | } 64 | 65 | @Test 66 | default void compoundStatement() { 67 | getJdbcOperations().execute("INSERT INTO test VALUES (100)"); 68 | 69 | getR2dbc() 70 | .withHandle(handle -> handle 71 | 72 | .createQuery("SELECT value FROM test; SELECT value FROM test") 73 | .mapResult(Example::extractColumns)) 74 | 75 | .as(StepVerifier::create) 76 | .expectNext(Collections.singletonList(100)).as("value from first statement") 77 | .expectNext(Collections.singletonList(100)).as("value from second statement") 78 | .verifyComplete(); 79 | } 80 | 81 | @BeforeEach 82 | default void createTable() { 83 | getJdbcOperations().execute("CREATE TABLE test ( value INTEGER )"); 84 | } 85 | 86 | @AfterEach 87 | default void dropTable() { 88 | getJdbcOperations().execute("DROP TABLE test"); 89 | } 90 | 91 | /** 92 | * Returns the bind identifier for a given substitution. 93 | * 94 | * @param index the zero-index number of the substitution 95 | * @return the bind identifier for a given substitution 96 | */ 97 | T getIdentifier(int index); 98 | 99 | /** 100 | * Returns a {@link JdbcOperations} for the connected database. 101 | * 102 | * @return a {@link JdbcOperations} for the connected database 103 | */ 104 | JdbcOperations getJdbcOperations(); 105 | 106 | /** 107 | * Returns the database-specific placeholder for a given substitution. 108 | * 109 | * @param index the zero-index number of the substitution 110 | * @return the database-specific placeholder for a given substitution 111 | */ 112 | String getPlaceholder(int index); 113 | 114 | /** 115 | * Returns a {@link R2dbc} for the connected database. 116 | * 117 | * @return a {@link R2dbc} for the connected database 118 | */ 119 | R2dbc getR2dbc(); 120 | 121 | static Update bind(Update update, Object identifier, Object value) { 122 | 123 | if (identifier instanceof Integer) { 124 | return update.bind((Integer) identifier, value); 125 | } 126 | 127 | Assert.isTrue(identifier instanceof String, String.format("Identifier %s must be a String or an Integer.", identifier)); 128 | 129 | return update.bind((String) identifier, value); 130 | } 131 | 132 | @Test 133 | default void prepareStatement() { 134 | getR2dbc() 135 | .withHandle(handle -> { 136 | Update update = handle.createUpdate(String.format("INSERT INTO test VALUES(%s)", getPlaceholder(0))); 137 | 138 | IntStream.range(0, 10) 139 | .forEach(i -> bind(update, getIdentifier(0), i).add()); 140 | 141 | return update.execute(); 142 | }) 143 | .as(StepVerifier::create) 144 | .expectNextCount(10).as("values from insertions") 145 | .verifyComplete(); 146 | } 147 | 148 | @Test 149 | default void savePoint() { 150 | getJdbcOperations().execute("INSERT INTO test VALUES (100)"); 151 | 152 | getR2dbc() 153 | .withHandle(handle -> handle 154 | .inTransaction(h1 -> h1 155 | .select("SELECT value FROM test") 156 | .mapResult(Example::extractColumns) 157 | 158 | .concatWith(h1.execute(String.format("INSERT INTO test VALUES (%s)", getPlaceholder(0)), 200)) 159 | .concatWith(h1.select("SELECT value FROM test") 160 | .mapResult(Example::extractColumns)) 161 | 162 | .concatWith(h1.createSavepoint("test_savepoint")) 163 | .concatWith(h1.execute(String.format("INSERT INTO test VALUES (%s)", getPlaceholder(0)), 300)) 164 | .concatWith(h1.select("SELECT value FROM test") 165 | .mapResult(Example::extractColumns)) 166 | 167 | .concatWith(h1.rollbackTransactionToSavepoint("test_savepoint")) 168 | .concatWith(h1.select("SELECT value FROM test") 169 | .mapResult(Example::extractColumns)))) 170 | 171 | .as(StepVerifier::create) 172 | .expectNext(Collections.singletonList(100)).as("value from select") 173 | .expectNext(1).as("rows inserted") 174 | .expectNext(Arrays.asList(100, 200)).as("values from select") 175 | .expectNext(1).as("rows inserted") 176 | .expectNext(Arrays.asList(100, 200, 300)).as("values from select") 177 | .expectNext(Arrays.asList(100, 200)).as("values from select") 178 | .verifyComplete(); 179 | } 180 | 181 | @Test 182 | default void transactionCommit() { 183 | getJdbcOperations().execute("INSERT INTO test VALUES (100)"); 184 | 185 | getR2dbc() 186 | .withHandle(handle -> handle 187 | .inTransaction(h1 -> h1 188 | .select("SELECT value FROM test") 189 | .mapResult(Example::extractColumns) 190 | 191 | .concatWith(h1.execute(String.format("INSERT INTO test VALUES (%s)", getPlaceholder(0)), 200)) 192 | .concatWith(h1.select("SELECT value FROM test") 193 | .mapResult(Example::extractColumns))) 194 | 195 | .concatWith(handle.select("SELECT value FROM test") 196 | .mapResult(Example::extractColumns))) 197 | 198 | .as(StepVerifier::create) 199 | .expectNext(Collections.singletonList(100)).as("value from select") 200 | .expectNext(1).as("rows inserted") 201 | .expectNext(Arrays.asList(100, 200)).as("values from select") 202 | .expectNext(Arrays.asList(100, 200)).as("values from select") 203 | .verifyComplete(); 204 | } 205 | 206 | @Test 207 | default void transactionRollback() { 208 | getJdbcOperations().execute("INSERT INTO test VALUES (100)"); 209 | 210 | getR2dbc() 211 | .withHandle(handle -> handle 212 | .inTransaction(h1 -> h1 213 | .select("SELECT value FROM test") 214 | .mapResult(Example::extractColumns) 215 | 216 | .concatWith(h1.execute(String.format("INSERT INTO test VALUES (%s)", getPlaceholder(0)), 200)) 217 | .concatWith(h1.select("SELECT value FROM test") 218 | .mapResult(Example::extractColumns)) 219 | 220 | .concatWith(Mono.error(new Exception()))) 221 | 222 | .onErrorResume(t -> handle.select("SELECT value FROM test") 223 | .mapResult(Example::extractColumns))) 224 | 225 | .as(StepVerifier::create) 226 | .expectNext(Collections.singletonList(100)).as("value from select") 227 | .expectNext(1).as("rows inserted") 228 | .expectNext(Arrays.asList(100, 200)).as("values from select") 229 | .expectNext(Collections.singletonList(100)).as("value from select") 230 | .verifyComplete(); 231 | } 232 | 233 | } 234 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | https://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | https://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /src/main/java/io/r2dbc/client/Handle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.client.util.Assert; 20 | import io.r2dbc.spi.Connection; 21 | import io.r2dbc.spi.IsolationLevel; 22 | import org.reactivestreams.Publisher; 23 | import reactor.core.publisher.Flux; 24 | import reactor.core.publisher.Mono; 25 | 26 | import java.util.function.Function; 27 | import java.util.stream.IntStream; 28 | 29 | import static io.r2dbc.client.util.ReactiveUtils.appendError; 30 | import static io.r2dbc.client.util.ReactiveUtils.typeSafe; 31 | 32 | /** 33 | * A wrapper for a {@link Connection} providing additional convenience APIs. 34 | */ 35 | public final class Handle { 36 | 37 | private final Connection connection; 38 | 39 | Handle(Connection connection) { 40 | this.connection = Assert.requireNonNull(connection, "connection must not be null"); 41 | } 42 | 43 | /** 44 | * Begins a new transaction. 45 | * 46 | * @return a {@link Publisher} that indicates that the transaction is open 47 | */ 48 | public Publisher beginTransaction() { 49 | return this.connection.beginTransaction(); 50 | } 51 | 52 | /** 53 | * Release any resources held by the {@link Handle}. 54 | * 55 | * @return a {@link Publisher} that termination is complete 56 | */ 57 | public Publisher close() { 58 | return this.connection.close(); 59 | } 60 | 61 | /** 62 | * Commits the current transaction. 63 | * 64 | * @return a {@link Publisher} that indicates that a transaction has been committed 65 | */ 66 | public Publisher commitTransaction() { 67 | return this.connection.commitTransaction(); 68 | } 69 | 70 | /** 71 | * Creates a new {@link Batch} instance for building a batched request. 72 | * 73 | * @return a new {@link Batch} instance 74 | */ 75 | public Batch createBatch() { 76 | return new Batch(this.connection.createBatch()); 77 | } 78 | 79 | /** 80 | * Creates a new {@link Query} instance for building a request. 81 | * 82 | * @param sql the SQL of the query 83 | * @return a new {@link Query} instance 84 | * @throws IllegalArgumentException if {@code sql} is {@code null} 85 | */ 86 | public Query createQuery(String sql) { 87 | Assert.requireNonNull(sql, "sql must not be null"); 88 | 89 | return new Query(this.connection.createStatement(sql)); 90 | } 91 | 92 | /** 93 | * Creates a savepoint in the current transaction. 94 | * 95 | * @param name the name of the savepoint to create 96 | * @return a {@link Publisher} that indicates that a savepoint has been created 97 | * @throws IllegalArgumentException if {@code name} is {@code null} 98 | */ 99 | public Publisher createSavepoint(String name) { 100 | Assert.requireNonNull(name, "name must not be null"); 101 | 102 | return this.connection.createSavepoint(name); 103 | } 104 | 105 | /** 106 | * Create a new {@link Update} instance for building an updating request. 107 | * 108 | * @param sql the SQL of the update 109 | * @return a new {@link Update} instance 110 | * @throws IllegalArgumentException if {@code sql} is {@code null} 111 | */ 112 | public Update createUpdate(String sql) { 113 | Assert.requireNonNull(sql, "sql must not be null"); 114 | 115 | return new Update(this.connection.createStatement(sql)); 116 | } 117 | 118 | /** 119 | * A convenience method for building and executing an {@link Update}, binding an ordered set of parameters. 120 | * 121 | * @param sql the SQL of the update 122 | * @param parameters the parameters to bind 123 | * @return the number of rows that were updated 124 | * @throws IllegalArgumentException if {@code sql} or {@code parameters} is {@code null} 125 | */ 126 | public Flux execute(String sql, Object... parameters) { 127 | Assert.requireNonNull(sql, "sql must not be null"); 128 | Assert.requireNonNull(parameters, "parameters must not be null"); 129 | 130 | Update update = createUpdate(sql); 131 | 132 | IntStream.range(0, parameters.length) 133 | .forEach(i -> update.bind(i, parameters[i])); 134 | 135 | return update.add().execute(); 136 | } 137 | 138 | /** 139 | * Execute behavior within a transaction returning results. The transaction is committed if the behavior completes successfully, and rolled back it produces an error. 140 | * 141 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results 142 | * @param the type of results 143 | * @return a {@link Flux} of results 144 | * @throws IllegalArgumentException if {@code resourceFunction} is {@code null} 145 | * @see Connection#commitTransaction() 146 | * @see Connection#rollbackTransaction() 147 | */ 148 | @SuppressWarnings("unchecked") 149 | public Flux inTransaction(Function> resourceFunction) { 150 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 151 | 152 | return Mono.from( 153 | beginTransaction()) 154 | .thenMany((Publisher) resourceFunction.apply(this)) 155 | .concatWith(typeSafe(this::commitTransaction)) 156 | .onErrorResume(appendError(this::rollbackTransaction)); 157 | } 158 | 159 | /** 160 | * Execute behavior within a transaction returning results. The transaction is committed if the behavior completes successfully, and rolled back it produces an error. 161 | * 162 | * @param isolationLevel the isolation level of the transaction 163 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results 164 | * @param the type of results 165 | * @return a {@link Flux} of results 166 | * @throws IllegalArgumentException if {@code resourceFunction} is {@code null} 167 | * @see Connection#setTransactionIsolationLevel(IsolationLevel) 168 | * @see Connection#commitTransaction() 169 | * @see Connection#rollbackTransaction() 170 | */ 171 | @SuppressWarnings("unchecked") 172 | public Flux inTransaction(IsolationLevel isolationLevel, Function> resourceFunction) { 173 | Assert.requireNonNull(isolationLevel, "isolationLevel must not be null"); 174 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 175 | 176 | return inTransaction(handle -> Flux.from(handle 177 | .setTransactionIsolationLevel(isolationLevel)) 178 | .thenMany((Publisher) resourceFunction.apply(this))); 179 | } 180 | 181 | /** 182 | * Releases a savepoint in the current transaction. 183 | * 184 | * @param name the name of the savepoint to release 185 | * @return a {@link Publisher} that indicates that a savepoint has been released 186 | * @throws IllegalArgumentException if {@code name} is {@code null} 187 | */ 188 | public Publisher releaseSavepoint(String name) { 189 | Assert.requireNonNull(name, "name must not be null"); 190 | 191 | return this.connection.releaseSavepoint(name); 192 | } 193 | 194 | /** 195 | * Rolls back the current transaction. 196 | * 197 | * @return a {@link Publisher} that indicates that a transaction has been rolled back 198 | */ 199 | public Publisher rollbackTransaction() { 200 | return this.connection.rollbackTransaction(); 201 | } 202 | 203 | /** 204 | * Rolls back to a savepoint in the current transaction. 205 | * 206 | * @param name the name of the savepoint to rollback to 207 | * @return a {@link Publisher} that indicates that a savepoint has been rolled back to 208 | * @throws IllegalArgumentException if {@code name} is {@code null} 209 | */ 210 | public Publisher rollbackTransactionToSavepoint(String name) { 211 | Assert.requireNonNull(name, "name must not be null"); 212 | 213 | return this.connection.rollbackTransactionToSavepoint(name); 214 | } 215 | 216 | /** 217 | * A convenience method for building a {@link Query}, binding an ordered set of parameters. 218 | * 219 | * @param sql the SQL of the query 220 | * @param parameters the parameters to bind 221 | * @return a new {@link Query} instance 222 | * @throws IllegalArgumentException if {@code sql} or {@code parameters} is {@code null} 223 | */ 224 | public Query select(String sql, Object... parameters) { 225 | Assert.requireNonNull(sql, "sql must not be null"); 226 | Assert.requireNonNull(parameters, "parameters must not be null"); 227 | 228 | Query query = createQuery(sql); 229 | 230 | IntStream.range(0, parameters.length) 231 | .forEach(i -> query.bind(i, parameters[i])); 232 | 233 | return query.add(); 234 | } 235 | 236 | /** 237 | * Configures the isolation level for the current transaction. 238 | * 239 | * @param isolationLevel the isolation level for this transaction 240 | * @return a {@link Publisher} that indicates that a transaction level has been configured 241 | * @throws IllegalArgumentException if {@code isolationLevel} is {@code null} 242 | */ 243 | public Publisher setTransactionIsolationLevel(IsolationLevel isolationLevel) { 244 | Assert.requireNonNull(isolationLevel, "isolationLevel must not be null"); 245 | 246 | return this.connection.setTransactionIsolationLevel(isolationLevel); 247 | } 248 | 249 | @Override 250 | public String toString() { 251 | return "Handle{" + 252 | "connection=" + this.connection + 253 | '}'; 254 | } 255 | 256 | /** 257 | * Execute behavior within a transaction not returning results. The transaction is committed if the behavior completes successfully, and rolled back it produces an error. 258 | * 259 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results. These results are discarded. 260 | * @return a {@link Mono} that execution is complete 261 | * @throws IllegalArgumentException if {@code resourceFunction} is {@code null} 262 | * @see Connection#commitTransaction() 263 | * @see Connection#rollbackTransaction() 264 | */ 265 | public Mono useTransaction(Function> resourceFunction) { 266 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 267 | 268 | return inTransaction(resourceFunction) 269 | .then(); 270 | } 271 | 272 | /** 273 | * Execute behavior within a transaction not returning results. The transaction is committed if the behavior completes successfully, and rolled back it produces an error. 274 | * 275 | * @param isolationLevel the isolation level of the transaction 276 | * @param resourceFunction a {@link Function} that takes a {@link Handle} and returns a {@link Publisher} of results. These results are discarded. 277 | * @return a {@link Mono} that execution is complete 278 | * @throws IllegalArgumentException if {@code isolationLevel} or {@code resourceFunction} is {@code null} 279 | * @see Connection#setTransactionIsolationLevel(IsolationLevel) 280 | * @see Connection#commitTransaction() 281 | * @see Connection#rollbackTransaction() 282 | */ 283 | public Mono useTransaction(IsolationLevel isolationLevel, Function> resourceFunction) { 284 | Assert.requireNonNull(isolationLevel, "isolationLevel must not be null"); 285 | Assert.requireNonNull(resourceFunction, "resourceFunction must not be null"); 286 | 287 | return inTransaction(isolationLevel, resourceFunction) 288 | .then(); 289 | } 290 | 291 | } 292 | -------------------------------------------------------------------------------- /intellij-style.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/test/java/io/r2dbc/client/HandleTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.r2dbc.client; 18 | 19 | import io.r2dbc.spi.test.MockBatch; 20 | import io.r2dbc.spi.test.MockConnection; 21 | import io.r2dbc.spi.test.MockResult; 22 | import io.r2dbc.spi.test.MockStatement; 23 | import org.junit.jupiter.api.Test; 24 | import org.reactivestreams.Publisher; 25 | import reactor.core.publisher.Mono; 26 | import reactor.test.StepVerifier; 27 | 28 | import java.util.Collections; 29 | 30 | import static io.r2dbc.spi.IsolationLevel.SERIALIZABLE; 31 | import static org.assertj.core.api.Assertions.assertThat; 32 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 33 | 34 | final class HandleTest { 35 | 36 | @Test 37 | void beginTransaction() { 38 | MockConnection connection = MockConnection.empty(); 39 | 40 | Publisher publisher = new Handle(connection) 41 | .beginTransaction(); 42 | 43 | StepVerifier.create(publisher).verifyComplete(); 44 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 45 | } 46 | 47 | @Test 48 | void close() { 49 | MockConnection connection = MockConnection.empty(); 50 | 51 | Publisher publisher = new Handle(connection) 52 | .close(); 53 | 54 | StepVerifier.create(publisher).verifyComplete(); 55 | assertThat(connection.isCloseCalled()).isTrue(); 56 | } 57 | 58 | @Test 59 | void commitTransaction() { 60 | MockConnection connection = MockConnection.empty(); 61 | 62 | Publisher publisher = new Handle(connection) 63 | .commitTransaction(); 64 | 65 | StepVerifier.create(publisher).verifyComplete(); 66 | assertThat(connection.isCommitTransactionCalled()).isTrue(); 67 | } 68 | 69 | @Test 70 | void constructorNoConnection() { 71 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(null)) 72 | .withMessage("connection must not be null"); 73 | } 74 | 75 | @Test 76 | void createBatch() { 77 | MockConnection connection = MockConnection.builder() 78 | .batch(MockBatch.empty()) 79 | .build(); 80 | 81 | Batch batch = new Handle(connection) 82 | .createBatch(); 83 | 84 | assertThat(batch).isNotNull(); 85 | } 86 | 87 | @Test 88 | void createQuery() { 89 | MockConnection connection = MockConnection.builder() 90 | .statement(MockStatement.empty()) 91 | .build(); 92 | 93 | Query query = new Handle(connection) 94 | .createQuery("test-query"); 95 | 96 | assertThat(query).isNotNull(); 97 | assertThat(connection.getCreateStatementSql()).isEqualTo("test-query"); 98 | } 99 | 100 | @Test 101 | void createQueryNoSql() { 102 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).createQuery(null)) 103 | .withMessage("sql must not be null"); 104 | } 105 | 106 | @Test 107 | void createSavepoint() { 108 | MockConnection connection = MockConnection.empty(); 109 | 110 | Publisher publisher = new Handle(connection) 111 | .createSavepoint("test-savepoint"); 112 | 113 | StepVerifier.create(publisher).verifyComplete(); 114 | assertThat(connection.getCreateSavepointName()).isEqualTo("test-savepoint"); 115 | } 116 | 117 | @Test 118 | void createSavepointNoName() { 119 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).createSavepoint(null)) 120 | .withMessage("name must not be null"); 121 | } 122 | 123 | @Test 124 | void createUpdate() { 125 | MockConnection connection = MockConnection.builder() 126 | .statement(MockStatement.empty()) 127 | .build(); 128 | 129 | Update update = new Handle(connection) 130 | .createUpdate("test-update"); 131 | 132 | assertThat(update).isNotNull(); 133 | assertThat(connection.getCreateStatementSql()).isEqualTo("test-update"); 134 | } 135 | 136 | @Test 137 | void createUpdateNoSql() { 138 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).createUpdate(null)) 139 | .withMessage("sql must not be null"); 140 | } 141 | 142 | @Test 143 | void execute() { 144 | MockStatement statement = MockStatement.builder() 145 | .result(MockResult.builder() 146 | .rowsUpdated(200) 147 | .build()) 148 | .build(); 149 | 150 | MockConnection connection = MockConnection.builder() 151 | .statement(statement) 152 | .build(); 153 | 154 | new Handle(connection) 155 | .execute("test-update", 100) 156 | .as(StepVerifier::create) 157 | .expectNext(200) 158 | .verifyComplete(); 159 | 160 | assertThat(connection.getCreateStatementSql()).isEqualTo("test-update"); 161 | assertThat(statement.getBindings()).contains(Collections.singletonMap(0, 100)); 162 | } 163 | 164 | @Test 165 | void executeNoSql() { 166 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).execute(null, new Object())) 167 | .withMessage("sql must not be null"); 168 | } 169 | 170 | @Test 171 | void inTransaction() { 172 | MockConnection connection = MockConnection.empty(); 173 | 174 | new Handle(connection) 175 | .inTransaction(handle -> 176 | Mono.just(100)) 177 | .as(StepVerifier::create) 178 | .expectNext(100) 179 | .verifyComplete(); 180 | 181 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 182 | assertThat(connection.isCommitTransactionCalled()).isTrue(); 183 | } 184 | 185 | @Test 186 | void inTransactionError() { 187 | MockConnection connection = MockConnection.empty(); 188 | Exception exception = new Exception(); 189 | 190 | new Handle(connection) 191 | .inTransaction(handle -> 192 | Mono.error(exception)) 193 | .as(StepVerifier::create) 194 | .verifyErrorMatches(exception::equals); 195 | 196 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 197 | assertThat(connection.isRollbackTransactionCalled()).isTrue(); 198 | } 199 | 200 | @Test 201 | void inTransactionIsolationLevel() { 202 | MockConnection connection = MockConnection.empty(); 203 | 204 | new Handle(connection) 205 | .inTransaction(SERIALIZABLE, handle -> 206 | Mono.just(100)) 207 | .as(StepVerifier::create) 208 | .expectNext(100) 209 | .verifyComplete(); 210 | 211 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 212 | assertThat(connection.getTransactionIsolationLevel()).isEqualTo(SERIALIZABLE); 213 | assertThat(connection.isCommitTransactionCalled()).isTrue(); 214 | } 215 | 216 | @Test 217 | void inTransactionIsolationLevelNoF() { 218 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).inTransaction(SERIALIZABLE, null)) 219 | .withMessage("resourceFunction must not be null"); 220 | } 221 | 222 | @Test 223 | void inTransactionIsolationLevelNoIsolationLevel() { 224 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).inTransaction(null, handle -> Mono.empty())) 225 | .withMessage("isolationLevel must not be null"); 226 | } 227 | 228 | @Test 229 | void inTransactionNoF() { 230 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).inTransaction(null)) 231 | .withMessage("resourceFunction must not be null"); 232 | } 233 | 234 | @Test 235 | void releaseSavepoint() { 236 | MockConnection connection = MockConnection.empty(); 237 | 238 | Publisher publisher = new Handle(connection) 239 | .releaseSavepoint("test-savepoint"); 240 | 241 | StepVerifier.create(publisher).verifyComplete(); 242 | assertThat(connection.getReleaseSavepointName()).isEqualTo("test-savepoint"); 243 | } 244 | 245 | @Test 246 | void releaseSavepointNoName() { 247 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).releaseSavepoint(null)) 248 | .withMessage("name must not be null"); 249 | } 250 | 251 | @Test 252 | void rollbackTransaction() { 253 | MockConnection connection = MockConnection.empty(); 254 | 255 | Publisher publisher = new Handle(connection) 256 | .rollbackTransaction(); 257 | 258 | StepVerifier.create(publisher).verifyComplete(); 259 | assertThat(connection.isRollbackTransactionCalled()).isTrue(); 260 | } 261 | 262 | @Test 263 | void rollbackTransactionToSavepoint() { 264 | MockConnection connection = MockConnection.empty(); 265 | 266 | Publisher publisher = new Handle(connection) 267 | .rollbackTransactionToSavepoint("test-savepoint"); 268 | 269 | StepVerifier.create(publisher).verifyComplete(); 270 | assertThat(connection.getRollbackTransactionToSavepointName()).isEqualTo("test-savepoint"); 271 | } 272 | 273 | @Test 274 | void rollbackTransactionToSavepointNoName() { 275 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).rollbackTransactionToSavepoint(null)) 276 | .withMessage("name must not be null"); 277 | } 278 | 279 | @Test 280 | void select() { 281 | MockStatement statement = MockStatement.empty(); 282 | 283 | MockConnection connection = MockConnection.builder() 284 | .statement(statement) 285 | .build(); 286 | 287 | Query query = new Handle(connection) 288 | .select("test-query", 100); 289 | 290 | assertThat(query).isNotNull(); 291 | assertThat(connection.getCreateStatementSql()).isEqualTo("test-query"); 292 | assertThat(statement.getBindings()).contains(Collections.singletonMap(0, 100)); 293 | } 294 | 295 | @Test 296 | void selectNoSql() { 297 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).select(null, new Object())) 298 | .withMessage("sql must not be null"); 299 | } 300 | 301 | @Test 302 | void setTransactionIsolationLevel() { 303 | MockConnection connection = MockConnection.empty(); 304 | 305 | Publisher publisher = new Handle(connection) 306 | .setTransactionIsolationLevel(SERIALIZABLE); 307 | 308 | StepVerifier.create(publisher).verifyComplete(); 309 | assertThat(connection.getTransactionIsolationLevel()).isEqualTo(SERIALIZABLE); 310 | } 311 | 312 | @Test 313 | void setTransactionIsolationLevelNoIsolationLevel() { 314 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).setTransactionIsolationLevel(null)) 315 | .withMessage("isolationLevel must not be null"); 316 | } 317 | 318 | @Test 319 | void useTransaction() { 320 | MockConnection connection = MockConnection.empty(); 321 | 322 | new Handle(connection) 323 | .useTransaction(handle -> 324 | Mono.just(100)) 325 | .as(StepVerifier::create) 326 | .verifyComplete(); 327 | 328 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 329 | assertThat(connection.isCommitTransactionCalled()).isTrue(); 330 | } 331 | 332 | @Test 333 | void useTransactionError() { 334 | MockConnection connection = MockConnection.empty(); 335 | Exception exception = new Exception(); 336 | 337 | new Handle(connection) 338 | .useTransaction(handle -> 339 | Mono.error(exception)) 340 | .as(StepVerifier::create) 341 | .verifyErrorMatches(exception::equals); 342 | 343 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 344 | assertThat(connection.isRollbackTransactionCalled()).isTrue(); 345 | } 346 | 347 | @Test 348 | void useTransactionIsolationLevel() { 349 | MockConnection connection = MockConnection.empty(); 350 | 351 | new Handle(connection) 352 | .useTransaction(SERIALIZABLE, handle -> 353 | Mono.just(100)) 354 | .as(StepVerifier::create) 355 | .verifyComplete(); 356 | 357 | assertThat(connection.isBeginTransactionCalled()).isTrue(); 358 | assertThat(connection.getTransactionIsolationLevel()).isEqualTo(SERIALIZABLE); 359 | assertThat(connection.isCommitTransactionCalled()).isTrue(); 360 | } 361 | 362 | @Test 363 | void useTransactionIsolationLevelNoF() { 364 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).useTransaction(SERIALIZABLE, null)) 365 | .withMessage("resourceFunction must not be null"); 366 | } 367 | 368 | @Test 369 | void useTransactionIsolationLevelNoIsolationLevel() { 370 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).useTransaction(null, handle -> Mono.empty())) 371 | .withMessage("isolationLevel must not be null"); 372 | } 373 | 374 | @Test 375 | void useTransactionNoF() { 376 | assertThatIllegalArgumentException().isThrownBy(() -> new Handle(MockConnection.empty()).useTransaction(null)) 377 | .withMessage("resourceFunction must not be null"); 378 | } 379 | 380 | } 381 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 22 | 23 | 4.0.0 24 | 25 | io.r2dbc 26 | r2dbc-client 27 | 0.8.0.BUILD-SNAPSHOT 28 | jar 29 | 30 | Reactive Relational Database Connectivity - Client 31 | https://github.com/r2dbc/r2dbc-client 32 | 33 | 34 | 3.12.0 35 | 1.8 36 | 3.0.2 37 | 5.5.2 38 | 1.2.3 39 | 7.2.2.jre8 40 | 8.0.16 41 | 42.2.8 42 | UTF-8 43 | UTF-8 44 | ${project.version} 45 | ${project.version} 46 | ${project.version} 47 | ${project.version} 48 | ${project.version} 49 | ${project.version} 50 | Dysprosium-RELEASE 51 | 2.1.4.RELEASE 52 | 1.12.0 53 | 54 | 55 | 56 | 57 | 58 | io.projectreactor 59 | reactor-bom 60 | ${reactor.version} 61 | pom 62 | import 63 | 64 | 65 | org.junit 66 | junit-bom 67 | ${junit.version} 68 | pom 69 | import 70 | 71 | 72 | org.testcontainers 73 | testcontainers-bom 74 | ${testcontainers.version} 75 | pom 76 | import 77 | 78 | 79 | 80 | 81 | 82 | 83 | io.projectreactor 84 | reactor-core 85 | 86 | 87 | io.r2dbc 88 | r2dbc-spi 89 | ${r2dbc-spi.version} 90 | 91 | 92 | 93 | com.google.code.findbugs 94 | jsr305 95 | ${jsr305.version} 96 | provided 97 | 98 | 99 | 100 | ch.qos.logback 101 | logback-classic 102 | ${logback.version} 103 | test 104 | 105 | 106 | dev.miku 107 | r2dbc-mysql 108 | ${r2dbc-mysql.version} 109 | test 110 | 111 | 112 | com.microsoft.sqlserver 113 | mssql-jdbc 114 | ${mssql-jdbc.version} 115 | test 116 | 117 | 118 | io.projectreactor 119 | reactor-test 120 | test 121 | 122 | 123 | io.r2dbc 124 | r2dbc-spi-test 125 | ${r2dbc-spi.version} 126 | test 127 | 128 | 129 | org.assertj 130 | assertj-core 131 | ${assertj.version} 132 | test 133 | 134 | 135 | org.junit.jupiter 136 | junit-jupiter-api 137 | test 138 | 139 | 140 | org.junit.jupiter 141 | junit-jupiter-engine 142 | test 143 | 144 | 145 | io.r2dbc 146 | r2dbc-pool 147 | ${r2dbc-pool.version} 148 | test 149 | 150 | 151 | io.r2dbc 152 | r2dbc-postgresql 153 | ${r2dbc-postgresql.version} 154 | test 155 | 156 | 157 | io.r2dbc 158 | r2dbc-h2 159 | ${r2dbc-h2.version} 160 | test 161 | 162 | 163 | io.r2dbc 164 | r2dbc-mssql 165 | ${r2dbc-mssql.version} 166 | test 167 | 168 | 169 | mysql 170 | mysql-connector-java 171 | ${mysql.version} 172 | test 173 | 174 | 175 | org.postgresql 176 | postgresql 177 | ${postgresql.version} 178 | test 179 | 180 | 181 | org.springframework.boot 182 | spring-boot-starter-jdbc 183 | ${spring-boot.version} 184 | test 185 | 186 | 187 | org.testcontainers 188 | mssqlserver 189 | test 190 | 191 | 192 | org.testcontainers 193 | mysql 194 | test 195 | 196 | 197 | org.testcontainers 198 | postgresql 199 | test 200 | 201 | 202 | com.jayway.jsonpath 203 | json-path 204 | RELEASE 205 | test 206 | 207 | 208 | org.springframework.hateoas 209 | spring-hateoas 210 | 1.0.0.RC2 211 | test 212 | 213 | 214 | org.springframework.boot 215 | spring-boot-starter-webflux 216 | ${spring-boot.version} 217 | test 218 | 219 | 220 | 221 | 222 | 223 | 224 | org.apache.maven.plugins 225 | maven-compiler-plugin 226 | 3.8.0 227 | 228 | 229 | -Werror 230 | -Xlint:all 231 | -Xlint:-options 232 | -Xlint:-processing 233 | -Xlint:-serial 234 | 235 | true 236 | ${java.version} 237 | ${java.version} 238 | 239 | 240 | 241 | org.apache.maven.plugins 242 | maven-deploy-plugin 243 | 2.8.2 244 | 245 | 246 | org.apache.maven.plugins 247 | maven-javadoc-plugin 248 | 3.0.1 249 | 250 | io.r2dbc.client.* 251 | 252 | https://projectreactor.io/docs/core/release/api/ 253 | https://www.reactive-streams.org/reactive-streams-1.0.2-javadoc/ 254 | 255 | 256 | 257 | 258 | attach-javadocs 259 | 260 | jar 261 | 262 | 263 | 264 | 265 | 266 | org.apache.maven.plugins 267 | maven-source-plugin 268 | 3.0.1 269 | 270 | 271 | attach-sources 272 | 273 | jar 274 | 275 | 276 | 277 | 278 | 279 | org.apache.maven.plugins 280 | maven-surefire-plugin 281 | 2.22.1 282 | 283 | random 284 | 285 | **/*Example.java 286 | **/*Test.java 287 | 288 | 289 | 290 | 291 | org.codehaus.mojo 292 | flatten-maven-plugin 293 | 1.1.0 294 | 295 | 296 | flatten 297 | process-resources 298 | 299 | flatten 300 | 301 | 302 | true 303 | oss 304 | 305 | keep 306 | keep 307 | expand 308 | remove 309 | 310 | 311 | 312 | 313 | flatten-clean 314 | clean 315 | 316 | clean 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | ${project.basedir} 325 | 326 | LICENSE 327 | NOTICE 328 | 329 | META-INF 330 | 331 | 332 | 333 | 334 | 335 | 336 | spring-milestones 337 | Spring Milestones 338 | https://repo.spring.io/milestone 339 | 340 | false 341 | 342 | 343 | 344 | spring-snapshots 345 | Spring Snapshots 346 | https://repo.spring.io/snapshot 347 | 348 | true 349 | 350 | 351 | 352 | oss-sonatype-snapshots 353 | https://oss.sonatype.org/content/repositories/snapshots/ 354 | 355 | true 356 | 357 | 358 | 359 | 360 | 361 | 362 | r2dbc-h2-artifactory 363 | 364 | 365 | r2dbcH2Artifactory 366 | 367 | 368 | 369 | 370 | r2dbc-h2-artifactory 371 | ${r2dbcH2Artifactory} 372 | 373 | true 374 | 375 | 376 | 377 | 378 | 379 | r2dbc-mssql-artifactory 380 | 381 | 382 | r2dbcMssqlArtifactory 383 | 384 | 385 | 386 | 387 | r2dbc-mssql-artifactory 388 | ${r2dbcMssqlArtifactory} 389 | 390 | true 391 | 392 | 393 | 394 | 395 | 396 | r2dbc-pool-artifactory 397 | 398 | 399 | r2dbcPoolArtifactory 400 | 401 | 402 | 403 | 404 | r2dbc-pool-artifactory 405 | ${r2dbcPoolArtifactory} 406 | 407 | true 408 | 409 | 410 | 411 | 412 | 413 | r2dbc-postgresql-artifactory 414 | 415 | 416 | r2dbcPostgresqlArtifactory 417 | 418 | 419 | 420 | 421 | r2dbc-postgresql-artifactory 422 | ${r2dbcPostgresqlArtifactory} 423 | 424 | true 425 | 426 | 427 | 428 | 429 | 430 | r2dbc-spi-artifactory 431 | 432 | 433 | r2dbcSpiArtifactory 434 | 435 | 436 | 437 | 438 | r2dbc-spi-artifactory 439 | ${r2dbcSpiArtifactory} 440 | 441 | true 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | --------------------------------------------------------------------------------