B - the logical typeS - the underlying scalar type this is converted topublic class ScalarTypeWrapper<B,S> extends Object implements ScalarType<B>
Enables the use of a simple interface to add additional scalarTypes.
| Constructor and Description |
|---|
ScalarTypeWrapper(Class<B> wrapperType,
ScalarType<S> scalarType,
ScalarTypeConverter<B,S> converter) |
| Modifier and Type | Method and Description |
|---|---|
void |
accumulateScalarTypes(String propName,
CtCompoundTypeScalarList list)
Accumulate all the scalar types used by an immutable compound value type.
|
void |
bind(DataBind b,
B value)
Convert (if necessary) and bind the value to the preparedStatement.
|
String |
format(Object v)
Convert the type into a string representation.
|
String |
formatValue(B v)
Convert the type into a string representation.
|
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 |
isDateTimeCapable()
Return true if the type can accept long systemTimeMillis input.
|
boolean |
isJdbcNative()
Return true if the type is native to JDBC.
|
B |
jsonFromString(String value,
JsonValueAdapter ctx) |
String |
jsonToString(B value,
JsonValueAdapter ctx) |
void |
jsonWrite(WriteJsonBuffer buffer,
B value,
JsonValueAdapter ctx) |
void |
loadIgnore(DataReader dataReader)
Ignore the reading of this value.
|
B |
parse(String value)
Convert the string value to the appropriate java object.
|
B |
parseDateTime(long systemTimeMillis)
Convert the systemTimeMillis into the appropriate java object.
|
B |
read(DataReader dataReader)
Read the value from the resultSet and convert if necessary to the logical
bean property value.
|
Object |
readData(DataInput dataInput) |
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,
Object v) |
public ScalarTypeWrapper(Class<B> wrapperType, ScalarType<S> scalarType, ScalarTypeConverter<B,S> converter)
public Object readData(DataInput dataInput) throws IOException
readData in interface ScalarType<B>IOExceptionpublic void writeData(DataOutput dataOutput, Object v) throws IOException
writeData in interface ScalarType<B>IOExceptionpublic void bind(DataBind b, B value) throws SQLException
ScalarTypevalue may need to be converted from the logical bean property type to the JDBC type.
bind in interface ScalarDataReader<B>bind in interface ScalarType<B>SQLExceptionpublic int getJdbcType()
ScalarTypeThis type should be consistent with the toJdbcType() method in converting the type to the appropriate type for binding to preparedStatements.
getJdbcType in interface ScalarType<B>public int getLength()
ScalarTypeIf 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).
getLength in interface ScalarType<B>public Class<B> getType()
ScalarTypeThis represents the 'logical' type rather than the JDBC type this maps to.
getType in interface ScalarType<B>public boolean isDateTimeCapable()
ScalarType
This is used to determine if is is sensible to use the
ScalarType.parseDateTime(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).
isDateTimeCapable in interface ScalarType<B>public boolean isJdbcNative()
ScalarTypeIf it is native to JDBC then its values/instances do not need to be converted to and from an associated JDBC type.
isJdbcNative in interface ScalarType<B>public String format(Object v)
ScalarTypeThis assumes the value is of the correct type.
This is so that ScalarType also implements the StringFormatter interface.
format in interface StringFormatterformat in interface ScalarType<B>public String formatValue(B v)
ScalarTypeReciprocal of parse().
formatValue in interface ScalarType<B>public B parse(String value)
ScalarTypeMostly used to support CSV, JSON and XML parsing.
Reciprocal of formatValue().
parse in interface StringParserparse in interface ScalarType<B>public B parseDateTime(long systemTimeMillis)
ScalarTypeFor non dateTime types this will throw an exception.
parseDateTime in interface ScalarType<B>public void loadIgnore(DataReader dataReader)
ScalarTypeloadIgnore in interface ScalarDataReader<B>loadIgnore in interface ScalarType<B>public B read(DataReader dataReader) throws SQLException
ScalarTyperead in interface ScalarDataReader<B>read in interface ScalarType<B>SQLExceptionpublic B toBeanType(Object value)
ScalarTypeThe type as per the bean property.
This is used to automatically convert id values (typically from a string to a int, long or UUID).
toBeanType in interface ScalarType<B>public Object toJdbcType(Object value)
ScalarTypeNote 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.
toJdbcType in interface ScalarType<B>public void accumulateScalarTypes(String propName, CtCompoundTypeScalarList list)
ScalarDataReaderaccumulateScalarTypes in interface ScalarDataReader<B>public ScalarType<?> getScalarType()
public String jsonToString(B value, JsonValueAdapter ctx)
jsonToString in interface ScalarType<B>public void jsonWrite(WriteJsonBuffer buffer, B value, JsonValueAdapter ctx)
jsonWrite in interface ScalarType<B>public B jsonFromString(String value, JsonValueAdapter ctx)
jsonFromString in interface ScalarType<B>Copyright © 2014. All Rights Reserved.