net.sf.hajdbc.dialect
Class StandardDialect

java.lang.Object
  extended by net.sf.hajdbc.dialect.StandardDialect
All Implemented Interfaces:
Dialect
Direct Known Subclasses:
DB2Dialect, DerbyDialect, FirebirdDialect, H2Dialect, HSQLDBDialect, IngresDialect, MaxDBDialect, MckoiDialect, MySQLDialect, OracleDialect, PostgreSQLDialect, SybaseDialect

public class StandardDialect
extends Object
implements Dialect

Since:
1.1
Author:
Paul Ferraro

Constructor Summary
StandardDialect()
           
 
Method Summary
protected  String alterIdentityColumnFormat()
           
protected  String alterSequenceFormat()
           
protected  String createForeignKeyConstraintFormat()
           
protected  String createUniqueConstraintFormat()
           
protected  String currentDatePattern()
           
protected  String currentTimePattern()
           
protected  String currentTimestampFunction()
           
protected  String currentTimestampPattern()
           
protected  String dateLiteralFormat()
           
protected  String dropConstraintFormat()
           
protected  String dropForeignKeyConstraintFormat()
           
protected  String dropUniqueConstraintFormat()
           
protected  String dummyTable()
           
 String evaluateCurrentDate(String sql, Date date)
          Replaces non-deterministic CURRENT_DATE functions with deterministic static values.
 String evaluateCurrentTime(String sql, Time time)
          Replaces non-deterministic CURRENT_TIME functions with deterministic static values.
 String evaluateCurrentTimestamp(String sql, Timestamp timestamp)
          Replaces non-deterministic CURRENT_TIMESTAMP functions with deterministic static values.
 String evaluateRand(String sql)
          Replaces non-deterministic RAND() functions with deterministic static values.
protected  String executeFunction(Connection connection, String function)
           
protected  String executeFunctionFormat()
           
protected  String executeFunctionSQL(String function)
           
protected  List<String> executeQuery(Connection connection, String sql)
           
 String getAlterIdentityColumnSQL(TableProperties table, ColumnProperties column, long value)
          Returns a SQL statement used reset the current value of an identity column.
 String getAlterSequenceSQL(SequenceProperties sequence, long value)
          Returns a SQL statement used reset the current value of a sequence.
 int getColumnType(ColumnProperties properties)
          Returns the data type of the specified column of the specified schema and table.
 String getCreateForeignKeyConstraintSQL(ForeignKeyConstraint key)
          Returns a SQL statement used to create a foreign key constraint.
 String getCreateUniqueConstraintSQL(UniqueConstraint constraint)
          Returns a SQL statement used to create a unique constraint.
 List<String> getDefaultSchemas(DatabaseMetaData metaData)
          Returns a search path of schemas
 String getDropForeignKeyConstraintSQL(ForeignKeyConstraint key)
          Returns a SQL statement used to drop a foreign key constraint.
 String getDropUniqueConstraintSQL(UniqueConstraint constraint)
          Returns a SQL statement used to drop a unique constraint.
 Pattern getIdentifierPattern(DatabaseMetaData metaData)
          Returns a pattern for identifiers that do not require quoting
 String getNextSequenceValueSQL(SequenceProperties sequence)
          Returns a SQL statement for obtaining the next value the specified sequence
 Collection<QualifiedName> getSequences(DatabaseMetaData metaData)
          Returns a collection of all sequences in this database.
 String getSimpleSQL()
          Returns a simple SQL statement used to validate whether a database is alive or not.
 String getTruncateTableSQL(TableProperties properties)
          Returns a SQL statement used to truncate a table.
protected  String insertIntoTablePattern()
           
 boolean isIdentity(ColumnProperties properties)
          Indicates whether or not the specified column is an identity column.
 boolean isSelectForUpdate(String sql)
          Determines whether the specified SQL is a SELECT ...
protected  String nextSequenceValueFormat()
           
protected  String parse(Pattern pattern, String string)
           
 String parseInsertTable(String sql)
          Parses a table name from the specified INSERT SQL statement that may contain identity columns.
 String parseSequence(String sql)
          Parses a sequence name from the specified SQL statement.
protected  String randomPattern()
           
protected  String selectForUpdatePattern()
           
protected  String sequencePattern()
           
protected  String sequenceTableType()
           
protected  String timeLiteralFormat()
           
protected  String timestampLiteralFormat()
           
protected  String truncateTableFormat()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardDialect

public StandardDialect()
Method Detail

selectForUpdatePattern

protected String selectForUpdatePattern()

insertIntoTablePattern

protected String insertIntoTablePattern()

sequencePattern

protected String sequencePattern()

currentDatePattern

protected String currentDatePattern()

currentTimePattern

protected String currentTimePattern()

currentTimestampPattern

protected String currentTimestampPattern()

randomPattern

protected String randomPattern()

getSimpleSQL

public String getSimpleSQL()
Description copied from interface: Dialect
Returns a simple SQL statement used to validate whether a database is alive or not.

Specified by:
getSimpleSQL in interface Dialect
Returns:
a SQL statement
See Also:
Dialect.getSimpleSQL()

