Package mgui.datasources
Class DataTypes
java.lang.Object
mgui.datasources.DataTypes
public class DataTypes
extends java.lang.Object
Class to provide functions for testing and comparing data types.
- Author:
- Andrew Reid
-
Field Summary
Fields Modifier and Type Field Description static int
BINARY
static int
BLOB
static int
BOOLEAN
static int
BYTE
static int
CHAR
static int
CLOB
static java.util.ArrayList<DataType>
dataTypes
static int
DATE
static int
DECIMAL
static int
DOUBLE
static int
FLOAT
static int
INTEGER
static int
JAVA_OBJECT
static int
LONG
static int
LONGSTRING
static int
RGB
static int
RGBA
static int
SHORT
static int
SINGLE
static int
STRING
static int
TIMESTAMP
static int
USHORT
-
Constructor Summary
Constructors Constructor Description DataTypes()
-
Method Summary
Modifier and Type Method Description static int
getDataBufferType(java.lang.String type)
static int
getDataBufferType(DataType type)
static java.lang.String
getDataBufferTypeStr(int type)
static java.util.ArrayList<DataType>
getDataTypeList()
Returns a sorted list of strings representing data types as specified in the setDataTypes methodstatic DataType
getFromDataBufferType(int db_type)
static java.lang.Object
getInstanceForValue(java.lang.Object value, int data_type)
Converts a value from aString
to an instance of the specified type.static int
getMappedSQLTypeDBMStoJDBC(int dataType, java.lang.String driverStr)
Return data type mapped to particular driver (for non-standard types) from DBMS type to JDBC typestatic int
getMappedSQLTypeJDBCtoDBMS(int dataType, java.lang.String driverStr)
static int
getSize(DataType type)
Returns the number of bytes required to store a value of DataTypetype
.static int
getSizeForSQLType(int type)
Returns the number of bytes required to store a value of the SQL typetype
.static int
getSizeForType(int type)
Returns the number of bytes required to store a value of DataType valuetype
.static int
getSQLStrValue(java.lang.String typeStr)
Returns the equivalent integer value (fromTypes
for the given type string.static java.lang.Class
getSQLTypeClass(int dataType)
Return the class of given data typestatic java.lang.String
getSQLTypeLabel(int SQLType)
static java.lang.Object
getSQLTypeObject(int dataType)
static java.lang.String
getSQLTypeStr(int SQLType)
static java.lang.String
getSQLTypeStr(int SQLType, int length)
static DataType
getType(int val)
static DataType
getType(java.lang.String type)
static DataType
getTypeForSize(int size)
static DataType
getTypeForSQL(int SQLType)
Returns aDataType
for the given SQL type (fromTypes
).static DataType
getTypeForSQLStr(java.lang.String sqlType)
static int
guessDataType(java.lang.String token)
Returns a best guess for the data type of the given string.static boolean
isComparable(int dataType)
static boolean
isNumeric(int sqlType)
Determines whether a given SQL type is numericstatic boolean
isText(int sqlType)
Determines whether a given SQL type is textstatic boolean
isText(DataType dataType)
Determines whether a given data type is textstatic boolean
isType(java.lang.Object obj, int type)
static void
setSQLTypes(java.util.HashMap<java.lang.Integer,java.lang.String> map)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
INTEGER
public static final int INTEGER- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE- See Also:
- Constant Field Values
-
SINGLE
public static final int SINGLE- See Also:
- Constant Field Values
-
CHAR
public static final int CHAR- See Also:
- Constant Field Values
-
STRING
public static final int STRING- See Also:
- Constant Field Values
-
LONGSTRING
public static final int LONGSTRING- See Also:
- Constant Field Values
-
BINARY
public static final int BINARY- See Also:
- Constant Field Values
-
BOOLEAN
public static final int BOOLEAN- See Also:
- Constant Field Values
-
SHORT
public static final int SHORT- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT- See Also:
- Constant Field Values
-
LONG
public static final int LONG- See Also:
- Constant Field Values
-
RGB
public static final int RGB- See Also:
- Constant Field Values
-
RGBA
public static final int RGBA- See Also:
- Constant Field Values
-
BYTE
public static final int BYTE- See Also:
- Constant Field Values
-
USHORT
public static final int USHORT- See Also:
- Constant Field Values
-
CLOB
public static final int CLOB- See Also:
- Constant Field Values
-
BLOB
public static final int BLOB- See Also:
- Constant Field Values
-
JAVA_OBJECT
public static final int JAVA_OBJECT- See Also:
- Constant Field Values
-
TIMESTAMP
public static final int TIMESTAMP- See Also:
- Constant Field Values
-
DATE
public static final int DATE- See Also:
- Constant Field Values
-
DECIMAL
public static final int DECIMAL- See Also:
- Constant Field Values
-
dataTypes
-
-
Constructor Details
-
DataTypes
public DataTypes()
-
-
Method Details
-
setSQLTypes
public static void setSQLTypes(java.util.HashMap<java.lang.Integer,java.lang.String> map) -
getType
-
getType
-
getTypeForSQLStr
-
getTypeForSQL
Returns aDataType
for the given SQL type (fromTypes
).- Parameters:
SQLType
-- Returns:
-
getSize
Returns the number of bytes required to store a value of DataTypetype
.- Parameters:
type
-- Returns:
-
getSizeForType
public static int getSizeForType(int type)Returns the number of bytes required to store a value of DataType valuetype
.- Parameters:
type
-- Returns:
-
getSizeForSQLType
public static int getSizeForSQLType(int type)Returns the number of bytes required to store a value of the SQL typetype
.- Parameters:
type
-- Returns:
-
getTypeForSize
-
getSQLTypeObject
public static java.lang.Object getSQLTypeObject(int dataType) -
getMappedSQLTypeDBMStoJDBC
public static int getMappedSQLTypeDBMStoJDBC(int dataType, java.lang.String driverStr)Return data type mapped to particular driver (for non-standard types) from DBMS type to JDBC type- Parameters:
dataType
- DBMS typedriverStr
- The driver URL as aString
- Returns:
dataType
mapped to the JDBC type
-
getMappedSQLTypeJDBCtoDBMS
public static int getMappedSQLTypeJDBCtoDBMS(int dataType, java.lang.String driverStr) -
getSQLTypeLabel
public static java.lang.String getSQLTypeLabel(int SQLType) -
getSQLTypeStr
public static java.lang.String getSQLTypeStr(int SQLType) -
getSQLTypeStr
public static java.lang.String getSQLTypeStr(int SQLType, int length) -
getSQLStrValue
public static int getSQLStrValue(java.lang.String typeStr)Returns the equivalent integer value (fromTypes
for the given type string.- Parameters:
typeStr
-- Returns:
-
isComparable
public static boolean isComparable(int dataType) -
isType
public static boolean isType(java.lang.Object obj, int type) -
getInstanceForValue
public static java.lang.Object getInstanceForValue(java.lang.Object value, int data_type) throws DataSourceExceptionConverts a value from aString
to an instance of the specified type.- Parameters:
value
-data_type
-- Returns:
- Throws:
DataSourceException
- - Ifvalue
cannot be converted to the specified type
-
guessDataType
public static int guessDataType(java.lang.String token)Returns a best guess for the data type of the given string.- Parameters:
token
-- Returns:
-
getSQLTypeClass
public static java.lang.Class getSQLTypeClass(int dataType)Return the class of given data type- Parameters:
dataType
-- Returns:
-
getDataBufferType
-
getFromDataBufferType
-
getDataBufferType
public static int getDataBufferType(java.lang.String type) -
getDataBufferTypeStr
public static java.lang.String getDataBufferTypeStr(int type) -
isNumeric
public static boolean isNumeric(int sqlType)Determines whether a given SQL type is numeric- Parameters:
sqlType
-- Returns:
-
isText
public static boolean isText(int sqlType)Determines whether a given SQL type is text- Parameters:
sqlType
-- Returns:
-
isText
Determines whether a given data type is text- Parameters:
sqlType
-- Returns:
-
getDataTypeList
Returns a sorted list of strings representing data types as specified in the setDataTypes method- Returns:
- sorted ArrayList of strings
-