com.mckoi.database.global
Class CastHelper

java.lang.Object
  extended by com.mckoi.database.global.CastHelper

public class CastHelper
extends java.lang.Object

Various utility methods for helping to cast a Java object to a type that is conformant to an SQL type.

Author:
Tobias Downer

Constructor Summary
CastHelper()
           
 
Method Summary
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.
static java.util.Date toDate(java.lang.String str)
          Parses a String as an SQL date.
static java.util.Date toTime(java.lang.String str)
          Parses a String as an SQL time.
static java.util.Date toTimeStamp(java.lang.String str)
          Parses a String as an SQL timestamp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CastHelper

public CastHelper()
Method Detail

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;
  1. 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.
  2. To cast an object to a specific type in an SQL function such as CAST.
Given any supported object, this will return the internal database representation of the object as either NullObject, BigNumber, String, Date, Boolean or ByteLongObject.

Parameters:
ob - the Object to cast to the given type
sql_type - the enumerated sql type, eg. SQLTypes.LONGVARCHAR
sql_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"