Class UUIDType

java.lang.Object
org.apache.cayenne.access.types.UUIDType
All Implemented Interfaces:
ExtendedType<UUID>

public class UUIDType extends Object implements ExtendedType<UUID>
An ExtendedType for java.util.UUID that picks the storage format from the JDBC type of the mapped column:
  • character columns store the canonical 36-char string;
  • binary columns store the 16-byte big-endian form, most significant bits first;
  • anything else is passed to the driver as an object, which is how a PostgreSQL native uuid column works.
Since:
5.0
  • Field Details

    • UUID_BYTES

      public static final int UUID_BYTES
      The length of the binary form of a UUID.
      See Also:
  • Constructor Details

    • UUIDType

      public UUIDType()
  • Method Details

    • getClassName

      public String getClassName()
      Description copied from interface: ExtendedType
      Returns a full name of Java class that this ExtendedType supports.
      Specified by:
      getClassName in interface ExtendedType<UUID>
    • materializeObject

      public UUID materializeObject(ResultSet rs, int index, int type) throws Exception
      Description copied from interface: ExtendedType
      Reads an object from JDBC ResultSet column, converting it to class returned by 'getClassName' method.
      Specified by:
      materializeObject in interface ExtendedType<UUID>
      Throws:
      Exception - if read error occurred, or an object can't be converted to a target Java class.
    • materializeObject

      public UUID materializeObject(CallableStatement rs, int index, int type) throws Exception
      Description copied from interface: ExtendedType
      Reads an object from a stored procedure OUT parameter, converting it to class returned by 'getClassName' method.
      Specified by:
      materializeObject in interface ExtendedType<UUID>
      Throws:
      Exception - if read error occurred, or an object can't be converted to a target Java class.
    • setJdbcObject

      public void setJdbcObject(PreparedStatement statement, UUID value, int pos, int type, int scale) throws Exception
      Description copied from interface: ExtendedType
      Initializes a single parameter of a PreparedStatement with object value.
      Specified by:
      setJdbcObject in interface ExtendedType<UUID>
      Throws:
      Exception
    • toString

      public String toString(UUID value)
      Description copied from interface: ExtendedType
      Converts value of the supported type to a human-readable String representation.
      Specified by:
      toString in interface ExtendedType<UUID>
      Parameters:
      value - a value to convert to String.
    • toBytes

      public static byte[] toBytes(UUID value)
      Converts a UUID to its 16-byte big-endian form, most significant bits first.
    • fromBytes

      public static UUID fromBytes(byte[] value)
      Converts a 16-byte big-endian value, most significant bits first, to a UUID.
    • fromString

      protected static UUID fromString(String value)
    • fromObject

      protected static UUID fromObject(Object value)
      Converts whatever the driver returned for a column of an unrecognized JDBC type. Drivers with native UUID support return a UUID; the rest fall back to the string or binary form.