com.scooterframework.orm.sqldataexpress.util
Class SqlUtil

java.lang.Object
  extended by com.scooterframework.orm.sqldataexpress.util.SqlUtil

public class SqlUtil
extends java.lang.Object

SqlUtil class has methods for general SQL processing and SQL related type conversion.


Field Summary
static java.lang.String JOIN_RELATION_AND
           
static java.lang.String JOIN_RELATION_OR
           
static java.lang.String REPLACE_PART_END
           
static java.lang.String REPLACE_PART_START
           
static java.lang.String REPLACEMENT_KEY
           
 
Constructor Summary
SqlUtil()
           
 
Method Summary
static java.lang.String buildDynamicSQLJoinStringForLike(java.lang.String original, java.util.List<java.lang.String> words, java.lang.String joinType)
          Builds a string of SQL like string.
static java.lang.String buildDynamicSQLJoinStringForLike(java.lang.String original, java.lang.String words, java.lang.String joinType)
          Builds a string of SQL like string.
static java.sql.Date convertStringToSQLDate(java.lang.String dateStr)
           
static java.sql.Time convertStringToSQLTime(java.lang.String dateStr)
           
static java.sql.Timestamp convertStringToSQLTimestamp(java.lang.String dateStr)
           
static java.lang.String convertToUpperCase(java.lang.String sql)
          Converts to upper case except for characters inside single quote.
static void copyData(RowData fromRowData, RowData toRowData)
          copies data from one row to another
static java.lang.String getGroupBy(java.util.Map<java.lang.String,java.lang.String> options)
          Constructs GROUP BY clause in a SQL statement.
static java.lang.String getHaving(java.util.Map<java.lang.String,java.lang.String> options)
          Constructs HAVING clause in a SQL statement.
static java.lang.String getJavaType(int sqlDataType)
          Converts from SQL data type to Java class type.
static java.lang.String getOrderBy(java.util.Map<java.lang.String,?> options)
          Constructs ORDER BY clause in a SQL statement.
static int getSqlDataTypeFromDataTypeName(java.lang.String sqlDataTypeName)
          Returns a SQL data type int for a SQL data type name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REPLACE_PART_START

public static final java.lang.String REPLACE_PART_START
See Also:
Constant Field Values

REPLACE_PART_END

public static final java.lang.String REPLACE_PART_END
See Also:
Constant Field Values

JOIN_RELATION_OR

public static final java.lang.String JOIN_RELATION_OR
See Also:
Constant Field Values

JOIN_RELATION_AND

public static final java.lang.String JOIN_RELATION_AND
See Also:
Constant Field Values

REPLACEMENT_KEY

public static final java.lang.String REPLACEMENT_KEY
See Also:
Constant Field Values
Constructor Detail

SqlUtil

public SqlUtil()
Method Detail

getSqlDataTypeFromDataTypeName

public static int getSqlDataTypeFromDataTypeName(java.lang.String sqlDataTypeName)

Returns a SQL data type int for a SQL data type name.

Developers can add types. See DatabaseConfig class for examples.

Parameters:
sqlDataTypeName - data type name
Returns:
SQL data type int

getJavaType

