Skip to content

Commit 5f228c6

Browse files
committed
Polishing
Consistent param/return/throws formatting. Add since tags to types introduced after the initial release. Consistent method naming.
1 parent 39fe894 commit 5f228c6

35 files changed

+215
-117
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ private Extensions(List<Extension> extensions) {
4444
/**
4545
* Create a new {@link Extensions} object.
4646
*
47-
* @param extensions the extensions to hold.
48-
* @return a new {@link Extensions} object.
47+
* @param extensions the extensions to hold
48+
* @return a new {@link Extensions} object
4949
*/
5050
static Extensions from(Collection<Extension> extensions) {
5151
return new Extensions(new ArrayList<>(extensions));
@@ -54,7 +54,7 @@ static Extensions from(Collection<Extension> extensions) {
5454
/**
5555
* Autodetect extensions using {@link ServiceLoader} mechanism.
5656
*
57-
* @return the detected {@link Extension}s.
57+
* @return the detected {@link Extension}s
5858
*/
5959
static Extensions autodetect() {
6060
logger.debug("Discovering Extensions using ServiceLoader");
@@ -93,8 +93,8 @@ <T extends Extension> void forEach(Class<T> extensionType, Consumer<T> consumer)
9393
/**
9494
* Create a new {@link Extensions} object that contains all extensions from this and {@code other}.
9595
*
96-
* @param other the additional {@link Extensions} to add.
97-
* @return a new {@link Extensions} object that contains all extensions from this and {@code other}.
96+
* @param other the additional {@link Extensions} to add
97+
* @return a new {@link Extensions} object that contains all extensions from this and {@code other}
9898
*/
9999
Extensions mergeWith(Extensions other) {
100100
List<Extension> extensions = new ArrayList<>(size() + other.size());
@@ -106,7 +106,7 @@ Extensions mergeWith(Extensions other) {
106106
/**
107107
* Returns the number of {@link Extension}s.
108108
*
109-
* @return the number of {@link Extension}s.
109+
* @return the number of {@link Extension}s
110110
*/
111111
public int size() {
112112
return this.extensions.size();

src/main/java/io/r2dbc/postgresql/api/Notification.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface Notification {
2626
/**
2727
* Returns name of this notification.
2828
*
29-
* @return name of this notification.
29+
* @return name of this notification
3030
*/
3131
String getName();
3232

src/main/java/io/r2dbc/postgresql/api/PostgresqlConnection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public interface PostgresqlConnection extends Connection {
7171
* connection are published as they are received. When the client gets {@link #close() closed}, the subscription {@link Subscriber#onComplete() completes normally}. Otherwise (transport
7272
* connection disconnected unintentionally) with an {@link R2dbcNonTransientResourceException error}.
7373
*
74-
* @return a hot {@link Flux} of {@link Notification Notifications}.
74+
* @return a hot {@link Flux} of {@link Notification Notifications}
7575
*/
7676
Flux<Notification> getNotifications();
7777

src/main/java/io/r2dbc/postgresql/api/PostgresqlException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public interface PostgresqlException {
2828
/**
2929
* Returns additional error information.
3030
*
31-
* @return the {@link ErrorDetails}.
31+
* @return the {@link ErrorDetails}
3232
*/
3333
ErrorDetails getErrorDetails();
3434

src/main/java/io/r2dbc/postgresql/api/PostgresqlReplicationConnection.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ public interface PostgresqlReplicationConnection extends Closeable {
3737
/**
3838
* Create a replication slot for logical or physical replication.
3939
*
40-
* @param request description of the slot to create.
41-
* @return {@link Mono} emitting {@link ReplicationSlot} information once the slot was created.
40+
* @param request description of the slot to create
41+
* @return {@link Mono} emitting {@link ReplicationSlot} information once the slot was created
4242
*/
4343
Mono<ReplicationSlot> createSlot(ReplicationSlotRequest request);
4444

4545
/**
4646
* Starts the {@link ReplicationStream} for logical or physical replication.
4747
* After starting the replication stream this connection becomes unavailable for slot creation and other streams unless the {@link ReplicationStream} is {@link ReplicationStream#close() closed}.
4848
*
49-
* @param request description of the replication stream to create.
50-
* @return {@link Mono} emitting {@link ReplicationStream} once the replication was started.
49+
* @param request description of the replication stream to create
50+
* @return {@link Mono} emitting {@link ReplicationStream} once the replication was started
5151
*/
5252
Mono<ReplicationStream> startReplication(ReplicationRequest request);
5353

5454
/**
5555
* Returns the {@link PostgresqlConnectionMetadata} for this connection.
5656
*
57-
* @return the {@link PostgresqlConnectionMetadata} for this connection.
57+
* @return the {@link PostgresqlConnectionMetadata} for this connection
5858
*/
5959
PostgresqlConnectionMetadata getMetadata();
6060

src/main/java/io/r2dbc/postgresql/api/PostgresqlStatement.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface PostgresqlStatement extends Statement {
3333
/**
3434
* {@inheritDoc}
3535
*
36-
* @throws IllegalArgumentException if {@code identifier} is not a {@link String} like {@code $1}, {@code $2}, etc.
36+
* @throws IllegalArgumentException if {@code identifier} is not a {@link String} like {@code $1}, {@code $2},
3737
*/
3838
@Override
3939
PostgresqlStatement bind(String identifier, Object value);
@@ -47,7 +47,7 @@ public interface PostgresqlStatement extends Statement {
4747
/**
4848
* {@inheritDoc}
4949
*
50-
* @throws IllegalArgumentException if {@code identifier} is not a {@link String} like {@code $1}, {@code $2}, etc.
50+
* @throws IllegalArgumentException if {@code identifier} is not a {@link String} like {@code $1}, {@code $2},
5151
*/
5252
@Override
5353
PostgresqlStatement bindNull(String identifier, Class<?> type);
@@ -75,7 +75,7 @@ default PostgresqlStatement fetchSize(int rows) {
7575
/**
7676
* {@inheritDoc}
7777
*
78-
* @throws IllegalStateException if this {@link Statement} already has a {@code RETURNING clause} or isn't a {@code DELETE}, {@code INSERT}, or {@code UPDATE} command.
78+
* @throws IllegalStateException if this {@link Statement} already has a {@code RETURNING clause} or isn't a {@code DELETE}, {@code INSERT}, or {@code UPDATE} command
7979
*/
8080
@Override
8181
PostgresqlStatement returnGeneratedValues(String... columns);

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public interface Client {
4343
* disconnects are not visible to the {@link Consumer notification consumer}.
4444
*
4545
* @param consumer the consumer of notification messages
46-
* @return a new {@link Disposable} that can be used to cancel the underlying subscription.
46+
* @return a new {@link Disposable} that can be used to cancel the underlying subscription
4747
* @throws IllegalArgumentException if {@code consumer} is {@code null}
4848
*/
4949
Disposable addNotificationListener(Consumer<NotificationResponse> consumer);
@@ -53,7 +53,7 @@ public interface Client {
5353
* subscription {@link Subscriber#onComplete() completes normally}. Otherwise (transport connection disconnected unintentionally) with an {@link R2dbcNonTransientResourceException error}.
5454
*
5555
* @param consumer the consumer of notification messages
56-
* @return a new {@link Disposable} that can be used to cancel the underlying subscription.
56+
* @return a new {@link Disposable} that can be used to cancel the underlying subscription
5757
* @throws IllegalArgumentException if {@code consumer} is {@code null}
5858
* @since 0.8.1
5959
*/
@@ -70,7 +70,7 @@ public interface Client {
7070
* Perform an exchange of messages. Note that the {@link ReadyForQuery} frame is not emitted through the resulting {@link Flux}.
7171
*
7272
* @param requests the publisher of outbound messages
73-
* @return a {@link Flux} of incoming messages that ends with the end of conversation (i.e. reception of a {@link ReadyForQuery} message. Th
73+
* @return a {@link Flux} of incoming messages that ends with the end of conversation (i.e. reception of a {@link ReadyForQuery} message
7474
* @throws IllegalArgumentException if {@code requests} is {@code null}
7575
*/
7676
default Flux<BackendMessage> exchange(Publisher<FrontendMessage> requests) {
@@ -83,7 +83,7 @@ default Flux<BackendMessage> exchange(Publisher<FrontendMessage> requests) {
8383
* @param takeUntil the predicate that signals the resulting {@link Flux} to terminate. Typically a check if the {@link BackendMessage} is the last frame of a conversation. Note that the
8484
* {@link BackendMessage} that matches the predicate is not emitted through the resulting {@link Flux}.
8585
* @param requests the publisher of outbound messages
86-
* @return a {@link Flux} of incoming messages that ends with the end of conversation matching {@code takeUntil}. (i.e. reception of a {@link ReadyForQuery} message.
86+
* @return a {@link Flux} of incoming messages that ends with the end of conversation matching {@code takeUntil}. (i.e. reception of a {@link ReadyForQuery} message
8787
* @throws IllegalArgumentException if {@code requests} is {@code null}
8888
* @since 0.9
8989
*/
@@ -129,14 +129,14 @@ default Flux<BackendMessage> exchange(Publisher<FrontendMessage> requests) {
129129
/**
130130
* Return the server version.
131131
*
132-
* @return the server version from {@code server_version}/{@code server_version_num} startup parameters.
132+
* @return the server version from {@code server_version}/{@code server_version_num} startup parameters
133133
*/
134134
Version getVersion();
135135

136136
/**
137137
* Returns whether the client is connected to a server.
138138
*
139-
* @return {@literal true} if the client is connected to a server.
139+
* @return {@code true} if the client is connected to a server
140140
*/
141141
boolean isConnected();
142142

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ private static boolean isSslException(Throwable throwable) {
248248
}
249249

250250
/**
251-
* Consume a {@link BackendMessage}. This method can either fully consume the message or it can signal by returning {@literal false} that the method wasn't able to fully consume the message and
251+
* Consume a {@link BackendMessage}. This method can either fully consume the message or it can signal by returning {@code false} that the method wasn't able to fully consume the message and
252252
* that the message needs to be passed to an active {@link Conversation}.
253253
*
254254
* @param message the {@link BackendMessage} to handle
255-
* @return {@literal false} if the message could not be fully consumed and should be propagated to the active {@link Conversation}
255+
* @return {@code false} if the message could not be fully consumed and should be propagated to the active {@link Conversation}
256256
*/
257257
private boolean consumeMessage(BackendMessage message) {
258258

src/main/java/io/r2dbc/postgresql/codec/AbstractArrayCodec.java

+42-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Abstract codec class that provides a basis for all concrete
3838
* implementations of a array-typed {@link Codec}.
3939
*
40-
* @param <T> the type that is handled by this {@link Codec}.
40+
* @param <T> the type that is handled by this {@link Codec}
4141
*/
4242
abstract class AbstractArrayCodec<T> extends AbstractCodec<Object[]> {
4343

@@ -94,10 +94,6 @@ static String escapeArrayElement(String s) {
9494
return b.toString();
9595
}
9696

97-
abstract T decodeItem(ByteBuf byteBuf);
98-
99-
abstract T decodeItem(String strValue);
100-
10197
@Override
10298
final Object[] doDecode(ByteBuf buffer, PostgresqlObjectId dataType, Format format, Class<? extends Object[]> type) {
10399
Assert.requireNonNull(buffer, "byteBuf must not be null");
@@ -111,20 +107,48 @@ final Object[] doDecode(ByteBuf buffer, PostgresqlObjectId dataType, Format form
111107
}
112108
}
113109

110+
/**
111+
* Decode value using binary format.
112+
*
113+
* @param byteBuffer buffer containing the binary representation of the value to decode
114+
* @return decoded value
115+
*/
116+
abstract T doDecodeBinary(ByteBuf byteBuffer);
117+
118+
/**
119+
* Decode value using text format.
120+
*
121+
* @param text string containing the textual representation of the value to decode
122+
* @return decoded value
123+
*/
124+
abstract T doDecodeText(String text);
125+
114126
@Override
115127
final Parameter doEncode(Object[] value) {
116128
Assert.requireNonNull(value, "value must not be null");
117129

118130
return encodeArray(() -> {
119131
ByteBuf byteBuf = this.byteBufAllocator.buffer();
120-
encodeAsText(byteBuf, value, this::encodeItem);
132+
encodeAsText(byteBuf, value, this::doEncodeText);
121133
return byteBuf;
122134
});
123135
}
124136

137+
/**
138+
* Create the encoded array representation.
139+
*
140+
* @param encodedSupplier supplies the
141+
* @return encoded {@link Parameter} item
142+
*/
125143
abstract Parameter encodeArray(Supplier<ByteBuf> encodedSupplier);
126144

127-
abstract String encodeItem(T value);
145+
/**
146+
* Encode a single array item using text format.
147+
*
148+
* @param value the value to encode
149+
* @return encoded array item
150+
*/
151+
abstract String doEncodeText(T value);
128152

129153
boolean isTypeAssignable(Class<?> type) {
130154
Assert.requireNonNull(type, "type must not be null");
@@ -148,18 +172,22 @@ private static int getDimensions(List<?> list) {
148172
Object inner = list.get(0);
149173

150174
while (inner instanceof List) {
151-
inner = ((List) inner).get(0);
175+
inner = ((List<?>) inner).get(0);
152176
dims++;
153177
}
154178

155179
return dims;
156180
}
157181

158182
private static Object[] toArray(List<?> list, Class<?> returnType) {
159-
return list
160-
.stream()
161-
.map(e -> (e instanceof List ? toArray((List) e, returnType.getComponentType()) : e))
162-
.toArray(r -> (Object[]) Array.newInstance(returnType, list.size()));
183+
List<Object> result = new ArrayList<>(list.size());
184+
185+
for (Object e : list) {
186+
Object o = (e instanceof List ? toArray((List<?>) e, returnType.getComponentType()) : e);
187+
result.add(o);
188+
}
189+
190+
return result.toArray((Object[]) Array.newInstance(returnType, list.size()));
163191
}
164192

165193
private List<Object> buildArrayList(ByteBuf buf) {
@@ -245,7 +273,7 @@ private List<Object> buildArrayList(ByteBuf buf) {
245273

246274
// add element to current array
247275
if (b != null && (!b.isEmpty() || wasInsideString)) {
248-
curArray.add(!wasInsideString && b.equals("NULL") ? null : decodeItem(b));
276+
curArray.add(!wasInsideString && b.equals("NULL") ? null : doDecodeText(b));
249277
}
250278

251279
wasInsideString = false;
@@ -352,7 +380,7 @@ private void readArrayAsBinary(ByteBuf buffer, Object[] array, int[] dims, int t
352380
continue;
353381

354382
}
355-
array[i] = decodeItem(buffer.readSlice(len));
383+
array[i] = doDecodeBinary(buffer.readSlice(len));
356384
}
357385
} else {
358386
for (int i = 0; i < dims[thisDimension]; ++i) {

src/main/java/io/r2dbc/postgresql/codec/AbstractBinaryCodec.java

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
import static io.r2dbc.postgresql.message.Format.FORMAT_TEXT;
3434
import static io.r2dbc.postgresql.type.PostgresqlObjectId.BYTEA;
3535

36+
/**
37+
* Support class for codecs that read/write {@code BYTEA} values.
38+
*
39+
* @param <T> the type that is handled by this {@link Codec}
40+
*/
3641
abstract class AbstractBinaryCodec<T> extends AbstractCodec<T> {
3742

3843
private static final Pattern BLOB_PATTERN = Pattern.compile("\\\\x([\\p{XDigit}]+)?");

src/main/java/io/r2dbc/postgresql/codec/AbstractCodec.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* Abstract codec class that provides a basis for all concrete
3535
* implementations of a {@link Codec} for well-known {@link PostgresqlObjectId}.
3636
*
37-
* @param <T> the type that is handled by this {@link Codec}.
37+
* @param <T> the type that is handled by this {@link Codec}
3838
*/
3939
abstract class AbstractCodec<T> implements Codec<T> {
4040

@@ -100,9 +100,10 @@ public Class<?> type() {
100100
*
101101
* @param type the well-known {@link PostgresqlObjectId type OID}
102102
* @param format the format to use
103-
* @param value {@link Publisher} emitting {@link ByteBuf buffers}. Make sure to use deferred buffer creation instead of {@link Mono#just(Object)} and {@link Flux#just(Object)} to avoid memory
104-
* leaks
103+
* @param value {@link Publisher} emitting {@link ByteBuf buffers}
105104
* @return the encoded {@link Parameter}
105+
* @implNote use deferred buffer creation instead of {@link Mono#just(Object)} and {@link Flux#just(Object)} to avoid memory
106+
* leaks
106107
*/
107108
static Parameter create(PostgresqlObjectId type, Format format, Publisher<? extends ByteBuf> value) {
108109
return new Parameter(format, type.getObjectId(), value);
@@ -125,7 +126,7 @@ static Parameter create(PostgresqlObjectId type, Format format, Supplier<? exten
125126
*
126127
* @param type the well-known {@link PostgresqlObjectId type OID}
127128
* @param format the data type {@link Format}, text or binary
128-
* @return the encoded {@code null} value.
129+
* @return the encoded {@code null} value
129130
*/
130131
static Parameter createNull(PostgresqlObjectId type, Format format) {
131132
return create(type, format, NULL_VALUE);
@@ -136,7 +137,7 @@ static Parameter createNull(PostgresqlObjectId type, Format format) {
136137
*
137138
* @param type the well-known {@link PostgresqlObjectId type OID}
138139
* @param format the data type {@link Format}, text or binary
139-
* @return {@code true} if this codec is able to decode values of {@link Format} and {@link PostgresqlObjectId}.
140+
* @return {@code true} if this codec is able to decode values of {@link Format} and {@link PostgresqlObjectId}
140141
*/
141142
abstract boolean doCanDecode(PostgresqlObjectId type, Format format);
142143

@@ -146,14 +147,14 @@ static Parameter createNull(PostgresqlObjectId type, Format format) {
146147
* @param buffer the data buffer
147148
* @param dataType the well-known {@link PostgresqlObjectId type OID}
148149
* @param format data type format
149-
* @param type the desired value type.
150-
* @return the decoded value. Can be {@code null} if the column value is {@code null}.
150+
* @param type the desired value type
151+
* @return the decoded value, can be {@code null} if the column value is {@code null}
151152
*/
152153
abstract T doDecode(ByteBuf buffer, PostgresqlObjectId dataType, Format format, Class<? extends T> type);
153154

154155
/**
155-
* @param value the {@code value}.
156-
* @return the encoded value.
156+
* @param value the {@code value}
157+
* @return the encoded value
157158
*/
158159
abstract Parameter doEncode(T value);
159160

0 commit comments

Comments
 (0)