executeFunctionFormat

protected String executeFunctionFormat()

executeFunctionSQL

protected String executeFunctionSQL(String function)

currentTimestampFunction

protected String currentTimestampFunction()

dummyTable

protected String dummyTable()

getTruncateTableSQL

public String getTruncateTableSQL(TableProperties properties)
Description copied from interface: Dialect
Returns a SQL statement used to truncate a table.

Specified by:
getTruncateTableSQL in interface Dialect
Parameters:
properties - table meta data
Returns:
a SQL statement
See Also:
Dialect.getTruncateTableSQL(net.sf.hajdbc.TableProperties)

truncateTableFormat

protected String truncateTableFormat()

getCreateForeignKeyConstraintSQL

public String getCreateForeignKeyConstraintSQL(ForeignKeyConstraint key)
Description copied from interface: Dialect
Returns a SQL statement used to create a foreign key constraint.

Specified by:
getCreateForeignKeyConstraintSQL in interface Dialect
Parameters:
key - foreign key constraint meta data
Returns:
a SQL statement
See Also:
Dialect.getCreateForeignKeyConstraintSQL(net.sf.hajdbc.ForeignKeyConstraint)

createForeignKeyConstraintFormat

protected String createForeignKeyConstraintFormat()

getDropForeignKeyConstraintSQL

public String getDropForeignKeyConstraintSQL(ForeignKeyConstraint key)
Description copied from interface: Dialect
Returns a SQL statement used to drop a foreign key constraint.

Specified by:
getDropForeignKeyConstraintSQL in interface Dialect
Parameters:
key - foreign key constraint meta data
Returns:
a SQL statement
See Also:
Dialect.getDropForeignKeyConstraintSQL(net.sf.hajdbc.ForeignKeyConstraint)

dropForeignKeyConstraintFormat

protected String dropForeignKeyConstraintFormat()

dropConstraintFormat

protected String dropConstraintFormat()

getCreateUniqueConstraintSQL

public String getCreateUniqueConstraintSQL(UniqueConstraint constraint)
Description copied from interface: Dialect
Returns a SQL statement used to create a unique constraint.

Specified by:
getCreateUniqueConstraintSQL in interface Dialect
Parameters:
constraint - unique constraint meta data
Returns:
a SQL statement
See Also:
Dialect.getCreateUniqueConstraintSQL(net.sf.hajdbc.UniqueConstraint)

createUniqueConstraintFormat

protected String createUniqueConstraintFormat()

getDropUniqueConstraintSQL

public String getDropUniqueConstraintSQL(UniqueConstraint constraint)
Description copied from interface: Dialect
Returns a SQL statement used to drop a unique constraint.

Specified by:
getDropUniqueConstraintSQL in interface Dialect
Parameters:
constraint - unique constraint meta data
Returns:
a SQL statement
See Also:
Dialect.getDropUniqueConstraintSQL(net.sf.hajdbc.UniqueConstraint)

dropUniqueConstraintFormat

protected String dropUniqueConstraintFormat()

isIdentity

public boolean isIdentity(ColumnProperties properties)
Description copied from interface: Dialect
Indicates whether or not the specified column is an identity column.

Specified by:
isIdentity in interface Dialect
Parameters:
properties - a table column
Returns:
true, if this column is an identity column, false otherwise
See Also:
Dialect.isIdentity(net.sf.hajdbc.ColumnProperties)

isSelectForUpdate

public boolean isSelectForUpdate(String sql)
Description copied from interface: Dialect
Determines whether the specified SQL is a SELECT ... FOR UPDATE statement

Specified by:
isSelectForUpdate in interface Dialect
Parameters:
sql - a SQL statement
Returns:
true if this is a SELECT ... FOR UPDATE statement, false if it is not
See Also:
Dialect.isSelectForUpdate(java.lang.String)

parseInsertTable

public String parseInsertTable(String sql)
Description copied from interface: Dialect
Parses a table name from the specified INSERT SQL statement that may contain identity columns.

Specified by:
parseInsertTable in interface Dialect
Parameters:
sql - a SQL statement
Returns:
the name of a table, or null if this SQL statement is not an INSERT statement or this dialect does not support identity columns
See Also:
Dialect.parseInsertTable(java.lang.String)

getDefaultSchemas

public List<String> getDefaultSchemas(DatabaseMetaData metaData)
                               throws SQLException
Description copied from interface: Dialect
Returns a search path of schemas

Specified by:
getDefaultSchemas in interface Dialect
Returns:
a list of schema names
Throws:
SQLException
See Also:
Dialect.getDefaultSchemas(java.sql.DatabaseMetaData)

executeFunction

protected String executeFunction(Connection connection,
                                 String function)
                          throws SQLException
Throws:
SQLException

executeQuery

protected List<String> executeQuery(Connection connection,
                                    String sql)
                             throws SQLException
Throws:
SQLException

parseSequence

public String parseSequence(String sql)
Description copied from interface: Dialect
Parses a sequence name from the specified SQL statement.

