Skip to content

Commit 84a5ef7

Browse files
committed
Polishing
Simplify switch. Update documentation. Reformat code. [#199]
1 parent dfc0fde commit 84a5ef7

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,15 @@ This reference table shows the type mapping between [PostgreSQL][p] and Java dat
301301
| [`inet`][psql-inet-ref] | [**`InetAddress`**][java-inet-ref]|
302302
| [`integer`][psql-integer-ref] | [**`Integer`**][java-integer-ref], [`Boolean`][java-boolean-ref], [`Byte`][java-byte-ref], [`Short`][java-short-ref], [`Long`][java-long-ref], [`BigDecimal`][java-bigdecimal-ref]|
303303
| [`interval`][psql-interval-ref] | Not yet supported.|
304-
| [`json`][psql-json-ref] | **`Json`**, [`String`][java-string-ref]. Reading: [`ByteBuf`][`byte[]`][java-primitive-ref][`ByteBuffer`][java-ByteBuffer-ref][`String`][java-string-ref][`InputStream`][java-inputstream-ref]|
305-
| [`jsonb`][psql-json-ref] | **`Json`**, [`String`][java-string-ref]. Reading: [`ByteBuf`][`byte[]`][java-primitive-ref][`ByteBuffer`][java-ByteBuffer-ref][`String`][java-string-ref][`InputStream`][java-inputstream-ref]|
304+
| [`json`][psql-json-ref] | **`Json`**, [`String`][java-string-ref]. Reading: `ByteBuf`[`byte[]`][java-primitive-ref], [`ByteBuffer`][java-ByteBuffer-ref], [`String`][java-string-ref], [`InputStream`][java-inputstream-ref]|
305+
| [`jsonb`][psql-json-ref] | **`Json`**, [`String`][java-string-ref]. Reading: `ByteBuf`[`byte[]`][java-primitive-ref], [`ByteBuffer`][java-ByteBuffer-ref], [`String`][java-string-ref], [`InputStream`][java-inputstream-ref]|
306306
| [`line`][psql-line-ref] | Not yet supported.|
307307
| [`lseg`][psql-lseq-ref] | Not yet supported.|
308308
| [`macaddr`][psql-macaddr-ref] | Not yet supported.|
309309
| [`macaddr8`][psql-macaddr8-ref] | Not yet supported.|
310310
| [`money`][psql-money-ref] | Not yet supported.|
311311
| [`numeric`][psql-bignumeric-ref] | [`BigDecimal`][java-bigdecimal-ref], [`Boolean`][java-boolean-ref], [`Byte`][java-byte-ref], [`Short`][java-short-ref], [`Integer`][java-integer-ref], [`Long`][java-long-ref]|
312+
| [`oid`][psql-oid-ref] | [**`Integer`**][java-integer-ref], [`Boolean`][java-boolean-ref], [`Byte`][java-byte-ref], [`Short`][java-short-ref], [`Long`][java-long-ref], [`BigDecimal`][java-bigdecimal-ref]|
312313
| [`path`][psql-path-ref] | Not yet supported.|
313314
| [`pg_lsn`][psql-pg_lsn-ref] | Not yet supported.|
314315
| [`point`][psql-point-ref] | Not yet supported.|
@@ -358,6 +359,7 @@ Support for the following single-dimensional arrays (read and write):
358359
[psql-macaddr-ref]: https://www.postgresql.org/docs/11/datatype-net-types.html#DATATYPE-MACADDR
359360
[psql-macaddr8-ref]: https://www.postgresql.org/docs/11/datatype-net-types.html#DATATYPE-MACADDR8
360361
[psql-money-ref]: https://www.postgresql.org/docs/11/datatype.html
362+
[psql-oid-ref]: https://www.postgresql.org/docs/11/datatype-oid.html
361363
[psql-path-ref]: https://www.postgresql.org/docs/11/datatype-geometric.html#id-1.5.7.16.9
362364
[psql-pg_lsn-ref]: https://www.postgresql.org/docs/11/datatype-pg-lsn.html
363365
[psql-point-ref]: https://www.postgresql.org/docs/11/datatype-geometric.html#id-1.5.7.16.5

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public Class<?> type() {
9898
/**
9999
* Create a {@link Parameter}.
100100
*
101-
* @param type the type OID
101+
* @param type the well-known {@link PostgresqlObjectId type OID}
102102
* @param format the format to use
103103
* @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
104104
* leaks
@@ -111,7 +111,7 @@ static Parameter create(PostgresqlObjectId type, Format format, Publisher<? exte
111111
/**
112112
* Create a {@link Parameter}.
113113
*
114-
* @param type the type OID
114+
* @param type the well-known {@link PostgresqlObjectId type OID}
115115
* @param format the format to use
116116
* @param bufferSupplier {@link Supplier} supplying the encoded {@link ByteBuf buffer}
117117
* @return the encoded {@link Parameter}
@@ -123,7 +123,7 @@ static Parameter create(PostgresqlObjectId type, Format format, Supplier<? exten
123123
/**
124124
* Encode a {@code null} value.
125125
*
126-
* @param type
126+
* @param type the well-known {@link PostgresqlObjectId type OID}
127127
* @param format the data type {@link Format}, text or binary
128128
* @return the encoded {@code null} value.
129129
*/
@@ -134,7 +134,7 @@ static Parameter createNull(PostgresqlObjectId type, Format format) {
134134
/**
135135
* Determine whether this {@link Codec} is capable of decoding column values based on the given {@link Format} and {@link PostgresqlObjectId}.
136136
*
137-
* @param type
137+
* @param type the well-known {@link PostgresqlObjectId type OID}
138138
* @param format the data type {@link Format}, text or binary
139139
* @return {@code true} if this codec is able to decode values of {@link Format} and {@link PostgresqlObjectId}.
140140
*/
@@ -144,7 +144,7 @@ static Parameter createNull(PostgresqlObjectId type, Format format) {
144144
* Decode the {@link ByteBuf data} into the {@link Class value type}.
145145
*
146146
* @param buffer the data buffer
147-
* @param dataType the data type
147+
* @param dataType the well-known {@link PostgresqlObjectId type OID}
148148
* @param format data type format
149149
* @param type the desired value type.
150150
* @return the decoded value. Can be {@code null} if the column value is {@code null}.

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import static io.r2dbc.postgresql.type.PostgresqlObjectId.INT4;
3636
import static io.r2dbc.postgresql.type.PostgresqlObjectId.INT8;
3737
import static io.r2dbc.postgresql.type.PostgresqlObjectId.NUMERIC;
38-
import static io.r2dbc.postgresql.type.PostgresqlObjectId.OID;;
38+
import static io.r2dbc.postgresql.type.PostgresqlObjectId.OID;
3939

4040
/**
4141
* Codec to decode all known numeric types.
@@ -78,12 +78,12 @@ boolean doCanDecode(PostgresqlObjectId type, Format format) {
7878
/**
7979
* Decode {@code buffer} to {@link Number} and potentially convert it to {@link Class expectedType} using {@link Function converter} if the decoded type does not match {@code expectedType}.
8080
*
81-
* @param buffer
82-
* @param dataType
83-
* @param format
84-
* @param expectedType
85-
* @param converter
86-
* @return
81+
* @param buffer the data buffer
82+
* @param dataType the well-known {@link PostgresqlObjectId type OID}
83+
* @param format the data type {@link Format}, text or binary
84+
* @param expectedType the expected result type
85+
* @param converter the converter function to convert from {@link Number} to {@code expectedType}
86+
* @return the decoded number
8787
*/
8888
T decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format format, Class<T> expectedType, Function<Number, T> converter) {
8989
Number number = decodeNumber(buffer, dataType, format);
@@ -93,10 +93,10 @@ T decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format for
9393
/**
9494
* Decode {@code buffer} to {@link Number} according to {@link PostgresqlObjectId}.
9595
*
96-
* @param buffer
97-
* @param dataType
98-
* @param format
99-
* @return
96+
* @param buffer the data buffer
97+
* @param dataType the well-known {@link PostgresqlObjectId type OID}
98+
* @param format the data type {@link Format}, text or binary
99+
* @return the decoded number
100100
*/
101101
private Number decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format format) {
102102
Assert.requireNonNull(buffer, "byteBuf must not be null");
@@ -115,6 +115,7 @@ private Number decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullab
115115
}
116116
return Short.parseShort(ByteBufUtils.decode(buffer));
117117
case INT4:
118+
case OID:
118119
if (FORMAT_BINARY == format) {
119120
return buffer.readInt();
120121
}
@@ -134,11 +135,6 @@ private Number decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullab
134135
return buffer.readDouble();
135136
}
136137
return Double.parseDouble(ByteBufUtils.decode(buffer));
137-
case OID:
138-
if (FORMAT_BINARY == format) {
139-
return buffer.readInt();
140-
}
141-
return Integer.parseInt(ByteBufUtils.decode(buffer));
142138
default:
143139
throw new UnsupportedOperationException(String.format("Cannot decode value for type %s, format %s", dataType, format));
144140
}

0 commit comments

Comments
 (0)