public interface ScalarType<T> extends StringParser, StringFormatter, ScalarDataReader<T>
Scalar in the sense that the types are not compound types. Scalar types only map to a single database column.
These types fall into two categories. Types that are mapped natively to JDBC types and the rest. Types that map to native JDBC types do not require any data type conversion to be persisted to the database. These are java types that map via java.sql.Types.
Types that are not native to JDBC require some conversion. These include some common java types such as java.util.Date, java.util.Calendar, java.math.BigInteger.
Note that Booleans may be native for some databases and require conversion on other databases.
| Modifier and Type | Method and Description |
|---|---|
void |
bind(DataBind b,
T value)
Convert (if necessary) and bind the value to the preparedStatement.
|
String |
format(Object v)
Convert the type into a string representation.
|
String |
formatValue(T 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.
|
Class<T> |
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.
|
T |
jsonFromString(String value,
JsonValueAdapter ctx) |
String |
jsonToString(T value,
JsonValueAdapter ctx) |
void |
jsonWrite(WriteJsonBuffer buffer,
T value,
JsonValueAdapter ctx) |
void |
loadIgnore(DataReader dataReader)
Ignore the reading of this value.
|
T |
parse(String value)
Convert the string value to the appropriate java object.
|
T |
parseDateTime(long dateTime)
Convert the systemTimeMillis into the appropriate java object.
|
T |
read(DataReader dataReader)
Read the value from the resultSet and convert if necessary to the logical
bean property value.
|
Object |
readData(DataInput dataInput) |
T |
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.
|
void |
writeData(DataOutput dataOutput,
Object v) |
accumulateScalarTypesint getLength()
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).
boolean isJdbcNative()
If it is native to JDBC then its values/instances do not need to be converted to and from an associated JDBC type.
int getJdbcType()
This type should be consistent with the toJdbcType() method in converting the type to the appropriate type for binding to preparedStatements.
Class<T> getType()
This represents the 'logical' type rather than the JDBC type this maps to.
T read(DataReader dataReader) throws SQLException
read in interface ScalarDataReader<T>SQLExceptionvoid loadIgnore(DataReader dataReader)
loadIgnore in interface ScalarDataReader<T>void bind(DataBind b, T value) throws SQLException
value may need to be converted from the logical bean property type to the JDBC type.
bind in interface ScalarDataReader<T>SQLExceptionObject toJdbcType(Object value)
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.
T toBeanType(Object value)
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).
String formatValue(T v)
Reciprocal of parse().
String format(Object v)
This assumes the value is of the correct type.
This is so that ScalarType also implements the StringFormatter interface.
format in interface StringFormatterT parse(String value)
Mostly used to support CSV, JSON and XML parsing.
Reciprocal of formatValue().
parse in interface StringParserT parseDateTime(long dateTime)
For non dateTime types this will throw an exception.
boolean isDateTimeCapable()
This is used to determine if is is sensible to use the
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).
void jsonWrite(WriteJsonBuffer buffer, T value, JsonValueAdapter ctx)
String jsonToString(T value, JsonValueAdapter ctx)
T jsonFromString(String value, JsonValueAdapter ctx)
Object readData(DataInput dataInput) throws IOException
IOExceptionvoid writeData(DataOutput dataOutput, Object v) throws IOException
IOExceptionCopyright © 2014. All Rights Reserved.