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 ArrayEncoding.AbstractArrayEncoder
arrayOid -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidappendArray(StringBuilder sb, char delim, N[] array) AppendStringrepresentation of array to sb.(package private) final intcountNulls(N[] array) Counts the number ofnullelements 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 voidWrite single value (number) to bytes beginning at offset.private byte[]writeBytes(N[] array, int nullCount, int offset) Methods inherited from class 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 ofnullelements in array.- Overrides:
countNullsin classArrayEncoding.AbstractArrayEncoder<N extends Number[]>- Parameters:
array- The array to countnullelements in.- Returns:
- The number of
nullelements 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 containnullelements.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:
toSingleDimensionBinaryRepresentationin 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 containnullelements.- 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
AppendStringrepresentation of array to sb.- Parameters:
sb- TheStringBuilderto append to.delim- The delimiter between elements.array- The array to represent. Will not benull, but may containnullelements.
-