Class EnumCodec<E>
- Type Parameters:
E- the Java enum type
- All Implemented Interfaces:
Codec<E>
ENUM types, mapping between Java enum constants and their
corresponding PostgreSQL label strings.-
Nested Class Summary
Nested classes/interfaces inherited from interface io.codemine.java.postgresql.codecs.Codec
Codec.DecodingException, Codec.ParsingResult<A> -
Field Summary
Fields inherited from interface io.codemine.java.postgresql.codecs.Codec
BIT, BOOL, BOX, BPCHAR, BYTEA, CHAR, CIDR, CIRCLE, CITEXT, DATE, DATEMULTIRANGE, DATERANGE, FLOAT4, FLOAT8, HSTORE, INET, INT2, INT4, INT4MULTIRANGE, INT4RANGE, INT8, INT8MULTIRANGE, INT8RANGE, INTERVAL, JSON, JSONB, LINE, LSEG, LTREE, MACADDR, MACADDR8, MONEY, NUMERIC, NUMMULTIRANGE, NUMRANGE, OID, PATH, POINT, POLYGON, TEXT, TIME, TIMESTAMP, TIMESTAMPTZ, TIMETZ, TSMULTIRANGE, TSRANGE, TSTZMULTIRANGE, TSTZRANGE, TSVECTOR, UUID, VARBIT, VARCHAR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondecodeInBinary(ByteBuffer buf, int length) Decodes a value from the PostgreSQL binary wire format.decodeInText(CharSequence input, int offset) Parses a PostgreSQL text-format literal of type A frominputstarting atoffset.voidencodeInBinary(E value, ByteArrayOutputStream out) Encodes the given non-null value into the PostgreSQL binary wire format, appending the bytes directly toout.voidencodeInText(StringBuilder sb, E value) Writes the given value to the string builder in PostgreSQL textual literal form.name()Returns the PostgreSQL type name (e.g.Generates a random value of type A, for testing purposes.schema()Returns the PostgreSQL schema name for this type, or empty string ornullif the type is in the default search path.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.codemine.java.postgresql.codecs.Codec
arrayOid, decodeInBinaryFromBytes, decodeInTextFromString, dimensions, encodeInBinaryToByteBuffer, encodeInBinaryToBytes, encodeInTextToString, inDim, jdbcType, map, oid, scalarOid, typeSig, withType, withType
-
Constructor Details
-
EnumCodec
Creates a new codec for the PostgreSQL enum typenameinschema.- Parameters:
schema- the PostgreSQL schema containing the enum type, or empty/null for the default search pathname- the PostgreSQL enum type namepgLabels- mapping from each Java enum constant to its PostgreSQL label string
-
-
Method Details
-
schema
Description copied from interface:CodecReturns the PostgreSQL schema name for this type, or empty string ornullif the type is in the default search path. -
name
Description copied from interface:CodecReturns the PostgreSQL type name (e.g."int4","text"). -
encodeInText
Description copied from interface:CodecWrites the given value to the string builder in PostgreSQL textual literal form.This is primarily used for encoding fields inside composite and array literals. The written form must be the canonical text representation accepted by PostgreSQL for the type.
- Specified by:
encodeInTextin interfaceCodec<E>
-
decodeInText
public Codec.ParsingResult<E> decodeInText(CharSequence input, int offset) throws Codec.DecodingException Description copied from interface:CodecParses a PostgreSQL text-format literal of type A frominputstarting atoffset.The input must be a non-null
CharSequenceholding the raw text as returned by the PostgreSQL server (e.g. the string value of a column obtained viaResultSet.getString(int)). Passing theStringdirectly avoids an extra copy compared to converting to achar[]first. NULL column values must be handled by the caller before invoking this method.Returns the parsed value together with the offset of the first character that was not consumed, allowing callers to continue parsing subsequent fields without copying the input. Throws
Codec.DecodingExceptionif the input cannot be interpreted as a valid literal of type A.- Specified by:
decodeInTextin interfaceCodec<E>- Throws:
Codec.DecodingException
-
encodeInBinary
Description copied from interface:CodecEncodes the given non-null value into the PostgreSQL binary wire format, appending the bytes directly toout.Appends exactly the binary payload for the value — no length prefix. The caller (e.g.
CompositeCodec) is responsible for prepending the 4-byteint32length header required by the PostgreSQL composite and array binary protocols.The byte order is always big-endian, as required by the PostgreSQL wire protocol.
- Specified by:
encodeInBinaryin interfaceCodec<E>
-
decodeInBinary
Description copied from interface:CodecDecodes a value from the PostgreSQL binary wire format.bufmust be a big-endianByteBufferpositioned at the first byte of the value's payload.lengthis the number of bytes that make up the payload (as read from the precedingint32length header). The method advances the buffer position by exactlylengthbytes.NULL handling (
length == -1) must be performed by the caller before invoking this method.- Specified by:
decodeInBinaryin interfaceCodec<E>- Throws:
Codec.DecodingException- if the binary data is malformed
-
random
Description copied from interface:CodecGenerates a random value of type A, for testing purposes. The providedRandominstance should be used as the source of randomness, and the generated values should cover a wide range of possible inputs, including edge cases.The
sizeparameter follows the QuickCheck convention: it is a non-negative integer that controls the "size" of the generated value — for scalars it bounds the magnitude, for collections it bounds the number of elements, and for multidimensional arrays it is propagated uniformly to all sub-arrays so that the resulting array has a rectangular shape.
-