Skip to content

Commit 2affcea

Browse files
committed
Polishing
[resolves pgjdbc#56][resolves pgjdbc#66] Signed-off-by: Ben Hale <bhale@pivotal.io>
1 parent d5ede1d commit 2affcea

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public final class PostgresqlConnectionConfiguration {
3434

3535
private final String applicationName;
3636

37+
private final Duration connectTimeout;
38+
3739
private final String database;
3840

3941
private final String host;
@@ -46,18 +48,17 @@ public final class PostgresqlConnectionConfiguration {
4648

4749
private final String username;
4850

49-
private final Duration connectTimeout;
51+
private PostgresqlConnectionConfiguration(String applicationName, @Nullable Duration connectTimeout, @Nullable String database, String host, String password, int port, @Nullable String schema,
52+
String username) {
5053

51-
private PostgresqlConnectionConfiguration(String applicationName, @Nullable String database, String host, String password, int port, @Nullable String schema, String username,
52-
Duration connectTimeout) {
5354
this.applicationName = Assert.requireNonNull(applicationName, "applicationName must not be null");
55+
this.connectTimeout = connectTimeout;
5456
this.database = database;
5557
this.host = Assert.requireNonNull(host, "host must not be null");
5658
this.password = Assert.requireNonNull(password, "password must not be null");
5759
this.port = port;
5860
this.schema = schema;
5961
this.username = Assert.requireNonNull(username, "username must not be null");
60-
this.connectTimeout = connectTimeout;
6162
}
6263

6364
/**
@@ -71,22 +72,27 @@ public static Builder builder() {
7172

7273
@Override
7374
public String toString() {
74-
return "PostgresConnectionConfiguration{" +
75+
return "PostgresqlConnectionConfiguration{" +
7576
"applicationName='" + this.applicationName + '\'' +
77+
", connectTimeout=" + this.connectTimeout +
7678
", database='" + this.database + '\'' +
7779
", host='" + this.host + '\'' +
7880
", password='" + this.password + '\'' +
7981
", port=" + this.port +
8082
", schema='" + this.schema + '\'' +
8183
", username='" + this.username + '\'' +
82-
", connectTimeout='" + this.connectTimeout + '\'' +
8384
'}';
8485
}
8586

8687
String getApplicationName() {
8788
return this.applicationName;
8889
}
8990

91+
@Nullable
92+
Duration getConnectTimeout() {
93+
return this.connectTimeout;
94+
}
95+
9096
@Nullable
9197
String getDatabase() {
9298
return this.database;
@@ -113,11 +119,6 @@ String getUsername() {
113119
return this.username;
114120
}
115121

116-
@Nullable
117-
Duration getConnectTimeout() {
118-
return this.connectTimeout;
119-
}
120-
121122
/**
122123
* A builder for {@link PostgresqlConnectionConfiguration} instances.
123124
* <p>
@@ -127,6 +128,8 @@ public static final class Builder {
127128

128129
private String applicationName = "r2dbc-postgresql";
129130

131+
private Duration connectTimeout;
132+
130133
private String database;
131134

132135
private String host;
@@ -139,8 +142,6 @@ public static final class Builder {
139142

140143
private String username;
141144

142-
private Duration connectTimeout;
143-
144145
private Builder() {
145146
}
146147

@@ -162,7 +163,12 @@ public Builder applicationName(String applicationName) {
162163
* @return a configured {@link PostgresqlConnectionConfiguration}
163164
*/
164165
public PostgresqlConnectionConfiguration build() {
165-
return new PostgresqlConnectionConfiguration(this.applicationName, this.database, this.host, this.password, this.port, this.schema, this.username, this.connectTimeout);
166+
return new PostgresqlConnectionConfiguration(this.applicationName, this.connectTimeout, this.database, this.host, this.password, this.port, this.schema, this.username);
167+
}
168+
169+
public Builder connectTimeout(@Nullable Duration connectTimeout) {
170+
this.connectTimeout = connectTimeout;
171+
return this;
166172
}
167173

168174
/**
@@ -222,22 +228,17 @@ public Builder schema(@Nullable String schema) {
222228
return this;
223229
}
224230

225-
public Builder connectTimeout(@Nullable Duration connectTimeout) {
226-
this.connectTimeout = connectTimeout;
227-
return this;
228-
}
229-
230231
@Override
231232
public String toString() {
232233
return "Builder{" +
233234
"applicationName='" + this.applicationName + '\'' +
235+
", connectTimeout='" + this.connectTimeout + '\'' +
234236
", database='" + this.database + '\'' +
235237
", host='" + this.host + '\'' +
236238
", password='" + this.password + '\'' +
237239
", port=" + this.port +
238240
", schema='" + this.schema + '\'' +
239241
", username='" + this.username + '\'' +
240-
", connectTimeout='" + this.connectTimeout + '\'' +
241242
'}';
242243
}
243244

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ public PostgresqlConnectionFactory create(ConnectionFactoryOptions connectionFac
5959
builder.applicationName(applicationName);
6060
}
6161

62+
builder.connectTimeout(connectionFactoryOptions.getValue(CONNECT_TIMEOUT));
6263
builder.database(connectionFactoryOptions.getValue(DATABASE));
6364
builder.host(connectionFactoryOptions.getRequiredValue(HOST));
6465
builder.password(connectionFactoryOptions.getRequiredValue(PASSWORD).toString());
6566
builder.port(connectionFactoryOptions.getRequiredValue(PORT));
6667
builder.schema(connectionFactoryOptions.getValue(SCHEMA));
6768
builder.username(connectionFactoryOptions.getRequiredValue(USER));
68-
builder.connectTimeout(connectionFactoryOptions.getValue(CONNECT_TIMEOUT));
6969

7070
return new PostgresqlConnectionFactory(builder.build());
7171
}

src/main/java/io/r2dbc/postgresql/client/ReactorNettyClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ public static Mono<ReactorNettyClient> connect(String host, int port, @Nullable
197197
* @param connectTimeout connect timeout
198198
* @throws IllegalArgumentException if {@code host} is {@code null}
199199
*/
200-
// TODO deal with growing argument list
201200
public static Mono<ReactorNettyClient> connect(ConnectionProvider connectionProvider, String host, int port, @Nullable Duration connectTimeout) {
202201
Assert.requireNonNull(connectionProvider, "connectionProvider must not be null");
203202
Assert.requireNonNull(host, "host must not be null");
204203

205204
TcpClient tcpClient = TcpClient.create(connectionProvider)
206205
.host(host).port(port);
206+
207207
if (connectTimeout != null) {
208208
tcpClient = tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(connectTimeout.toMillis()));
209209
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,24 @@ void builderNoUsername() {
5353
void configuration() {
5454
PostgresqlConnectionConfiguration configuration = PostgresqlConnectionConfiguration.builder()
5555
.applicationName("test-application-name")
56+
.connectTimeout(Duration.ofMillis(1000))
5657
.database("test-database")
5758
.host("test-host")
5859
.password("test-password")
5960
.port(100)
6061
.schema("test-schema")
6162
.username("test-username")
62-
.connectTimeout(Duration.ofMillis(1000))
6363
.build();
6464

6565
assertThat(configuration)
6666
.hasFieldOrPropertyWithValue("applicationName", "test-application-name")
67+
.hasFieldOrPropertyWithValue("connectTimeout", Duration.ofMillis(1000))
6768
.hasFieldOrPropertyWithValue("database", "test-database")
6869
.hasFieldOrPropertyWithValue("host", "test-host")
6970
.hasFieldOrPropertyWithValue("password", "test-password")
7071
.hasFieldOrPropertyWithValue("port", 100)
7172
.hasFieldOrPropertyWithValue("schema", "test-schema")
72-
.hasFieldOrPropertyWithValue("username", "test-username")
73-
.hasFieldOrPropertyWithValue("connectTimeout", Duration.ofMillis(1000));
73+
.hasFieldOrPropertyWithValue("username", "test-username");
7474
}
7575

7676
@Test

0 commit comments

Comments
 (0)