Class JKBooleanConverter

java.lang.Object
com.jk.data.dataaccess.orm.util.JKBooleanConverter
All Implemented Interfaces:
jakarta.persistence.AttributeConverter<Boolean,String>
Direct Known Subclasses:
JKBooleanYesNoConvertor, JKBooleanYNConvertor

public class JKBooleanConverter extends Object implements jakarta.persistence.AttributeConverter<Boolean,String>
This class is used to convert boolean values (true and false) into a custom string representation.
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • JKBooleanConverter

      public JKBooleanConverter()
      This method constructs a new JKBooleanConverter.

      This constructs represents the true boolean value with the "1" string, and the false boolean value with the "0" string.

    • JKBooleanConverter

      public JKBooleanConverter(String trueString, String falseString)
      This method constructs a new JKBooleanConverter with the specified true and false strings.
      Parameters:
      trueString - Specifies the string representation of the true boolean value.
      falseString - Specifies the string representation of the false boolean value.
  • Method Details

    • convertToDatabaseColumn

      public String convertToDatabaseColumn(Boolean value)
      Converts the value stored in the entity attribute into the data representation to be stored in the database.
      Specified by:
      convertToDatabaseColumn in interface jakarta.persistence.AttributeConverter<Boolean,String>
      Parameters:
      value - the entity attribute value to be converted
      Returns:
      the converted data to be stored in the database column
    • convertToEntityAttribute

      public Boolean convertToEntityAttribute(String value)
      Converts the data stored in the database column into the value to be stored in the entity attribute. Note that it is the responsibility of the converter writer to specify the correct dbData type for the corresponding column for use by the JDBC driver: i.e., persistence providers are not expected to do such type conversion.
      Specified by:
      convertToEntityAttribute in interface jakarta.persistence.AttributeConverter<Boolean,String>
      Parameters:
      value - the data from the database column to be converted
      Returns:
      the converted value to be stored in the entity attribute