Skip to content

Commit 16f508c

Browse files
committed
Add ConnectionFactory option for binaryTransfer
[resolves #160]
1 parent 6b673e9 commit 16f508c

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Mono<Connection> connectionMono = Mono.from(connectionFactory.create());
7575
| `database` | Database to select. _(Optional)_
7676
| `applicationName` | The name of the application connecting to the database. Defaults to `r2dbc-postgresql`. _(Optional)_
7777
| `autodetectExtensions` | Whether to auto-detect and register `Extension`s from the class path. Defaults to `true`. _(Optional)_
78+
| `forceBinary` | Whether to force binary transfer. Defaults to `false`. _(Optional)_
7879
| `options` | A `Map<String, String>` of connection parameters. These are applied to each database connection created by the `ConnectionFactory`. Useful for setting generic [PostgreSQL connection parameters][psql-runtime-config]. _(Optional)_
7980
| `schema` | The schema to set. _(Optional)_
8081
| `sslMode` | SSL mode to use, see `SSLMode` enum. Supported values: `DISABLE`, `ALLOW`, `PREFER`, `REQUIRE`, `VERIFY_CA`, `VERIFY_FULL`. _(Optional)_

src/main/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProvider.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public final class PostgresqlConnectionFactoryProvider implements ConnectionFact
4949
*/
5050
public static final Option<Boolean> AUTODETECT_EXTENSIONS = Option.valueOf("autodetectExtensions");
5151

52+
/**
53+
* Force binary transfer.
54+
*/
55+
public static final Option<Boolean> FORCE_BINARY = Option.valueOf("forceBinary");
56+
5257
/**
5358
* Driver option value.
5459
*/
@@ -135,6 +140,12 @@ static PostgresqlConnectionConfiguration createConfiguration(ConnectionFactoryOp
135140
builder.port(port);
136141
}
137142

143+
Boolean forceBinary = connectionFactoryOptions.getValue(FORCE_BINARY);
144+
145+
if (forceBinary != null) {
146+
builder.forceBinary(forceBinary);
147+
}
148+
138149
Boolean ssl = connectionFactoryOptions.getValue(SSL);
139150
if (ssl != null && ssl) {
140151
builder.enableSsl();

src/test/java/io/r2dbc/postgresql/PostgresqlConnectionFactoryProviderTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626

2727
import static io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider.AUTODETECT_EXTENSIONS;
28+
import static io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider.FORCE_BINARY;
2829
import static io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider.LEGACY_POSTGRESQL_DRIVER;
2930
import static io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider.OPTIONS;
3031
import static io.r2dbc.postgresql.PostgresqlConnectionFactoryProvider.POSTGRESQL_DRIVER;
@@ -145,6 +146,19 @@ void shouldCreateConnectionFactoryWithoutPassword() {
145146
.build())).isNotNull();
146147
}
147148

149+
@Test
150+
void providerShouldConsiderBinaryTransfer() {
151+
PostgresqlConnectionFactory factory = this.provider.create(builder()
152+
.option(DRIVER, LEGACY_POSTGRESQL_DRIVER)
153+
.option(HOST, "test-host")
154+
.option(PASSWORD, "test-password")
155+
.option(USER, "test-user")
156+
.option(FORCE_BINARY, true)
157+
.build());
158+
159+
assertThat(factory.getConfiguration().isForceBinary()).isTrue();
160+
}
161+
148162
@Test
149163
void providerShouldParseAndHandleConnectionParameters() {
150164
Map<String, String> expectedOptions = new HashMap<>();

0 commit comments

Comments
 (0)