com.googlecode.jdbw.server
Class DefaultSQLDialect

java.lang.Object
  extended by com.googlecode.jdbw.server.DefaultSQLDialect
All Implemented Interfaces:
SQLDialect
Direct Known Subclasses:
H2SQLDialect, SybaseASESQLDialect

public class DefaultSQLDialect
extends Object
implements SQLDialect

A default implementation of SQLDialect providing some functionality which is common to most database servers.

Author:
Martin Berglund

Constructor Summary
DefaultSQLDialect()
           
 
Method Summary
protected  Object createExampleObject(int sqlType)
           
 String escapeIdentifier(String identifier)
          Takes the name of a database object (table, column, etc) and returns the name wrapped in characters that marks it's an identifier.
 String escapeString(String string)
          Returns a string with all special characters replaced with their proper escape sequences.
protected  String formatBinary(Object value)
           
protected  String formatBoolean(Object value)
           
 String formatDate(Date date)
          Formats a java Date into the preferred date string format for this database server type, probably YYYY-MM-DD
protected  String formatDate(Object value)
           
 String formatDateTime(Date date)
          Formats a java Date into the preferred date time string format for this database server type, probably YYYY-MM-DD HH:MM:SS.ZZZ
protected  String formatDatetime(Object value)
           
protected  String formatDecimal(Object value)
           
protected  String formatFloatingPoint(Object value)
           
protected  String formatInteger(Object value)
           
protected  String formatString(Object value)
           
 String formatTime(Date date)
          Formats a java Date into the preferred time string format for this database server type, probably HH:MM:SS.ZZZ
protected  String formatTime(Object value)
           
 String formatValue(Object value, int targetType)
          Formats a generic object into a String that can be inserted into a dynamically constructed SQL statement.
 String[] getCreateTableStatement(String schemaName, String name, List<Column> columns, List<Index> indexes)
           
 String getDropTableStatement(String catalog, String schema, String tableName)
           
 String getSingleLineCommentPrefix()
           
static boolean isBigDecimal(int sqlType)
           
static boolean isBinary(int sqlType)
           
static boolean isBoolean(int sqlType)
           
 boolean isCompatible(int fromSqlType, int toSqlType)
           
static boolean isDate(int sqlType)
           
static boolean isDatetime(int sqlType)
           
static boolean isFloatingPoint(int sqlType)
           
static boolean isInteger(int sqlType)
           
static boolean isString(int sqlType)
           
static boolean isTime(int sqlType)
           
 Object safeType(Column targetColumn, Object object)
          Attempts to convert a particular value to an acceptable format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultSQLDialect

public DefaultSQLDialect()
Method Detail

escapeString

public String escapeString(String string)
Description copied from interface: SQLDialect
Returns a string with all special characters replaced with their proper escape sequences. You don't need to do this for strings passed in as parameters, since the JDBC driver will do it for you.

Specified by:
escapeString in interface SQLDialect
Parameters:
string - String to convert
Returns:
The original string with special characters escaped

escapeIdentifier

public String escapeIdentifier(String identifier)
Description copied from interface: SQLDialect
Takes the name of a database object (table, column, etc) and returns the name wrapped in characters that marks it's an identifier. Use this if, for example, your column names may be colliding with keywords on the server.

Specified by:
escapeIdentifier in interface SQLDialect
Parameters:
identifier - string to wrapp
Returns:
The input string wrapped as an identifier

formatDateTime

public String formatDateTime(Date date)
Description copied from interface: SQLDialect
Formats a java Date into the preferred date time string format for this database server type, probably YYYY-MM-DD HH:MM:SS.ZZZ

Specified by:
formatDateTime in interface SQLDialect
Returns:
Date formatted as a string

formatDate

public String formatDate(Date date)
Description copied from interface: SQLDialect
Formats a java Date into the preferred date string format for this database server type, probably YYYY-MM-DD

Specified by:
formatDate in interface SQLDialect
Parameters:
date - Date to format
Returns:
Date formatted as a string

formatTime

public String formatTime(Date date)
Description copied from interface: SQLDialect
Formats a java Date into the preferred time string format for this database server type, probably HH:MM:SS.ZZZ

Specified by:
formatTime in interface SQLDialect
Parameters:
date - Date to format
Returns:
Date formatted as a string

formatValue

public String formatValue(Object value,
                          int targetType)
Description copied from interface: SQLDialect
Formats a generic object into a String that can be inserted into a dynamically constructed SQL statement. You'll need to supply the type you want the value to be in the database context through the targetType parameter. Note: Throws IllegalArgumentException is the objects cannot be formatted

Specified by:
formatValue in interface SQLDialect
Parameters:
value - Value to be formatted
targetType - java.sql.Types constant of the type you want to format the value as
Returns:
String with the value formatted as the specified type

getCreateTableStatement

public String[] getCreateTableStatement(String schemaName,
                                        String name,
                                        List<Column> columns,
                                        List<Index> indexes)
Specified by:
getCreateTableStatement in interface SQLDialect

getDropTableStatement

public String getDropTableStatement(String catalog,
                                    String schema,
                                    String tableName)
Specified by:
getDropTableStatement in interface SQLDialect

getSingleLineCommentPrefix

public String getSingleLineCommentPrefix()
Specified by:
getSingleLineCommentPrefix in interface SQLDialect
Returns:
What to put in front of a line to comment it out

isCompatible

public boolean isCompatible(int fromSqlType,
                            int toSqlType)
Specified by:
isCompatible in interface SQLDialect
Returns:
True if this database can convert data of type fromSqlType to type toSqlType

safeType

public Object safeType(Column targetColumn,
                       Object object)
Description copied from interface: SQLDialect
Attempts to convert a particular value to an acceptable format. Given a column on the server and the value we want to put into this column, the method will try to convert the value into a format that is compatible with the column.

Specified by:
safeType in interface SQLDialect
Parameters:
targetColumn - Column we want to insert into
object - Object to insert
Returns:
A compatible value for the target column

createExampleObject

protected Object createExampleObject(int sqlType)

isBigDecimal

public static boolean isBigDecimal(int sqlType)

isBoolean

public static boolean isBoolean(int sqlType)

isFloatingPoint

public static boolean isFloatingPoint(int sqlType)

isString

public static boolean isString(int sqlType)

isInteger

public static boolean isInteger(int sqlType)

isDatetime

public static boolean isDatetime(int sqlType)

isDate

public static boolean isDate(int sqlType)

isTime

public static boolean isTime(int sqlType)

isBinary

public static boolean isBinary(int sqlType)

formatDecimal

protected String formatDecimal(Object value)

formatBoolean

protected String formatBoolean(Object value)

formatFloatingPoint

protected String formatFloatingPoint(Object value)

formatString

protected String formatString(Object value)

formatInteger

protected String formatInteger(Object value)

formatDatetime

protected String formatDatetime(Object value)

formatDate

protected String formatDate(Object value)

formatTime

protected String formatTime(Object value)

formatBinary

protected String formatBinary(Object value)


Copyright © 2012. All Rights Reserved.