Class CodedValueTypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue>

java.lang.Object
org.apache.ibatis.type.TypeReference<E>
org.apache.ibatis.type.BaseTypeHandler<E>
net.solarnetwork.central.dao.mybatis.type.CodedValueTypeHandler<E>
Type Parameters:
E - the enum type
All Implemented Interfaces:
org.apache.ibatis.type.TypeHandler<E>
Direct Known Subclasses:
CodedValueTypeHandler.Zero

public class CodedValueTypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue> extends org.apache.ibatis.type.BaseTypeHandler<E>
Type handler for enum values that implement CodedValue so that an integer database column is used for storage.
  • Constructor Details

    • CodedValueTypeHandler

      public CodedValueTypeHandler(Class<E> type)
      Constructor.

      This will attempt to resolve a code value 0 for a default value, falling back to null if that is not found.

      Parameters:
      type - the type
    • CodedValueTypeHandler

      public CodedValueTypeHandler(Class<E> type, E defaultValue)
      Constructor.
      Parameters:
      type - the type
      defaultValue - the default value to use if no matching code is found
  • Method Details

    • setParameter

      public void setParameter(PreparedStatement ps, int i, E parameter, org.apache.ibatis.type.JdbcType jdbcType) throws SQLException
      Specified by:
      setParameter in interface org.apache.ibatis.type.TypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue>
      Overrides:
      setParameter in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue>
      Throws:
      SQLException
    • setNonNullParameter

      public void setNonNullParameter(PreparedStatement ps, int i, E parameter, org.apache.ibatis.type.JdbcType jdbcType) throws SQLException
      Specified by:
      setNonNullParameter in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue>
      Throws:
      SQLException
    • getNullableResult

      public E getNullableResult(ResultSet rs, String columnName) throws SQLException
      Specified by:
      getNullableResult in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue>
      Throws:
      SQLException
    • getNullableResult

      public E getNullableResult(ResultSet rs, int columnIndex) throws SQLException
      Specified by:
      getNullableResult in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue>
      Throws:
      SQLException
    • getNullableResult

      public E getNullableResult(CallableStatement cs, int columnIndex) throws SQLException
      Specified by:
      getNullableResult in class org.apache.ibatis.type.BaseTypeHandler<E extends Enum<E> & net.solarnetwork.domain.CodedValue>
      Throws:
      SQLException
    • getType

      public Class<E> getType()
      Get the class type.
      Returns:
      the type, never null