Skip to content

Commit a387b3d

Browse files
committed
Merge branch 'stackbuilders-add-oid-to-supported-numerics'
[#199]
2 parents 9a1b9ab + 84a5ef7 commit a387b3d

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
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: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +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;
3839

3940
/**
4041
* Codec to decode all known numeric types.
@@ -43,7 +44,7 @@
4344
*/
4445
abstract class AbstractNumericCodec<T extends Number> extends AbstractCodec<T> {
4546

46-
private static final Set<PostgresqlObjectId> SUPPORTED_TYPES = EnumSet.of(INT2, INT4, INT8, FLOAT4, FLOAT8, NUMERIC);
47+
private static final Set<PostgresqlObjectId> SUPPORTED_TYPES = EnumSet.of(INT2, INT4, INT8, FLOAT4, FLOAT8, NUMERIC, OID);
4748

4849
/**
4950
* Creates a new {@link AbstractCodec}.
@@ -77,12 +78,12 @@ boolean doCanDecode(PostgresqlObjectId type, Format format) {
7778
/**
7879
* 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}.
7980
*
80-
* @param buffer
81-
* @param dataType
82-
* @param format
83-
* @param expectedType
84-
* @param converter
85-
* @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
8687
*/
8788
T decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format format, Class<T> expectedType, Function<Number, T> converter) {
8889
Number number = decodeNumber(buffer, dataType, format);
@@ -92,10 +93,10 @@ T decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format for
9293
/**
9394
* Decode {@code buffer} to {@link Number} according to {@link PostgresqlObjectId}.
9495
*
95-
* @param buffer
96-
* @param dataType
97-
* @param format
98-
* @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
99100
*/
100101
private Number decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullable Format format) {
101102
Assert.requireNonNull(buffer, "byteBuf must not be null");
@@ -114,6 +115,7 @@ private Number decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullab
114115
}
115116
return Short.parseShort(ByteBufUtils.decode(buffer));
116117
case INT4:
118+
case OID:
117119
if (FORMAT_BINARY == format) {
118120
return buffer.readInt();
119121
}
@@ -133,9 +135,9 @@ private Number decodeNumber(ByteBuf buffer, PostgresqlObjectId dataType, @Nullab
133135
return buffer.readDouble();
134136
}
135137
return Double.parseDouble(ByteBufUtils.decode(buffer));
138+
default:
139+
throw new UnsupportedOperationException(String.format("Cannot decode value for type %s, format %s", dataType, format));
136140
}
137-
138-
throw new UnsupportedOperationException(String.format("Cannot decode value for type %s, format %s", dataType, format));
139141
}
140142

141143
/**

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ void intPrimitive() {
193193
testCodec(Integer.class, 100, "INT2");
194194
testCodec(Integer.class, 100, "INT4");
195195
testCodec(Integer.class, 100, "INT8");
196+
testCodec(Integer.class, 100, "OID");
196197
testCodec(Integer.class, 100, "NUMERIC");
197198
testCodec(Integer.class, 100, "FLOAT4");
198199
testCodec(Integer.class, 100, "FLOAT8");
@@ -289,6 +290,7 @@ void longPrimitive() {
289290
testCodec(Long.class, 100L, "INT2");
290291
testCodec(Long.class, 100L, "INT4");
291292
testCodec(Long.class, 100L, "INT8");
293+
testCodec(Long.class, 100L, "OID");
292294
testCodec(Long.class, 100L, "NUMERIC");
293295
testCodec(Long.class, 100L, "FLOAT4");
294296
testCodec(Long.class, 100L, "FLOAT8");

0 commit comments

Comments
 (0)