Interface Codec<A>

Type Parameters:
A - the Java type handled by this codec

public interface Codec<A>
A codec for PostgreSQL types intended for use with pgJDBC. This interface provides methods for binding values to prepared statements and decoding values from result sets.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Codec<io.codemine.java.postgresql.codecs.Bit>
    Codec for SQL bit.
    static final Codec<Boolean>
    Codec for SQL boolean.
    static final Codec<io.codemine.java.postgresql.codecs.Box>
    Codec for SQL box.
    static final Codec<String>
    Codec for SQL bpchar (char(n)).
    static final Codec<io.codemine.java.postgresql.codecs.Bytea>
    Codec for SQL bytea (binary).
    static final Codec<Byte>
    Codec for SQL "char" (internal type).
    static final Codec<io.codemine.java.postgresql.codecs.Cidr>
    Codec for SQL cidr.
    static final Codec<io.codemine.java.postgresql.codecs.Circle>
    Codec for SQL circle.
    static final Codec<String>
    Codec for SQL citext.
    static final Codec<LocalDate>
    Codec for SQL date.
    static final Codec<io.codemine.java.postgresql.codecs.Multirange<LocalDate>>
    Codec for SQL datemultirange.
    static final Codec<io.codemine.java.postgresql.codecs.Range<LocalDate>>
    Codec for SQL daterange.
    static final Codec<Float>
    Codec for SQL float4 (real).
    static final Codec<Double>
    Codec for SQL float8 (double).
    static final Codec<io.codemine.java.postgresql.codecs.Hstore>
    Codec for SQL hstore.
    static final Codec<io.codemine.java.postgresql.codecs.Inet>
    Codec for SQL inet (IP address).
    static final Codec<Short>
    Codec for SQL int2 (smallint).
    static final Codec<Integer>
    Codec for SQL int4 (integer).
    static final Codec<io.codemine.java.postgresql.codecs.Multirange<Integer>>
    Codec for SQL int4multirange.
    static final Codec<io.codemine.java.postgresql.codecs.Range<Integer>>
    Codec for SQL int4range.
    static final Codec<Long>
    Codec for SQL int8 (bigint).
    static final Codec<io.codemine.java.postgresql.codecs.Multirange<Long>>
    Codec for SQL int8multirange.
    static final Codec<io.codemine.java.postgresql.codecs.Range<Long>>
    Codec for SQL int8range.
    static final Codec<io.codemine.java.postgresql.codecs.Interval>
    Codec for SQL interval.
    static final Codec<com.fasterxml.jackson.databind.JsonNode>
    Codec for SQL json (text).
    static final Codec<com.fasterxml.jackson.databind.JsonNode>
    Codec for SQL jsonb (binary JSON).
    static final Codec<io.codemine.java.postgresql.codecs.Line>
    Codec for SQL line.
    static final Codec<io.codemine.java.postgresql.codecs.Lseg>
    Codec for SQL lseg.
    static final Codec<io.codemine.java.postgresql.codecs.Ltree>
    Codec for SQL ltree.
    static final Codec<io.codemine.java.postgresql.codecs.Macaddr>
    Codec for SQL macaddr.
    static final Codec<io.codemine.java.postgresql.codecs.Macaddr8>
    Codec for SQL macaddr8.
    static final Codec<Long>
    Codec for SQL money.
    static final Codec<BigDecimal>
    Codec for SQL numeric/decimal.
    static final Codec<io.codemine.java.postgresql.codecs.Multirange<BigDecimal>>
    Codec for SQL nummultirange.
    static final Codec<io.codemine.java.postgresql.codecs.Range<BigDecimal>>
    Codec for SQL numrange.
    static final Codec<Integer>
    Codec for PostgreSQL OID.
    static final Codec<io.codemine.java.postgresql.codecs.Path>
    Codec for SQL path.
    static final Codec<io.codemine.java.postgresql.codecs.Point>
    Codec for SQL point.
    static final Codec<io.codemine.java.postgresql.codecs.Polygon>
    Codec for SQL polygon.
    static final Codec<String>
    Codec for SQL text.
    static final Codec<LocalTime>
    Codec for SQL time.
    static final Codec<LocalDateTime>
    Codec for SQL timestamp without timezone.
    static final Codec<Instant>
    Codec for SQL timestamptz (timestamp with timezone).
    static final Codec<io.codemine.java.postgresql.codecs.Timetz>
    Codec for SQL timetz.
    static final Codec<io.codemine.java.postgresql.codecs.Multirange<LocalDateTime>>
    Codec for SQL tsmultirange.
    static final Codec<io.codemine.java.postgresql.codecs.Range<LocalDateTime>>
    Codec for SQL tsrange.
    static final Codec<io.codemine.java.postgresql.codecs.Multirange<Instant>>
    Codec for SQL tstzmultirange.
    static final Codec<io.codemine.java.postgresql.codecs.Range<Instant>>
    Codec for SQL tstzrange.
    static final Codec<io.codemine.java.postgresql.codecs.Tsvector>
    Codec for SQL tsvector.
    static final Codec<UUID>
    Codec for SQL uuid.
    static final Codec<io.codemine.java.postgresql.codecs.Bit>
    Codec for SQL varbit.
    static final Codec<String>
    Codec for SQL varchar.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    bind(PreparedStatement ps, int index, A value)
    Binds a value to a prepared statement.
    static Codec<io.codemine.java.postgresql.codecs.Bit>
    bit(int n)
    Returns a codec for PostgreSQL bit(n) — a fixed-length bit string of exactly n bits.
    static Codec<String>
    bpchar(int n)
    Returns a codec for PostgreSQL bpchar(n) — a fixed-length blank-padded character string of exactly n characters.
    static <Z> Codec<Z>
    composite(String schema, String name, Function<Object[],Z> construct, io.codemine.java.postgresql.codecs.CompositeCodec.Field<Z,?>... fields)
    Creates a composite codec for any number of fields using an untyped vararg array constructor.
    default A
    decodeNonNullable(ResultSet rs, int row, int col)
    Decodes a non-nullable value from the result set.
    decodeNullable(ResultSet rs, int row, int col)
    Decodes a nullable value from the result set.
    default Optional<A>
    decodeOptional(ResultSet rs, int row, int col)
    Decodes an optional value from the result set.
    static <A> Codec<A>
    enumeration(String schema, String name, Map<A,String> valueToLabel)
    Returns a codec for PostgreSQL enum types.
    static <Z, A> io.codemine.java.postgresql.codecs.CompositeCodec.Field<Z,A>
    field(String name, Codec<A> codec, Function<Z,A> getter)
    Creates a field descriptor for a composite type.
    default Codec<List<A>>
    Add one dimension of array nesting to this codec, returning a codec for the corresponding PostgreSQL array type.
    io.codemine.java.postgresql.codecs.Codec<A>
    Converts this codec to an agnostic codec that can be used with any PostgreSQL client library.
    static Codec<io.codemine.java.postgresql.codecs.Bit>
    varbit(int n)
    Returns a codec for PostgreSQL varbit(n) — a variable-length bit string of at most n bits.
    static Codec<String>
    varchar(int n)
    Returns a codec for PostgreSQL varchar(n) — a variable-length character string of at most n characters.
  • Field Details

    • INT4

      static final Codec<Integer> INT4
      Codec for SQL int4 (integer).
    • TEXT

      static final Codec<String> TEXT
      Codec for SQL text.
    • INET

      static final Codec<io.codemine.java.postgresql.codecs.Inet> INET
      Codec for SQL inet (IP address).
    • MACADDR

      static final Codec<io.codemine.java.postgresql.codecs.Macaddr> MACADDR
      Codec for SQL macaddr.
    • BOOL

      static final Codec<Boolean> BOOL
      Codec for SQL boolean.
    • INT2

      static final Codec<Short> INT2
      Codec for SQL int2 (smallint).
    • INT8

      static final Codec<Long> INT8
      Codec for SQL int8 (bigint).
    • FLOAT4

      static final Codec<Float> FLOAT4
      Codec for SQL float4 (real).
    • FLOAT8

      static final Codec<Double> FLOAT8
      Codec for SQL float8 (double).
    • NUMERIC

      static final Codec<BigDecimal> NUMERIC
      Codec for SQL numeric/decimal.
    • BYTEA

      static final Codec<io.codemine.java.postgresql.codecs.Bytea> BYTEA
      Codec for SQL bytea (binary).
    • UUID

      static final Codec<UUID> UUID
      Codec for SQL uuid.
    • JSON

      static final Codec<com.fasterxml.jackson.databind.JsonNode> JSON
      Codec for SQL json (text).
    • JSONB

      static final Codec<com.fasterxml.jackson.databind.JsonNode> JSONB
      Codec for SQL jsonb (binary JSON).
    • VARCHAR

      static final Codec<String> VARCHAR
      Codec for SQL varchar.
    • BPCHAR

      static final Codec<String> BPCHAR
      Codec for SQL bpchar (char(n)).
    • CHAR

      static final Codec<Byte> CHAR
      Codec for SQL "char" (internal type).
    • OID

      static final Codec<Integer> OID
      Codec for PostgreSQL OID.
    • MONEY

      static final Codec<Long> MONEY
      Codec for SQL money.
    • DATE

      static final Codec<LocalDate> DATE
      Codec for SQL date.
    • TIME

      static final Codec<LocalTime> TIME
      Codec for SQL time.
    • TIMETZ

      static final Codec<io.codemine.java.postgresql.codecs.Timetz> TIMETZ
      Codec for SQL timetz.
    • TIMESTAMP

      static final Codec<LocalDateTime> TIMESTAMP
      Codec for SQL timestamp without timezone.
    • TIMESTAMPTZ

      static final Codec<Instant> TIMESTAMPTZ
      Codec for SQL timestamptz (timestamp with timezone).
    • INTERVAL

      static final Codec<io.codemine.java.postgresql.codecs.Interval> INTERVAL
      Codec for SQL interval.
    • POINT

      static final Codec<io.codemine.java.postgresql.codecs.Point> POINT
      Codec for SQL point.
    • LINE

      static final Codec<io.codemine.java.postgresql.codecs.Line> LINE
      Codec for SQL line.
    • LSEG

      static final Codec<io.codemine.java.postgresql.codecs.Lseg> LSEG
      Codec for SQL lseg.
    • BOX

      static final Codec<io.codemine.java.postgresql.codecs.Box> BOX
      Codec for SQL box.
    • PATH

      static final Codec<io.codemine.java.postgresql.codecs.Path> PATH
      Codec for SQL path.
    • POLYGON

      static final Codec<io.codemine.java.postgresql.codecs.Polygon> POLYGON
      Codec for SQL polygon.
    • CIRCLE

      static final Codec<io.codemine.java.postgresql.codecs.Circle> CIRCLE
      Codec for SQL circle.
    • CIDR

      static final Codec<io.codemine.java.postgresql.codecs.Cidr> CIDR
      Codec for SQL cidr.
    • MACADDR8

      static final Codec<io.codemine.java.postgresql.codecs.Macaddr8> MACADDR8
      Codec for SQL macaddr8.
    • BIT

      static final Codec<io.codemine.java.postgresql.codecs.Bit> BIT
      Codec for SQL bit.
    • VARBIT

      static final Codec<io.codemine.java.postgresql.codecs.Bit> VARBIT
      Codec for SQL varbit.
    • CITEXT

      static final Codec<String> CITEXT
      Codec for SQL citext.
    • TSVECTOR

      static final Codec<io.codemine.java.postgresql.codecs.Tsvector> TSVECTOR
      Codec for SQL tsvector.
    • HSTORE

      static final Codec<io.codemine.java.postgresql.codecs.Hstore> HSTORE
      Codec for SQL hstore.
    • INT4RANGE

      static final Codec<io.codemine.java.postgresql.codecs.Range<Integer>> INT4RANGE
      Codec for SQL int4range.
    • INT8RANGE

      static final Codec<io.codemine.java.postgresql.codecs.Range<Long>> INT8RANGE
      Codec for SQL int8range.
    • NUMRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Range<BigDecimal>> NUMRANGE
      Codec for SQL numrange.
    • TSRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Range<LocalDateTime>> TSRANGE
      Codec for SQL tsrange.
    • TSTZRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Range<Instant>> TSTZRANGE
      Codec for SQL tstzrange.
    • DATERANGE

      static final Codec<io.codemine.java.postgresql.codecs.Range<LocalDate>> DATERANGE
      Codec for SQL daterange.
    • INT4MULTIRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Multirange<Integer>> INT4MULTIRANGE
      Codec for SQL int4multirange.
    • INT8MULTIRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Multirange<Long>> INT8MULTIRANGE
      Codec for SQL int8multirange.
    • NUMMULTIRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Multirange<BigDecimal>> NUMMULTIRANGE
      Codec for SQL nummultirange.
    • TSMULTIRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Multirange<LocalDateTime>> TSMULTIRANGE
      Codec for SQL tsmultirange.
    • TSTZMULTIRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Multirange<Instant>> TSTZMULTIRANGE
      Codec for SQL tstzmultirange.
    • DATEMULTIRANGE

      static final Codec<io.codemine.java.postgresql.codecs.Multirange<LocalDate>> DATEMULTIRANGE
      Codec for SQL datemultirange.
    • LTREE

      static final Codec<io.codemine.java.postgresql.codecs.Ltree> LTREE
      Codec for SQL ltree.
  • Method Details

    • bit

      static Codec<io.codemine.java.postgresql.codecs.Bit> bit(int n)
      Returns a codec for PostgreSQL bit(n) — a fixed-length bit string of exactly n bits.

      If n <= 0, this returns the unparameterized BIT codec.

      Parameters:
      n - the number of bits
      Returns:
      a codec for bit(n)
    • varbit

      static Codec<io.codemine.java.postgresql.codecs.Bit> varbit(int n)
      Returns a codec for PostgreSQL varbit(n) — a variable-length bit string of at most n bits.

      If n <= 0, this returns the unparameterized VARBIT codec.

      Parameters:
      n - the maximum number of bits
      Returns:
      a codec for varbit(n)
    • varchar

      static Codec<String> varchar(int n)
      Returns a codec for PostgreSQL varchar(n) — a variable-length character string of at most n characters.

      If n <= 0, this returns the unparameterized VARCHAR codec.

      Parameters:
      n - the maximum length in characters
      Returns:
      a codec for varchar(n)
    • bpchar

      static Codec<String> bpchar(int n)
      Returns a codec for PostgreSQL bpchar(n) — a fixed-length blank-padded character string of exactly n characters.
      Parameters:
      n - the fixed length in characters
      Returns:
      a codec for bpchar(n)
    • enumeration

      static <A> Codec<A> enumeration(String schema, String name, Map<A,String> valueToLabel)
      Returns a codec for PostgreSQL enum types.
      Type Parameters:
      A - the enum type
      Parameters:
      schema - the schema name. Empty string or null for the default schema (usually ")
      name - the enum type name
      valueToLabel - a map of enum values to their corresponding labels
      Returns:
      a Codec for the specified enum type
    • composite

      @SafeVarargs static <Z> Codec<Z> composite(String schema, String name, Function<Object[],Z> construct, io.codemine.java.postgresql.codecs.CompositeCodec.Field<Z,?>... fields)
      Creates a composite codec for any number of fields using an untyped vararg array constructor.

      The construct function receives an Object[] whose elements correspond positionally to the supplied field descriptors.

      Note: this constructor is less safely typed than the arity-specific overloads. Callers are responsible for casting elements of the array to the correct types.

      Type Parameters:
      Z - the composite type produced by the construct function
      Parameters:
      schema - PostgreSQL schema name, or empty/null for default search path
      name - PostgreSQL composite type name
      construct - function that maps an Object[] of decoded field values to Z
      fields - field descriptors in declaration order
      Returns:
      a Codec for the composite type
    • field

      static <Z, A> io.codemine.java.postgresql.codecs.CompositeCodec.Field<Z,A> field(String name, Codec<A> codec, Function<Z,A> getter)
      Creates a field descriptor for a composite type.
      Type Parameters:
      Z - the composite type
      A - the field type
      Parameters:
      name - the field name
      codec - the codec for the field type
      getter - a function to extract the field value from the composite object
      Returns:
      a field descriptor
    • toAgnostic

      io.codemine.java.postgresql.codecs.Codec<A> toAgnostic()
      Converts this codec to an agnostic codec that can be used with any PostgreSQL client library.

      This is required for composite codecs, which need to delegate to the underlying agnostic codec for each field.

      Returns:
      an agnostic codec equivalent to this codec
    • bind

      void bind(PreparedStatement ps, int index, A value) throws SQLException
      Binds a value to a prepared statement.
      Parameters:
      ps - the prepared statement
      index - the parameter index
      value - the value to bind
      Throws:
      SQLException - if a database access error occurs
    • decodeNullable

      A decodeNullable(ResultSet rs, int row, int col) throws SQLException
      Decodes a nullable value from the result set.
      Parameters:
      rs - the result set
      row - the row index
      col - the column index
      Returns:
      the decoded value, or null if the value is SQL NULL
      Throws:
      SQLException - if a database access error occurs
    • decodeNonNullable

      default A decodeNonNullable(ResultSet rs, int row, int col) throws SQLException
      Decodes a non-nullable value from the result set.
      Parameters:
      rs - the result set
      row - the row index
      col - the column index
      Returns:
      the decoded value
      Throws:
      SQLException - if a database access error occurs or the value is null
    • decodeOptional

      default Optional<A> decodeOptional(ResultSet rs, int row, int col) throws SQLException
      Decodes an optional value from the result set.
      Parameters:
      rs - the result set
      row - the row index
      col - the column index
      Returns:
      the decoded value wrapped in an Optional, or Optional.empty() if the value is SQL NULL
      Throws:
      SQLException - if a database access error occurs
    • inDim

      default Codec<List<A>> inDim()
      Add one dimension of array nesting to this codec, returning a codec for the corresponding PostgreSQL array type. For example, if this is a codec for type A, the returned codec will be for type A[]. This can be called repeatedly to create codecs for multi-dimensional arrays, e.g. A[][].
      Returns:
      a codec for a one-dimension higher array of this codec's type