org.clazzes.jdbc2xml.schema.impl
Class DDLHelper

java.lang.Object
  extended by org.clazzes.jdbc2xml.schema.impl.DDLHelper

public abstract class DDLHelper
extends Object

Static helper methods to construct SQL queries for schema manipulations.

Author:
wglas

Constructor Summary
DDLHelper()
           
 
Method Summary
static String buildAddColumn(String tableName, ColumnInfo ci, Dialect dialect, String addColumnCommand, boolean addStmtInBrackets)
           
static String buildAddForeignKey(String tableName, ForeignKeyInfo foreignKeyInfo, boolean addStmtInBrackets)
           
static String buildAddIndex(TableInfo ti, IndexInfo indexInfo, boolean allowsMultipleNullsInUniqueIndizes)
           
static String buildCreateTable(TableInfo ti, Dialect dialect, String suffix)
          Construct a create table statement.
static String buildDropColumn(String tableName, String columnName)
           
static String buildDropForeignKey(String tableName, String foreignKeyName, String dropForeignKeyCommand)
           
static String buildDropIndex(String tableName, String indexName, boolean needsOnTableSuffix)
           
static String buildDropTable(String tableName)
          Build a drop table statement.
static String buildHexSuffix()
           
static SqlCommand buildRenameTable(String renameTableCommand, String tableName, String newTableName)
          Generate a rename table command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DDLHelper

public DDLHelper()
Method Detail

buildCreateTable

public static String buildCreateTable(TableInfo ti,
                                      Dialect dialect,
                                      String suffix)
Construct a create table statement.

Parameters:
ti - the table information.
dialect - The dialect for creating column specs.
suffix - An RDBMS-specific suffix, which will be appended after the create table clause.
Returns:
A string, which carries the create table statement.

buildDropTable

public static String buildDropTable(String tableName)
Build a drop table statement.

Parameters:
tableName - The name of the table to drop.
Returns:
The SQL statement to drop the table.

buildAddIndex

public static String buildAddIndex(TableInfo ti,
                                   IndexInfo indexInfo,
                                   boolean allowsMultipleNullsInUniqueIndizes)
                            throws SQLException
Parameters:
ti - the table information.
indexInfo - The description of the index to be created.
allowsMultipleNullsInUniqueIndizes - Specifies if a UNIQUE INDEX may contain multiple NULL values. If false, INDEXes for NULLable columns must be created non-UNIQUE.
Returns:
The SQL statement to add the index.
Throws:
SQLException - If the index does not contain a name.

buildDropIndex

public static String buildDropIndex(String tableName,
                                    String indexName,
                                    boolean needsOnTableSuffix)
                             throws SQLException
Parameters:
tableName - The name of the table on which to drop the index.
indexName - The name of the index to drop.
needsOnTableSuffix - Specifies if DROP INDEX needs (or at least allows) the ON tableName suffix
Returns:
The SQL statement to drop the index.
Throws:
SQLException - If the index does not contain a name.

buildAddForeignKey

public static String buildAddForeignKey(String tableName,
                                        ForeignKeyInfo foreignKeyInfo,
                                        boolean addStmtInBrackets)
                                 throws SQLException
Parameters:
tableName - The name of the table on which to add a foreign key.
foreignKeyInfo - The description of the foreign key.
addStmtInBrackets - true will produce ADD (statement), false for: ADD statement.
Returns:
The SQL statement to create the foreign key.
Throws:
SQLException - If the foreign key uses unimplemented features.

buildDropForeignKey

public static String buildDropForeignKey(String tableName,
                                         String foreignKeyName,
                                         String dropForeignKeyCommand)
Parameters:
tableName - The name of the table on which to add a foreign key.
foreignKeyName - The name of the foreign key to drop.
dropForeignKeyCommand - The RDBMS-specific command after ALTER TABLE needed to drop a foreign key.
Returns:
The SQL statement to create the foreign key.

buildAddColumn

public static String buildAddColumn(String tableName,
                                    ColumnInfo ci,
                                    Dialect dialect,
                                    String addColumnCommand,
                                    boolean addStmtInBrackets)
Parameters:
tableName - the table name.
ci - The description of the column to be created.
dialect - The dialect for creating column specs.
addColumnCommand - The RDBMS specific command after ALTER TABLER for adding a column.
Returns:
The SQL statement to add the column.

buildDropColumn

public static String buildDropColumn(String tableName,
                                     String columnName)
Parameters:
tableName - The name of the table on which to drop the column.
columnName - The name of the column to drop.
Returns:
The SQL statement to drop the column.

buildRenameTable

public static SqlCommand buildRenameTable(String renameTableCommand,
                                          String tableName,
                                          String newTableName)
Generate a rename table command. Please note, that only some RDBMS engines support renaming tables.

Parameters:
renameTableComman - The dialect specific command to rename a table, which must contain two %s placeholders, the first one for the original table name, second one for the new table name. If set to null, the ISO SQL command RENAME TABLE %s TO %s is used for renaming the table.
tableName - The name of the table which will be renamed.
newTableName - The name of the table after renaming.
Returns:
The SQL command to rename the table.

buildHexSuffix

public static String buildHexSuffix()
Returns:
An 8-digit hexadecimal suffix build from a hash of the urrent system time, which is used to arbitrate object names created by jdbc2xml.


Copyright © 2011. All Rights Reserved.