001package io.ebean.config; 002 003/** 004 * Matches the functionality of javax.persistence.AttributeConverter 005 * <p> 006 * In general AttributeConverter should be used in preference to this 007 * ScalarTypeConverter as it is JPA standard and offers the same functionality. 008 * </p> 009 * <p> 010 * For Ebean we will look to deprecate this interface in preference to AttributeConverter. 011 * </p> 012 * <p> 013 * Used to convert between a value object and a known scalar type. The value 014 * object is the logical type used in your application and the scalar type is 015 * the value used to persist than to the DB. 016 * </p> 017 * <p> 018 * The Value object should be immutable and scalar (aka not compound) and 019 * converts to and from a known scalar type which Ebean will use to persist the 020 * value. 021 * </p> 022 * 023 * @param <B> The value object type. 024 * @param <S> The scalar object type that is used to persist the value object. 025 */ 026public interface ScalarTypeConverter<B, S> { 027 028 /** 029 * Return the value to represent null. Typically this is actually null but for 030 * scala.Option and similar type converters this actually returns an instance 031 * representing "None". 032 */ 033 B getNullValue(); 034 035 /** 036 * Convert the scalar type value into the value object. 037 * <p> 038 * This typically occurs when Ebean reads the value from a resultSet or other 039 * data source. 040 * </p> 041 * 042 * @param scalarType the value from the data source 043 */ 044 B wrapValue(S scalarType); 045 046 /** 047 * Convert the value object into a scalar value that Ebean knows how to 048 * persist. 049 * <p> 050 * This typically occurs when Ebean is persisting the value object to the data 051 * store. 052 * </p> 053 * 054 * @param beanType the value object 055 */ 056 S unwrapValue(B beanType); 057 058}