Class ScalarTypeWrapper<B,S>
- java.lang.Object
-
- io.ebeaninternal.server.type.ScalarTypeWrapper<B,S>
-
- Type Parameters:
B
- the logical typeS
- the underlying scalar type this is converted to
- All Implemented Interfaces:
StringFormatter
,StringParser
,ScalarDataReader<B>
,ScalarType<B>
- Direct Known Subclasses:
ScalarTypeLongToTimestamp
public class ScalarTypeWrapper<B,S> extends Object implements ScalarType<B>
A ScalarType that uses a ScalarTypeConverter to convert to and from another underlying ScalarType.Enables the use of a simple interface to add additional scalarTypes.
-
-
Constructor Summary
Constructors Constructor Description ScalarTypeWrapper(Class<B> wrapperType, ScalarType<S> scalarType, ScalarTypeConverter<B,S> converter)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
asVersion(B value)
Convert the value into a long version value.void
bind(DataBind b, B value)
Convert (if necessary) and bind the value to the preparedStatement.B
convertFromMillis(long systemTimeMillis)
Convert the systemTimeMillis into the appropriate java object.String
format(Object v)
Convert the type into a string representation.String
formatValue(B v)
Convert the type into a string representation.DocPropertyType
getDocType()
Return the type this maps to for JSON document stores.int
getJdbcType()
Return the type as per java.sql.Types that this maps to.int
getLength()
Return the default DB column length for this type.ScalarType<?>
getScalarType()
Class<B>
getType()
Return the type that matches the bean property type.boolean
isBinaryType()
Return true if this is a binary type and can not support parse() and format() from/to string.boolean
isDateTimeCapable()
Return true if the type can accept long systemTimeMillis input.boolean
isDirty(Object value)
For mutable scalarType's return true if the value is dirty.boolean
isJdbcNative()
Return true if the type is native to JDBC.boolean
isMutable()
Return true if this is a mutable scalar type (like hstore).B
jsonRead(com.fasterxml.jackson.core.JsonParser parser)
Read the value from JsonParser.void
jsonWrite(com.fasterxml.jackson.core.JsonGenerator writer, B beanValue)
Write the value to the JsonGenerator.void
loadIgnore(DataReader dataReader)
Ignore the reading of this value.B
parse(String value)
Convert the string value to the appropriate java object.B
read(DataReader dataReader)
Read the value from the resultSet and convert if necessary to the logical bean property value.B
readData(DataInput dataInput)
Read the value from binary input.B
toBeanType(Object value)
Convert the value as necessary to the logical Bean type.Object
toJdbcType(Object value)
Convert the value as necessary to the JDBC type.String
toString()
void
writeData(DataOutput dataOutput, B value)
Write the value to binary output.
-
-
-
Constructor Detail
-
ScalarTypeWrapper
public ScalarTypeWrapper(Class<B> wrapperType, ScalarType<S> scalarType, ScalarTypeConverter<B,S> converter)
-
-
Method Detail
-
asVersion
public long asVersion(B value)
Description copied from interface:ScalarType
Convert the value into a long version value.- Specified by:
asVersion
in interfaceScalarType<B>
-
isBinaryType
public boolean isBinaryType()
Description copied from interface:ScalarType
Return true if this is a binary type and can not support parse() and format() from/to string. This allows Ebean to optimise marshalling types to string.- Specified by:
isBinaryType
in interfaceScalarType<B>
-
isMutable
public boolean isMutable()
Description copied from interface:ScalarType
Return true if this is a mutable scalar type (like hstore).- Specified by:
isMutable
in interfaceScalarType<B>
-
isDirty
public boolean isDirty(Object value)
Description copied from interface:ScalarType
For mutable scalarType's return true if the value is dirty. Non-dirty properties may be excluded from updates.- Specified by:
isDirty
in interfaceScalarType<B>
-
readData
public B readData(DataInput dataInput) throws IOException
Description copied from interface:ScalarType
Read the value from binary input.- Specified by:
readData
in interfaceScalarType<B>
- Throws:
IOException
-
writeData
public void writeData(DataOutput dataOutput, B value) throws IOException
Description copied from interface:ScalarType
Write the value to binary output.- Specified by:
writeData
in interfaceScalarType<B>
- Throws:
IOException
-
bind
public void bind(DataBind b, B value) throws SQLException
Description copied from interface:ScalarType
Convert (if necessary) and bind the value to the preparedStatement.value may need to be converted from the logical bean property type to the JDBC type.
- Specified by:
bind
in interfaceScalarType<B>
- Throws:
SQLException
-
getJdbcType
public int getJdbcType()
Description copied from interface:ScalarType
Return the type as per java.sql.Types that this maps to.This type should be consistent with the toJdbcType() method in converting the type to the appropriate type for binding to preparedStatements.
- Specified by:
getJdbcType
in interfaceScalarType<B>
-
getLength
public int getLength()
Description copied from interface:ScalarType
Return the default DB column length for this type.If a BeanProperty has no explicit length defined then this length should be assigned.
This is primarily to support defining a length on Enum types (to supplement defining the length on the BeanProperty directly).
- Specified by:
getLength
in interfaceScalarType<B>
-
getType
public Class<B> getType()
Description copied from interface:ScalarType
Return the type that matches the bean property type.This represents the 'logical' type rather than the JDBC type this maps to.
- Specified by:
getType
in interfaceScalarType<B>
-
isDateTimeCapable
public boolean isDateTimeCapable()
Description copied from interface:ScalarType
Return true if the type can accept long systemTimeMillis input.This is used to determine if is is sensible to use the
ScalarType.convertFromMillis(long)
method.This includes the Date, Calendar, sql Date, Time, Timestamp, JODA types as well as Long, BigDecimal and String (although it generally is not expected to parse systemTimeMillis to a String or BigDecimal).
- Specified by:
isDateTimeCapable
in interfaceScalarType<B>
-
isJdbcNative
public boolean isJdbcNative()
Description copied from interface:ScalarType
Return true if the type is native to JDBC.If it is native to JDBC then its values/instances do not need to be converted to and from an associated JDBC type.
- Specified by:
isJdbcNative
in interfaceScalarType<B>
-
format
public String format(Object v)
Description copied from interface:ScalarType
Convert the type into a string representation.This assumes the value is of the correct type.
This is so that ScalarType also implements the StringFormatter interface.
- Specified by:
format
in interfaceScalarType<B>
- Specified by:
format
in interfaceStringFormatter
-
formatValue
public String formatValue(B v)
Description copied from interface:ScalarType
Convert the type into a string representation.Reciprocal of parse().
- Specified by:
formatValue
in interfaceScalarType<B>
-
parse
public B parse(String value)
Description copied from interface:ScalarType
Convert the string value to the appropriate java object.Mostly used to support CSV, JSON and XML parsing.
Reciprocal of formatValue().
- Specified by:
parse
in interfaceScalarType<B>
- Specified by:
parse
in interfaceStringParser
-
convertFromMillis
public B convertFromMillis(long systemTimeMillis)
Description copied from interface:ScalarType
Convert the systemTimeMillis into the appropriate java object.For non dateTime types this will throw an exception.
- Specified by:
convertFromMillis
in interfaceScalarType<B>
-
loadIgnore
public void loadIgnore(DataReader dataReader)
Description copied from interface:ScalarType
Ignore the reading of this value. Typically this means moving the index position in the ResultSet.- Specified by:
loadIgnore
in interfaceScalarType<B>
-
read
public B read(DataReader dataReader) throws SQLException
Description copied from interface:ScalarType
Read the value from the resultSet and convert if necessary to the logical bean property value.- Specified by:
read
in interfaceScalarDataReader<B>
- Specified by:
read
in interfaceScalarType<B>
- Throws:
SQLException
-
toBeanType
public B toBeanType(Object value)
Description copied from interface:ScalarType
Convert the value as necessary to the logical Bean type.The type as per the bean property.
This is used to automatically convert id values (typically from a string to a int, long or UUID).
- Specified by:
toBeanType
in interfaceScalarType<B>
-
toJdbcType
public Object toJdbcType(Object value)
Description copied from interface:ScalarType
Convert the value as necessary to the JDBC type.Note that this should also match the type as per the getJdbcType() method.
This is typically used when the matching type is used in a where clause and we use this to ensure it is an appropriate jdbc type.
- Specified by:
toJdbcType
in interfaceScalarType<B>
-
getScalarType
public ScalarType<?> getScalarType()
-
jsonRead
public B jsonRead(com.fasterxml.jackson.core.JsonParser parser) throws IOException
Description copied from interface:ScalarType
Read the value from JsonParser.- Specified by:
jsonRead
in interfaceScalarType<B>
- Throws:
IOException
-
jsonWrite
public void jsonWrite(com.fasterxml.jackson.core.JsonGenerator writer, B beanValue) throws IOException
Description copied from interface:ScalarType
Write the value to the JsonGenerator.- Specified by:
jsonWrite
in interfaceScalarType<B>
- Throws:
IOException
-
getDocType
public DocPropertyType getDocType()
Description copied from interface:ScalarType
Return the type this maps to for JSON document stores.- Specified by:
getDocType
in interfaceScalarType<B>
-
-