Specified by:
parseSequence in interface Dialect
Parameters:
sql - a SQL statement
Returns:
the name of a sequence, or null if this SQL statement does not reference a sequence or this dialect does not support sequences
See Also:
Dialect.parseSequence(java.lang.String)

getColumnType

public int getColumnType(ColumnProperties properties)
Description copied from interface: Dialect
Returns the data type of the specified column of the specified schema and table. This method is intended to correct JDBC driver type mapping quirks.

Specified by:
getColumnType in interface Dialect
Parameters:
properties - table column meta data
Returns:
the JDBC data type of this column
See Also:
Dialect.getColumnType(net.sf.hajdbc.ColumnProperties)

getSequences

public Collection<QualifiedName> getSequences(DatabaseMetaData metaData)
                                       throws SQLException
Description copied from interface: Dialect
Returns a collection of all sequences in this database.

Specified by:
getSequences in interface Dialect
Parameters:
metaData - database meta data
Returns:
a collection of sequence names
Throws:
SQLException
See Also:
Dialect.getSequences(java.sql.DatabaseMetaData)

sequenceTableType

protected String sequenceTableType()

getNextSequenceValueSQL

public String getNextSequenceValueSQL(SequenceProperties sequence)
Description copied from interface: Dialect
Returns a SQL statement for obtaining the next value the specified sequence

Specified by:
getNextSequenceValueSQL in interface Dialect
Parameters:
sequence - a sequence name
Returns:
a SQL statement
See Also:
Dialect.getNextSequenceValueSQL(net.sf.hajdbc.SequenceProperties)

nextSequenceValueFormat

protected String nextSequenceValueFormat()

getAlterSequenceSQL

public String getAlterSequenceSQL(SequenceProperties sequence,
                                  long value)
Description copied from interface: Dialect
Returns a SQL statement used reset the current value of a sequence.

Specified by:
getAlterSequenceSQL in interface Dialect
Parameters:
sequence - a sequence name
value - a sequence value
Returns:
a SQL statement
See Also:
Dialect.getAlterSequenceSQL(net.sf.hajdbc.SequenceProperties, long)

alterSequenceFormat

protected String alterSequenceFormat()

getAlterIdentityColumnSQL

public String getAlterIdentityColumnSQL(TableProperties table,
                                        ColumnProperties column,
                                        long value)
                                 throws SQLException
Description copied from interface: Dialect
Returns a SQL statement used reset the current value of an identity column.

Specified by:
getAlterIdentityColumnSQL in interface Dialect
Parameters:
table - a sequence name
column - a sequence name
value - a sequence value
Returns:
a SQL statement
Throws:
SQLException

alterIdentityColumnFormat

protected String alterIdentityColumnFormat()

getIdentifierPattern

public Pattern getIdentifierPattern(DatabaseMetaData metaData)
                             throws SQLException
Description copied from interface: Dialect
Returns a pattern for identifiers that do not require quoting

Specified by:
getIdentifierPattern in interface Dialect
Returns:
a regular expression pattern
Throws:
SQLException
See Also:
Dialect.getIdentifierPattern(java.sql.DatabaseMetaData)

parse

protected String parse(Pattern pattern,
                       String string)

evaluateCurrentDate

public String evaluateCurrentDate(String sql,
                                  Date date)
Description copied from interface: Dialect
Replaces non-deterministic CURRENT_DATE functions with deterministic static values.

Specified by:
evaluateCurrentDate in interface Dialect
Parameters:
sql - an SQL statement
date - the replacement date
Returns:
an equivalent deterministic SQL statement
See Also:
Dialect.evaluateCurrentDate(java.lang.String, java.sql.Date)

dateLiteralFormat

protected String dateLiteralFormat()

evaluateCurrentTime

public String evaluateCurrentTime(String sql,
                                  Time time)
Description copied from interface: Dialect
Replaces non-deterministic CURRENT_TIME functions with deterministic static values.

Specified by:
evaluateCurrentTime in interface Dialect
Parameters:
sql - an SQL statement
time - the replacement time
Returns:
an equivalent deterministic SQL statement
See Also:
Dialect.evaluateCurrentTime(java.lang.String, java.sql.Time)

timeLiteralFormat

protected String timeLiteralFormat()

evaluateCurrentTimestamp

public String evaluateCurrentTimestamp(String sql,
                                       Timestamp timestamp)
Description copied from interface: Dialect
Replaces non-deterministic CURRENT_TIMESTAMP functions with deterministic static values.

Specified by:
evaluateCurrentTimestamp in interface Dialect
Parameters:
sql - an SQL statement
timestamp - the replacement timestamp
Returns:
an equivalent deterministic SQL statement
See Also:
Dialect.evaluateCurrentTimestamp(java.lang.String, java.sql.Timestamp)

timestampLiteralFormat

protected String timestampLiteralFormat()

evaluateRand

public String evaluateRand(String sql)
Description copied from interface: Dialect
Replaces non-deterministic RAND() functions with deterministic static values.

Specified by:
evaluateRand in interface Dialect
Parameters:
sql - an SQL statement
Returns:
an equivalent deterministic SQL statement
See Also:
Dialect.evaluateRand(java.lang.String)