Package com.mckoi.database.global
Class CastHelper
- java.lang.Object
-
- com.mckoi.database.global.CastHelper
-
public class CastHelper extends java.lang.ObjectVarious utility methods for helping to cast a Java object to a type that is conformant to an SQL type.
-
-
Field Summary
Fields Modifier and Type Field Description private static BigNumberBD_ONEprivate static BigNumberBD_ZEROA couple of standard BigNumber statics.private static java.text.DateFormat[]date_format_sqlDate, Time and Timestamp parser/formattersprivate static java.text.DateFormat[]time_format_sqlprivate static java.text.DateFormat[]ts_format_sql
-
Constructor Summary
Constructors Constructor Description CastHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ObjectcastObjectToSQLType(java.lang.Object ob, int sql_type, int sql_size, int sql_scale, java.lang.String sql_type_string)Casts a Java object to the SQL type specified by the given DataTableColumnDef object.private static java.lang.StringdateErrorString(java.lang.String msg, java.text.DateFormat[] df)Helper that generates an appropriate error message for a date format error.private static java.lang.StringformatDateAsString(java.util.Date d)Formats the date object as a standard SQL string.private static java.lang.StringpaddedString(java.lang.String str, int size)Returns the given string padded or truncated to the given size.private static BigNumbertoBigNumber(java.lang.String str)Converts the given string to a BigNumber.private static java.util.DatetoDate(long time)Returns the given long value as a date object.static java.util.DatetoDate(java.lang.String str)Parses a String as an SQL date.private static java.lang.ObjecttoJavaObject(java.lang.Object ob)Converts the given object to an SQL JAVA_OBJECT type by serializing the object.static java.util.DatetoTime(java.lang.String str)Parses a String as an SQL time.static java.util.DatetoTimeStamp(java.lang.String str)Parses a String as an SQL timestamp.
-
-
-
Field Detail
-
BD_ZERO
private static BigNumber BD_ZERO
A couple of standard BigNumber statics.
-
BD_ONE
private static BigNumber BD_ONE
-
date_format_sql
private static java.text.DateFormat[] date_format_sql
Date, Time and Timestamp parser/formatters
-
time_format_sql
private static java.text.DateFormat[] time_format_sql
-
ts_format_sql
private static java.text.DateFormat[] ts_format_sql
-
-
Method Detail
-
toJavaObject
private static java.lang.Object toJavaObject(java.lang.Object ob)
Converts the given object to an SQL JAVA_OBJECT type by serializing the object.
-
formatDateAsString
private static java.lang.String formatDateAsString(java.util.Date d)
Formats the date object as a standard SQL string.
-
paddedString
private static java.lang.String paddedString(java.lang.String str, int size)Returns the given string padded or truncated to the given size. If size is -1 then the size doesn't matter.
-
toDate
private static java.util.Date toDate(long time)
Returns the given long value as a date object.
-
toBigNumber
private static BigNumber toBigNumber(java.lang.String str)
Converts the given string to a BigNumber. Returns 0 if the cast fails.
-
dateErrorString
private static java.lang.String dateErrorString(java.lang.String msg, java.text.DateFormat[] df)Helper that generates an appropriate error message for a date format error.
-
toDate
public static java.util.Date toDate(java.lang.String str)
Parses a String as an SQL date.
-
toTime
public static java.util.Date toTime(java.lang.String str)
Parses a String as an SQL time.
-
toTimeStamp
public static java.util.Date toTimeStamp(java.lang.String str)
Parses a String as an SQL timestamp.
-
castObjectToSQLType
public static java.lang.Object castObjectToSQLType(java.lang.Object ob, int sql_type, int sql_size, int sql_scale, java.lang.String sql_type_string)Casts a Java object to the SQL type specified by the given DataTableColumnDef object. This is used for the following engine functions;- To prepare a value for insertion into the data store. For example, the table column may be STRING but the value here is a BigNumber.
- To cast an object to a specific type in an SQL function such as CAST.
- Parameters:
ob- the Object to cast to the given typesql_type- the enumerated sql type, eg. SQLTypes.LONGVARCHARsql_size- the size of the type. For example, CHAR(20)sql_scale- the scale of the numerical type.sql_type_string- 'sql_type' as a human understandable string, eg. "LONGVARCHAR"
-
-