Class SpannerDecoder

  • All Implemented Interfaces:
    Decoder

    public class SpannerDecoder
    extends Object
    implements Decoder
    SpannerDecoder implements the Decoder interface for Google Cloud Spanner. It converts Spanner Struct types into Java objects for retrieval from Spanner.

    This decoder handles: - Primitive types (boolean, int, long, double, string) - Byte arrays - Lists and arrays - Maps and structs - Null values

    • Constructor Detail

      • SpannerDecoder

        public SpannerDecoder​(com.google.cloud.spanner.Struct struct)
        Creates a new SpannerDecoder with the specified Struct.
        Parameters:
        struct - The Spanner Struct to decode
      • SpannerDecoder

        public SpannerDecoder​(com.google.cloud.spanner.Value value)
    • Method Detail

      • asString

        public String asString()
        Decodes a Spanner Value into a string.
        Specified by:
        asString in interface Decoder
        Returns:
        The decoded string value, or null if the value is null
      • asInt

        public Integer asInt()
        Decodes a Spanner Value into an integer.
        Specified by:
        asInt in interface Decoder
        Returns:
        The decoded integer value, or null if the value is null
      • asLong

        public Long asLong()
        Decodes a Spanner Value into a long.
        Specified by:
        asLong in interface Decoder
        Returns:
        The decoded long value, or null if the value is null
      • asFloat

        public Float asFloat()
        Decodes a Spanner Value into a float.
        Specified by:
        asFloat in interface Decoder
        Returns:
        The decoded float value, or null if the value is null
      • asDouble

        public Double asDouble()
        Decodes a Spanner Value into a double.
        Specified by:
        asDouble in interface Decoder
        Returns:
        The decoded double value, or null if the value is null
      • asBytes

        public byte[] asBytes()
        Decodes a Spanner Value into a byte array.
        Specified by:
        asBytes in interface Decoder
        Returns:
        The decoded byte array, or null if the value is null
      • asBool

        public Boolean asBool()
        Decodes a Spanner Value into a boolean.
        Specified by:
        asBool in interface Decoder
        Returns:
        The decoded boolean value, or null if the value is null
      • asNull

        public Boolean asNull()
        Checks if the Spanner Value is null.
        Specified by:
        asNull in interface Decoder
        Returns:
        true if the value is null, false otherwise
      • decodeList

        public void decodeList​(ListDecoderCallback callback)
        Decodes a list of Spanner Values using the provided callback.
        Specified by:
        decodeList in interface Decoder
        Parameters:
        callback - The callback to handle each list element
      • listLen

        public int listLen()
        Gets the length of the list in the Spanner Value.
        Specified by:
        listLen in interface Decoder
        Returns:
        The number of elements in the list
      • decodeMap

        public void decodeMap​(MapDecoderCallback callback)
        Decodes a map of Spanner Values using the provided callback.
        Specified by:
        decodeMap in interface Decoder
        Parameters:
        callback - The callback to handle each map entry
      • asInterface

        public Object asInterface()
        Converts the Spanner Value into a Java object. This method handles all supported Spanner types and converts them into their corresponding Java types.
        Specified by:
        asInterface in interface Decoder
        Returns:
        The converted Java object
      • setValue

        public void setValue​(com.google.cloud.spanner.Value value)
        Sets the current value to decode.
        Parameters:
        value - The value to decode