Package org.postgresql.jdbc
Class ArrayEncoding.NumberArrayEncoder<N extends Number>
java.lang.Object
org.postgresql.jdbc.ArrayEncoding.AbstractArrayEncoder<N[]>
org.postgresql.jdbc.ArrayEncoding.NumberArrayEncoder<N>
- Type Parameters:
N
- The base type of array.
- All Implemented Interfaces:
ArrayEncoding.ArrayEncoder<N[]>
- Enclosing class:
ArrayEncoding
private abstract static class ArrayEncoding.NumberArrayEncoder<N extends Number>
extends ArrayEncoding.AbstractArrayEncoder<N[]>
Base class to provide support for
Number
based arrays.-
Field Summary
FieldsFields inherited from class org.postgresql.jdbc.ArrayEncoding.AbstractArrayEncoder
arrayOid
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
appendArray
(StringBuilder sb, char delim, N[] array) AppendString
representation of array to sb.(package private) final int
countNulls
(N[] array) Counts the number ofnull
elements in array.final byte[]
toBinaryRepresentation
(BaseConnection connection, N[] array, int oid) Creates binary representation of the array.(package private) final byte[]
toSingleDimensionBinaryRepresentation
(BaseConnection connection, N[] array) Createsbyte[]
of just the raw data (no metadata).protected abstract void
Write single value (number) to bytes beginning at offset.private byte[]
writeBytes
(N[] array, int nullCount, int offset) Methods inherited from class org.postgresql.jdbc.ArrayEncoding.AbstractArrayEncoder
getDefaultArrayTypeOid, getTypeOID, supportBinaryRepresentation, toArrayString
-
Field Details
-
fieldSize
private final int fieldSize
-
-
Constructor Details
-
NumberArrayEncoder
NumberArrayEncoder(int fieldSize, int oid, int arrayOid) - Parameters:
fieldSize
- The fixed size to represent each value in binary.oid
- The base type oid.arrayOid
- The array type oid.
-
-
Method Details
-
countNulls
Counts the number ofnull
elements in array.- Overrides:
countNulls
in classArrayEncoding.AbstractArrayEncoder<N extends Number[]>
- Parameters:
array
- The array to countnull
elements in.- Returns:
- The number of
null
elements in array.
-
toBinaryRepresentation
public final byte[] toBinaryRepresentation(BaseConnection connection, N[] array, int oid) throws SQLException, SQLFeatureNotSupportedException Creates binary representation of the array.- Parameters:
connection
- The connection the binary representation will be used on. Attributes from the connection might impact how values are translated to binary.array
- The array to binary encode. Must not benull
, but may containnull
elements.oid
- The array type oid to use. Calls toArrayEncoding.ArrayEncoder.supportBinaryRepresentation(int)
must have returnedtrue
.- Returns:
- The binary representation of array.
- Throws:
SQLFeatureNotSupportedException
- IfArrayEncoding.ArrayEncoder.supportBinaryRepresentation(int)
is false for oid.SQLException
-
toSingleDimensionBinaryRepresentation
final byte[] toSingleDimensionBinaryRepresentation(BaseConnection connection, N[] array) throws SQLException, SQLFeatureNotSupportedException Createsbyte[]
of just the raw data (no metadata).- Specified by:
toSingleDimensionBinaryRepresentation
in classArrayEncoding.AbstractArrayEncoder<N extends Number[]>
- Parameters:
connection
- The connection the binary representation will be used on.array
- The array to create binary representation of. Will not benull
, but may containnull
elements.- Returns:
byte[]
of just the raw data (no metadata).- Throws:
SQLFeatureNotSupportedException
- IfArrayEncoding.AbstractArrayEncoder.supportBinaryRepresentation(int)
is false for oid.SQLException
-
writeBytes
-
write
Write single value (number) to bytes beginning at offset.- Parameters:
number
- The value to write to bytes. This will never benull
.bytes
- Thebyte[]
to write to.offset
- The offset into bytes to write the number value.
-
appendArray
AppendString
representation of array to sb.- Parameters:
sb
- TheStringBuilder
to append to.delim
- The delimiter between elements.array
- The array to represent. Will not benull
, but may containnull
elements.
-