Skip to content

Commit aff601e

Browse files
mp911desbrannen
authored andcommitted
Add support for R2DBC
This commit introduces support for R2DBC ("Reactive Relational Database Connectivity") with custom ConnectionFactory implementations, a functional DatabaseClient for SQL execution, transaction management, a bind marker abstraction database initialization utilities, and exception translation. Closes gh-25065
1 parent 7f79a37 commit aff601e

File tree

114 files changed

+13150
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+13150
-1
lines changed

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ configure(allprojects) { project ->
2626
mavenBom "com.fasterxml.jackson:jackson-bom:2.11.0"
2727
mavenBom "io.netty:netty-bom:4.1.50.Final"
2828
mavenBom "io.projectreactor:reactor-bom:2020.0.0-SNAPSHOT"
29+
mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR5"
2930
mavenBom "io.rsocket:rsocket-bom:1.0.1"
3031
mavenBom "org.eclipse.jetty:jetty-bom:9.4.30.v20200611"
3132
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.4-M2"

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ include "spring-expression"
2424
include "spring-instrument"
2525
include "spring-jcl"
2626
include "spring-jdbc"
27+
include "spring-r2dbc"
2728
include "spring-jms"
2829
include "spring-messaging"
2930
include "spring-orm"

spring-r2dbc/spring-r2dbc.gradle

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
description = "Spring R2DBC"
2+
3+
apply plugin: "kotlin"
4+
5+
// Workaround for https://youtrack.jetbrains.com/issue/KT-39610
6+
configurations["optional"].attributes.attribute(
7+
org.gradle.api.attributes.Usage.USAGE_ATTRIBUTE,
8+
objects.named(Usage.class, "java-runtime")
9+
)
10+
11+
dependencies {
12+
compile(project(":spring-beans"))
13+
compile(project(":spring-core"))
14+
compile(project(":spring-tx"))
15+
compile("io.r2dbc:r2dbc-spi")
16+
compile("io.projectreactor:reactor-core")
17+
compileOnly(project(":kotlin-coroutines"))
18+
optional("org.jetbrains.kotlin:kotlin-reflect")
19+
optional("org.jetbrains.kotlin:kotlin-stdlib")
20+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-core")
21+
optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor")
22+
testCompile(project(":kotlin-coroutines"))
23+
testCompile(testFixtures(project(":spring-beans")))
24+
testCompile(testFixtures(project(":spring-core")))
25+
testCompile(testFixtures(project(":spring-context")))
26+
testCompile("io.projectreactor:reactor-test")
27+
testCompile("io.r2dbc:r2dbc-h2")
28+
testCompile("io.r2dbc:r2dbc-spi-test:0.8.1.RELEASE")
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2002-2020 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 org.springframework.r2dbc;
18+
19+
import io.r2dbc.spi.R2dbcException;
20+
21+
import org.springframework.dao.InvalidDataAccessResourceUsageException;
22+
23+
24+
/**
25+
* Exception thrown when SQL specified is invalid. Such exceptions always have a
26+
* {@link io.r2dbc.spi.R2dbcException} root cause.
27+
*
28+
* <p>It would be possible to have subclasses for no such table, no such column etc.
29+
* A custom R2dbcExceptionTranslator could create such more specific exceptions,
30+
* without affecting code using this class.
31+
*
32+
* @author Mark Paluch
33+
* @since 5.3
34+
*/
35+
@SuppressWarnings("serial")
36+
public class BadSqlGrammarException extends InvalidDataAccessResourceUsageException {
37+
38+
private final String sql;
39+
40+
41+
/**
42+
* Constructor for BadSqlGrammarException.
43+
* @param task name of current task
44+
* @param sql the offending SQL statement
45+
* @param ex the root cause
46+
*/
47+
public BadSqlGrammarException(String task, String sql, R2dbcException ex) {
48+
super(task + "; bad SQL grammar [" + sql + "]", ex);
49+
this.sql = sql;
50+
}
51+
52+
53+
/**
54+
* Return the wrapped {@link R2dbcException}.
55+
*/
56+
public R2dbcException getR2dbcException() {
57+
return (R2dbcException) getCause();
58+
}
59+
60+
/**
61+
* Return the SQL that caused the problem.
62+
*/
63+
public String getSql() {
64+
return this.sql;
65+
}
66+
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2002-2020 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 org.springframework.r2dbc;
18+
19+
import io.r2dbc.spi.R2dbcException;
20+
21+
import org.springframework.dao.UncategorizedDataAccessException;
22+
import org.springframework.lang.Nullable;
23+
24+
/**
25+
* Exception thrown when we can't classify a {@link R2dbcException} into
26+
* one of our generic data access exceptions.
27+
*
28+
* @author Mark Paluch
29+
* @since 5.3
30+
*/
31+
@SuppressWarnings("serial")
32+
public class UncategorizedR2dbcException extends UncategorizedDataAccessException {
33+
34+
/** SQL that led to the problem. */
35+
@Nullable
36+
private final String sql;
37+
38+
39+
/**
40+
* Constructor for {@code UncategorizedSQLException}.
41+
* @param msg the detail message
42+
* @param sql the offending SQL statement
43+
* @param ex the exception thrown by underlying data access API
44+
*/
45+
public UncategorizedR2dbcException(String msg, @Nullable String sql, R2dbcException ex) {
46+
super(msg, ex);
47+
this.sql = sql;
48+
}
49+
50+
51+
/**
52+
* Return the wrapped {@link R2dbcException}.
53+
*/
54+
public R2dbcException getR2dbcException() {
55+
return (R2dbcException) getCause();
56+
}
57+
58+
/**
59+
* Return the SQL that led to the problem (if known).
60+
*/
61+
@Nullable
62+
public String getSql() {
63+
return this.sql;
64+
}
65+
66+
}

0 commit comments

Comments
 (0)