org.clazzes.jdbc2xml.schema
Interface Dialect

All Known Implementing Classes:
DerbyDialect, MSSQLServerDialect, MySQLDialect, OracleDialect, PostgreSQLDialect

public interface Dialect

SQL Dialects provide DBMS specific helpers to allow unified SQL commands.

Author:
lech

Method Summary
 java.lang.String constructJDBCURL(java.lang.String hostname, java.lang.Integer port, java.lang.String databaseName, java.util.Properties properties)
          Constructs a JDBC URL for the dialect; all parameters may be null, default values are used then.
 java.lang.String createColumnSpec(ColumnInfo columnInfo)
          Computes a string to feed a CREATE TABLE or ALTER TABLE ADD COLUMN statement, or returns null if the type is unsupported by the underlying DBMS or by the Dialect implementation.
 java.lang.String defaultDriverName()
           
 void fetchAdditionalColumnInfo(SchemaEngine schemaEngine, TableInfo ti, ColumnInfo ci)
          Hook to fetch additional, Dialect specific column information (e.g.
 java.lang.String getID()
           
 int getMappedSqlType(java.lang.String dialectDataType)
          Get the JDBC SQL type for a specified dialect specific type.
 java.lang.String normalizeDefaultValue(int type, java.lang.String s)
          Normalize a default value returned by DatabaseMetaData.getColumns(String, String, String, String) in the column COLUMN_DEF.
 void pushAddColumn(SqlCommandQueue queue, TableInfo ti, ColumnInfo ci)
          Push the add column command to a command queue.
 void pushAddForeignKey(SqlCommandQueue queue, TableInfo ti, ForeignKeyInfo fki)
          Push the add foreign key command to a command queue.
 void pushAddIndex(SqlCommandQueue queue, TableInfo ti, IndexInfo indexInfo)
          Push the add index command to a command queue.
 void pushChangeColumn(SchemaEngine schemaEngine, SqlCommandQueue queue, TableInfo ti, ColumnInfo oldColumnInfo, ColumnInfo newColumnInfo)
          Rename and change the datatype of a database column.
 void pushCreateTable(SchemaEngine schemaEngine, SqlCommandQueue queue, TableInfo ti)
          Push the create table command to a command queue.
 void pushDropColumn(SchemaEngine schemaEngine, SqlCommandQueue queue, TableInfo ti, ColumnInfo ci, boolean force)
          Push the drop column command to a command queue.
 void pushDropForeignKey(SqlCommandQueue queue, TableInfo ti, ForeignKeyInfo fki)
          Push the drop foreign key command to a command queue.
 void pushDropIndex(SqlCommandQueue queue, TableInfo ti, IndexInfo indexInfo)
          Push the drop index command to a command queue.
 void pushDropTable(SchemaEngine schemaEngine, SqlCommandQueue queue, TableInfo ti, boolean force)
          Push the drop table command to a command queue.
 void pushModifyColumn(SchemaEngine schemaEngine, SqlCommandQueue queue, TableInfo ti, ColumnInfo oldColumnInfo, ColumnInfo newColumnInfo)
          Modify the datatype of a database column.
 void pushRenameTable(SchemaEngine schemaEngine, SqlCommandQueue queue, TableInfo ti, java.lang.String newTableName)
          Push a rename table command to a command queue.
 void quoteString(java.lang.StringBuffer sb, java.lang.String s)
          Quote the given string to the string buffer.
 

Method Detail

getID

java.lang.String getID()
Returns:
A descriptive ID of the dialect, which contains no whitespace characters.

quoteString

void quoteString(java.lang.StringBuffer sb,
                 java.lang.String s)
Quote the given string to the string buffer. This is for occasions, where you want to build an insert statement without a placeholder in a PreparedStatement. However, using a PreparedStatemnt is highly recommended.

Parameters:
sb - The buffer to write to.
s - the String to quote.

normalizeDefaultValue

java.lang.String normalizeDefaultValue(int type,
                                       java.lang.String s)
Normalize a default value returned by DatabaseMetaData.getColumns(String, String, String, String) in the column COLUMN_DEF. Some database engines return the default value in a quoted manner, so we must perform unquoting here.

Parameters:
type - The java.sql.Types constant of the column type.
s - The string to normalize.
Returns:
The normalized default value without amy quoting.

createColumnSpec

java.lang.String createColumnSpec(ColumnInfo columnInfo)
Computes a string to feed a CREATE TABLE or ALTER TABLE ADD COLUMN statement, or returns null if the type is unsupported by the underlying DBMS or by the Dialect implementation. This string includes the column name, the database specific column type and possible NOT NULL clauses.

Parameters:
columnInfo -
Returns:
a string to feed a CREATE TABLE or ALTER TABLE ADD COLUMN statement, or null

pushCreateTable

void pushCreateTable(SchemaEngine schemaEngine,
                     SqlCommandQueue queue,
                     TableInfo ti)
                     throws java.sql.SQLException
Push the create table command to a command queue.

Parameters:
schemaEngine - The SchemaEngine.
queue - The queue to push to.
ti - The table info for which to push the create table command.
Throws:
java.sql.SQLException

pushRenameTable

void pushRenameTable(SchemaEngine schemaEngine,
                     SqlCommandQueue queue,
                     TableInfo ti,
                     java.lang.String newTableName)
                     throws java.sql.SQLException
Push a rename table command to a command queue.

Parameters:
schemaEngine - The SchemaEngine.
queue - The queue to push to.
ti - The table info for which to push the rename table command.
newTableName - The new name of the table after the rename operation.b
Throws:
java.sql.SQLException

pushDropTable

void pushDropTable(SchemaEngine schemaEngine,
                   SqlCommandQueue queue,
                   TableInfo ti,
                   boolean force)
                   throws java.sql.SQLException
Push the drop table command to a command queue.

Parameters:
schemaEngine - The SchemaEngine.
queue - The queue to push to.
ti - The table info for which to push the drop table command.
force - If set to true, the data is not backed up before dropping the table. Consequently, rollback is not supported, if force is set to true.
Throws:
java.sql.SQLException

pushAddForeignKey

void pushAddForeignKey(SqlCommandQueue queue,
                       TableInfo ti,
                       ForeignKeyInfo fki)
                       throws java.sql.SQLException
Push the add foreign key command to a command queue.

Parameters:
queue - The queue to push to.
fki - The foreign key description.
ti - The table info for which to push the add foreign key command.
Throws:
java.sql.SQLException

pushDropForeignKey

void pushDropForeignKey(SqlCommandQueue queue,
                        TableInfo ti,
                        ForeignKeyInfo fki)
                        throws java.sql.SQLException
Push the drop foreign key command to a command queue.

Parameters:
queue - The queue to push to.
fki - The foreign key description.
ti - The table info for which to push the drop foreign key command.
Throws:
java.sql.SQLException

pushAddIndex

void pushAddIndex(SqlCommandQueue queue,
                  TableInfo ti,
                  IndexInfo indexInfo)
                  throws java.sql.SQLException
Push the add index command to a command queue.

Parameters:
queue - The queue to push to.
indexInfo - The index description.
ti - The table info for which to push the add index command.
Throws:
java.sql.SQLException

pushDropIndex

void pushDropIndex(SqlCommandQueue queue,
                   TableInfo ti,
                   IndexInfo indexInfo)
                   throws java.sql.SQLException
Push the drop index command to a command queue.

Parameters:
queue - The queue to push to.
indexInfo - The index description.
ti - The table info for which to push the drop index command.
Throws:
java.sql.SQLException

pushAddColumn

void pushAddColumn(SqlCommandQueue queue,
                   TableInfo ti,
                   ColumnInfo ci)
                   throws java.sql.SQLException
Push the add column command to a command queue.

Parameters:
queue - The queue to push to.
ci - The column description.
ti - The table info for which to push the add column command.
Throws:
java.sql.SQLException

pushDropColumn

void pushDropColumn(SchemaEngine schemaEngine,
                    SqlCommandQueue queue,
                    TableInfo ti,
                    ColumnInfo ci,
                    boolean force)
                    throws java.sql.SQLException
Push the drop column command to a command queue.

Parameters:
schemaEngine - The SchemaEngine.
queue - The queue to push to.
ti - The table info for which to push the add column command.
ci - The column description.
force - f set to true, the data is not backed up before dropping the column. Consequently, rollback is not supported, if force is set to true.
Throws:
java.sql.SQLException

pushModifyColumn

void pushModifyColumn(SchemaEngine schemaEngine,
                      SqlCommandQueue queue,
                      TableInfo ti,
                      ColumnInfo oldColumnInfo,
                      ColumnInfo newColumnInfo)
                      throws java.sql.SQLException
Modify the datatype of a database column. The calling engine asserts, that the old column name is identical to the new column name.

Parameters:
schemaEngine - The SchemaEngine.
queue - The queue to push to.
ti - The description of the database table.
oldColumnInfo - The column info as represented by the current schema.
newColumnInfo - The column information carrying the column name and the new datatype.
Throws:
java.sql.SQLException

pushChangeColumn

void pushChangeColumn(SchemaEngine schemaEngine,
                      SqlCommandQueue queue,
                      TableInfo ti,
                      ColumnInfo oldColumnInfo,
                      ColumnInfo newColumnInfo)
                      throws java.sql.SQLException
Rename and change the datatype of a database column. The calling engine asserts, that the old column name is distinct from the new column name.

Parameters:
schemaEngine - The SchemaEngine.
queue - The queue to push to.
ti - The description of the database table.
oldColumnInfo - The original column info of the column to be changed.
newColumnInfo - The destination column info carrying the new column name and the new datatype.
Throws:
java.sql.SQLException

defaultDriverName

java.lang.String defaultDriverName()
Returns:
the default driver name for this dialect

constructJDBCURL

java.lang.String constructJDBCURL(java.lang.String hostname,
                                  java.lang.Integer port,
                                  java.lang.String databaseName,
                                  java.util.Properties properties)
Constructs a JDBC URL for the dialect; all parameters may be null, default values are used then.

Parameters:
hostname - Name of the host to connect to, use null get the default value "localhost" for Client/Server resp. non-net URLs for integrated engines.
port - IP port to connect to, use null to use the dialect specific default port for Client/Server resp. non-net URLs for integrated engines.
databaseName - name of the database to connect to, use null to connect w/o a certain database
properties - Properties to add to the URL, usually for tweaking the JDBC driver, may be null.
Returns:
the complete JDBC URL.

getMappedSqlType

int getMappedSqlType(java.lang.String dialectDataType)
Get the JDBC SQL type for a specified dialect specific type.

Parameters:
dialectDataType - String representation of dialect specific type.
Returns:
the mapped type as defined in Types

fetchAdditionalColumnInfo

void fetchAdditionalColumnInfo(SchemaEngine schemaEngine,
                               TableInfo ti,
                               ColumnInfo ci)
Hook to fetch additional, Dialect specific column information (e.g. auto increment).

Parameters:
schemaEngine - The calling SchemaEngine
ti - The TableInfo
ci - The ColumnInfo


Copyright © 2010. All Rights Reserved.