org.clazzes.jdbc2xml.schema.impl
Class MySQLDialect

java.lang.Object
  extended by org.clazzes.jdbc2xml.schema.impl.MySQLDialect
All Implemented Interfaces:
Dialect

public class MySQLDialect
extends java.lang.Object
implements Dialect

This class implements Dialect for MySQL 5.0.x

Author:
lech

Field Summary
static java.lang.String defaultDriverName
           
 
Constructor Summary
MySQLDialect()
           
 
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()
           
 java.lang.String getID()
           
 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(SqlCommandQueue queue, TableInfo ti, ColumnInfo oldColumnInfo, ColumnInfo newColumnInfo)
          Rename and change the datatype of a database column.
 void pushCreateTable(SqlCommandQueue queue, TableInfo ti)
          Push the create table command to a command queue.
 void pushDropColumn(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(SqlCommandQueue queue, TableInfo ti, boolean force)
          Push the drop table command to a command queue.
 void pushModifyColumn(SqlCommandQueue queue, TableInfo ti, ColumnInfo oldColumnInfo, ColumnInfo newColumnInfo)
          Modify the datatype of a database column.
 void quoteString(java.lang.StringBuffer sb, java.lang.String s)
          Quote the given string to the string buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultDriverName

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

MySQLDialect

public MySQLDialect()
Method Detail

getID

public java.lang.String getID()
Specified by:
getID in interface Dialect
Returns:
A descriptive ID of the dialect, which contains no whitespace characters.

pushCreateTable

public void pushCreateTable(SqlCommandQueue queue,
                            TableInfo ti)
Description copied from interface: Dialect
Push the create table command to a command queue.

Specified by:
pushCreateTable in interface Dialect
Parameters:
queue - The queue to push to.
ti - The table info for which to push the create table command.

pushDropTable

public void pushDropTable(SqlCommandQueue queue,
                          TableInfo ti,
                          boolean force)
Description copied from interface: Dialect
Push the drop table command to a command queue.

Specified by:
pushDropTable in interface Dialect
Parameters:
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.

createColumnSpec

public java.lang.String createColumnSpec(ColumnInfo columnInfo)
Description copied from interface: Dialect
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.

Specified by:
createColumnSpec in interface Dialect
Returns:
a string to feed a CREATE TABLE or ALTER TABLE ADD COLUMN statement, or null

defaultDriverName

public java.lang.String defaultDriverName()
Specified by:
defaultDriverName in interface Dialect
Returns:
the default driver name for this dialect

quoteString

public void quoteString(java.lang.StringBuffer sb,
                        java.lang.String s)
Description copied from interface: Dialect
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.

Specified by:
quoteString in interface Dialect
Parameters:
sb - The buffer to write to.
s - the String to quote.

normalizeDefaultValue

public java.lang.String normalizeDefaultValue(int type,
                                              java.lang.String s)
Description copied from interface: Dialect
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.

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

pushAddForeignKey

public void pushAddForeignKey(SqlCommandQueue queue,
                              TableInfo ti,
                              ForeignKeyInfo fki)
                       throws java.sql.SQLException
Description copied from interface: Dialect
Push the add foreign key command to a command queue.

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

pushDropForeignKey

public void pushDropForeignKey(SqlCommandQueue queue,
                               TableInfo ti,
                               ForeignKeyInfo fki)
                        throws java.sql.SQLException
Description copied from interface: Dialect
Push the drop foreign key command to a command queue.

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

pushAddIndex

public void pushAddIndex(SqlCommandQueue queue,
                         TableInfo ti,
                         IndexInfo indexInfo)
                  throws java.sql.SQLException
Description copied from interface: Dialect
Push the add index command to a command queue.

Specified by:
pushAddIndex in interface Dialect
Parameters:
queue - The queue to push to.
ti - The table info for which to push the add index command.
indexInfo - The index description.
Throws:
java.sql.SQLException

pushDropIndex

public void pushDropIndex(SqlCommandQueue queue,
                          TableInfo ti,
                          IndexInfo indexInfo)
                   throws java.sql.SQLException
Description copied from interface: Dialect
Push the drop index command to a command queue.

Specified by:
pushDropIndex in interface Dialect
Parameters:
queue - The queue to push to.
ti - The table info for which to push the drop index command.
indexInfo - The index description.
Throws:
java.sql.SQLException

pushAddColumn

public void pushAddColumn(SqlCommandQueue queue,
                          TableInfo ti,
                          ColumnInfo ci)
                   throws java.sql.SQLException
Description copied from interface: Dialect
Push the add column command to a command queue.

Specified by:
pushAddColumn in interface Dialect
Parameters:
queue - The queue to push to.
ti - The table info for which to push the add column command.
ci - The column description.
Throws:
java.sql.SQLException

pushDropColumn

public void pushDropColumn(SqlCommandQueue queue,
                           TableInfo ti,
                           ColumnInfo ci,
                           boolean force)
                    throws java.sql.SQLException
Description copied from interface: Dialect
Push the drop column command to a command queue.

Specified by:
pushDropColumn in interface Dialect
Parameters:
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

pushChangeColumn

public void pushChangeColumn(SqlCommandQueue queue,
                             TableInfo ti,
                             ColumnInfo oldColumnInfo,
                             ColumnInfo newColumnInfo)
                      throws java.sql.SQLException
Description copied from interface: Dialect
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.

Specified by:
pushChangeColumn in interface Dialect
Parameters:
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

pushModifyColumn

public void pushModifyColumn(SqlCommandQueue queue,
                             TableInfo ti,
                             ColumnInfo oldColumnInfo,
                             ColumnInfo newColumnInfo)
                      throws java.sql.SQLException
Description copied from interface: Dialect
Modify the datatype of a database column. The calling engine asserts, that the old column name is identical to the new column name.

Specified by:
pushModifyColumn in interface Dialect
Parameters:
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

constructJDBCURL

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

Specified by:
constructJDBCURL in interface Dialect
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.


Copyright © 2007. All Rights Reserved.