public static java.lang.String getJavaType(int sqlDataType)
Converts from SQL data type to Java class type. Here is a list of presumed Java class name and its corresponding SQL data type:
  java.sql.Array         public static final int ARRAY 2003
  java.lang.Long         public static final int BIGINT -5
  byte[]                 public static final int BINARY -2
  java.lang.Boolean      public static final int BIT -7
  java.sql.Blob          public static final int BLOB 2004
  java.lang.Boolean      public static final int BOOLEAN 16
  java.lang.String       public static final int CHAR 1
  java.sql.Clob          public static final int CLOB 2005
  java.lang.Object       public static final int DATALINK 70
  java.sql.Timestamp     public static final int DATE 91
  java.lang.BigDecimal   public static final int DECIMAL 3
  java.lang.Object       public static final int DISTINCT 2001
  java.lang.Double       public static final int DOUBLE 8
  java.lang.Double       public static final int FLOAT 6
  java.lang.Integer      public static final int INTEGER 4
  java.lang.Object       public static final int JAVA_OBJECT 2000
  java.lang.String       public static final int LONGNVARCHAR -16
  byte[]                 public static final int LONGVARBINARY -4
  java.lang.String       public static final int LONGVARCHAR -1
  java.lang.String       public static final int NCHAR -15
  java.sql.Clob          public static final int NCLOB 2011
  java.lang.Object       public static final int NULL 0
  java.lang.BigDecimal   public static final int NUMERIC 2
  java.lang.String       public static final int NVARCHAR -9
  java.lang.Object       public static final int OTHER 1111
  java.lang.Double       public static final int REAL 7
  java.sql.Ref           public static final int REF 2006
  java.lang.Integer      public static final int ROWID -8
  java.lang.Integer      public static final int SMALLINT 5
  java.sql.String        public static final int SQLXML 2009
  java.sql.Struct        public static final int STRUCT 2002
  java.sql.Time          public static final int TIME 92
  java.sql.Timestamp     public static final int TIMESTAMP 93
  java.lang.Integer      public static final int TINYINT -6
  byte[]                 public static final int VARBINARY -3
  java.lang.String       public static final int VARCHAR 12
 
The following types are simply converted to "java.lang.Object":

Default java type is "java.lang.Object".

Developers can add types. See DatabaseConfig class for examples.

Parameters:
sqlDataType - SQL data type from java.sql.Types
Returns:
The Java class type name.

buildDynamicSQLJoinStringForLike

public static java.lang.String buildDynamicSQLJoinStringForLike(java.lang.String original,
                                                                java.lang.String words,
                                                                java.lang.String joinType)
Builds a string of SQL like string. Example: original string: "lower(category) like $keyword$" words string: "dog, cat, fish" joinType: OR converted string: "lower(category) like '%dog%' OR lower(category) like '%cat%' OR lower(category) like '%fish%'"

Parameters:
words - a string of words separated by either space or comma
Returns:
string of SQL like type

buildDynamicSQLJoinStringForLike

public static java.lang.String buildDynamicSQLJoinStringForLike(java.lang.String original,
                                                                java.util.List<java.lang.String> words,
                                                                java.lang.String joinType)
Builds a string of SQL like string. Example: original string: "lower(category) like $keyword$" words list: "{dog, cat, fish}" joinType: OR converted string: "lower(category) like '%dog%' OR lower(category) like '%cat%' OR lower(category) like '%fish%'"

Parameters:
words - a string of words separated by either space or comma
Returns:
string of SQL like type

convertStringToSQLDate

public static java.sql.Date convertStringToSQLDate(java.lang.String dateStr)

convertStringToSQLTime

public static java.sql.Time convertStringToSQLTime(java.lang.String dateStr)

convertStringToSQLTimestamp

public static java.sql.Timestamp convertStringToSQLTimestamp(java.lang.String dateStr)

convertToUpperCase

public static java.lang.String convertToUpperCase(java.lang.String sql)
Converts to upper case except for characters inside single quote.

Parameters:
sql - original SQL query string
Returns:
String in upper case

copyData

public static void copyData(RowData fromRowData,
                            RowData toRowData)
copies data from one row to another


getOrderBy

public static java.lang.String getOrderBy(java.util.Map<java.lang.String,?> options)
Constructs ORDER BY clause in a SQL statement. Empty string is returned if there is no options for this clause.

Parameters:
options -
Returns:
a SQL fragment

getGroupBy

public static java.lang.String getGroupBy(java.util.Map<java.lang.String,java.lang.String> options)
Constructs GROUP BY clause in a SQL statement. Empty string is returned if there is no options for this clause.

Parameters:
options -
Returns:
a SQL fragment

getHaving

public static java.lang.String getHaving(java.util.Map<java.lang.String,java.lang.String> options)
Constructs HAVING clause in a SQL statement. Empty string is returned if there is no options for this clause.

Parameters:
options -
Returns:
a SQL fragment