https://github.com/gudzpoz/r2dbc-jdbc
R2DBC over JDBC
https://github.com/gudzpoz/r2dbc-jdbc
database java r2dbc reactive reactive-streams
Last synced: about 2 months ago
JSON representation
R2DBC over JDBC
- Host: GitHub
- URL: https://github.com/gudzpoz/r2dbc-jdbc
- Owner: gudzpoz
- License: apache-2.0
- Created: 2022-05-14T04:56:26.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-10T01:16:46.000Z (over 3 years ago)
- Last Synced: 2025-02-28T14:45:27.180Z (over 1 year ago)
- Topics: database, java, r2dbc, reactive, reactive-streams
- Language: Java
- Homepage:
- Size: 222 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reactive Relational Database Connectivity JDBC Implementation
[](https://mvnrepository.com/artifact/party.iroiro/r2dbc-jdbc)

[](./LICENSE)
[](https://github.com/gudzpoz/r2dbc-jdbc/actions/workflows/build.yml)
[](https://github.com/gudzpoz/r2dbc-jdbc/actions/workflows/test.yml)
[](https://app.codecov.io/gh/gudzpoz/r2dbc-jdbc)
This project contains a simplistic [Java Database Connectivity (JDBC)](https://docs.oracle.com/javase/8/docs/technotes/guides/jdbc/)
implementation of the [R2DBC SPI](https://github.com/r2dbc/r2dbc-spi). This implementation is not intended to be used directly,
but rather to be used as the backing implementation for a humane client library.
As for Spring Data, this library provides a `R2dbcDialectProvider`.
You may simply set `spring.r2dbc.url` accordingly in your `application.yml/properties`
and things should work out of the box.
It requires Java 9.
## Status
It is a toy project, and I promise there will be bugs.
## Wait, what?
```text
JDBC Connections Reactive
/|\ Access
| |
|------------| Input Jobs (SemiBlockingQueue) \|/
| The | <--------------------------- R2dbcConnections
| |
| worker(s) | ---------------------------> Dispatcher
|------------| (SemiBlockingQueue) |
Output |
\|/
Executing callbacks in Schedulers.parallel()
```
## Why?
[R2DBC H2](https://github.com/r2dbc/r2dbc-h2) is not *that* non-blocking. This library, as is shown in the above diagram,
actually simulates the regular TCP Client-Server connection to provider reactive access.
For *big* databases like MariaDB or PostgreSQL, you might as well go to [Drivers](https://r2dbc.io/drivers/) to find a
better SPI. However, if you want reactivity for some embedded databases like [H2](https://www.h2database.com),
[Derby](https://db.apache.org/derby/) or [HSQLDB](https://hsqldb.org/), maybe you can have a go with this.
## Usage
Just follow the guide on [R2DBC](https://r2dbc.io/).
### From Maven Central
[](https://mvnrepository.com/artifact/party.iroiro/r2dbc-jdbc)
Maven
Using directly?
```xml
party.iroiro
r2dbc-jdbc
0.3.1
```
Gradle
Using directly?
```groovy
implementation 'party.iroiro:r2dbc-jdbc:0.3.1'
```
### Use with Spring Data
Maven
```xml
org.springframework.boot
spring-boot-starter-data-r2dbc
party.iroiro
r2dbc-jdbc
0.3.1
runtime
```
Gradle
```groovy
implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
runtimeOnly 'party.iroiro:r2dbc-jdbc:0.3.1'
```
Spring Data requires a `R2dbcDialectProvider` to map repository operations to SQLs.
Since different databases may differ in SQL grammar, you may set one matching your database with,
for example:
```java
System.setProperty("j2dialect", "org.springframework.data.r2dbc.dialect.H2Dialect");
```
Currently, available dialects in Spring Data Reactive are:
- `org.springframework.data.r2dbc.dialect.H2Dialect`
- `org.springframework.data.r2dbc.dialect.PostgresDialect`
- `org.springframework.data.r2dbc.dialect.MySqlDialect`
- `org.springframework.data.r2dbc.dialect.OracleDialect`
- `org.springframework.data.r2dbc.dialect.SqlServerDialect`
### Passing JDBC urls
Note that you cannot pass a raw JDBC url directly. With R2DBC API, the call might look like this:
```java
import io.r2dbc.spi.ConnectionFactories;
class Main {
void test() {
// String
ConnectionFactories.get(
"r2dbc:r2jdbc:h2~mem:///test"
);
// ConnectionFactoryOptions is more friendly
ConnectionFactories.get(
ConnectionFactoryOptions.builder()
.option(ConnectionFactoryOptions.PROTOCOL, "r2dbc")
.option(ConnectionFactoryOptions.DATABASE, "r2jdbc")
.option(JdbcConnectionFactoryProvider.URL, "jdbc:h2:mem:test")
.build());
}
}
```
We accept some extra options. All are optional.
OptionExplained
`JdbcConnectionFactoryProvider.URL`
Example: `r2dbc:r2jdbc:h2:///?j2url=jdbc:h2:mem:test`
Used directly as JDBC url
Default: **Infer from R2DBC url**
`JdbcConnectionFactoryProvider.FORWARD`
Example: `r2dbc:r2jdbc:h2:///test?CIPHER=AES&j2forward=CIPHER`
What R2DBC options to forward to JDBC (comma separated).
Default: **None**
`JdbcConnectionFactoryProvider.CODEC`
Example: `r2dbc:r2jdbc:h2:///test?j2codec=party.iroiro.r2jdbc.codecs.DefaultCodec`
Name of a class converting JDBC types into regular Java types (used by the worker).
Default: **Built-in**
`JdbcConnectionFactoryProvider.CONV`
Example: `r2dbc:r2jdbc:h2:///test?j2conv=party.iroiro.r2jdbc.codecs.DefaultConverter`
Name of a class converting between Java types.
Default: **Built-in**
## License
I am borrowing tests from [R2DBC H2](https://github.com/r2dbc/r2dbc-h2), which is licensed under
[Apache License 2.0](https://github.com/r2dbc/r2dbc-h2/blob/main/LICENSE).
Licensed under the [Apache License Version 2.0](./LICENSE)