org.clazzes.jdbc2xml.schema.impl
Class DDLHelper

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

public abstract class DDLHelper
extends java.lang.Object

Static helper methods to construct SQL queries for schema manipulations.

Author:
wglas

Constructor Summary
DDLHelper()
           
 
Method Summary
static java.lang.String buildAddColumn(java.lang.String tableName, ColumnInfo ci, Dialect dialect, java.lang.String addColumnCommand)
           
static java.lang.String buildAddForeignKey(java.lang.String tableName, ForeignKeyInfo foreignKeyInfo)
           
static java.lang.String buildAddIndex(TableInfo ti, IndexInfo indexInfo, boolean allowsMultipleNullsInUniqueIndizes)
           
static java.lang.String buildCreateTable(TableInfo ti, Dialect dialect, java.lang.String suffix)
          Construct a create table statement.
static java.lang.String buildDropColumn(java.lang.String tableName, java.lang.String columnName)
           
static java.lang.String buildDropForeignKey(java.lang.String tableName, java.lang.String foreignKeyName, java.lang.String dropForeignKeyCommand)
           
static java.lang.String buildDropIndex(java.lang.String tableName, java.lang.String indexName, boolean needsOnTableSuffix)
           
static java.lang.String buildDropTable(java.lang.String tableName)
          Build a drop table statement.
static java.lang.String buildHexSuffix()
           
static java.lang.String buildRenameTable(java.lang.String tableName, java.lang.String newTableName)
          Generate a rename table statement.
 
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 java.lang.String buildCreateTable(TableInfo ti,
                                                Dialect dialect,
                                                java.lang.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 java.lang.String buildDropTable(java.lang.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 java.lang.String buildAddIndex(TableInfo ti,
                                             IndexInfo indexInfo,
                                             boolean allowsMultipleNullsInUniqueIndizes)
                                      throws java.sql.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:
java.sql.SQLException - If the index does not contain a name.

buildDropIndex

public static java.lang.String buildDropIndex(java.lang.String tableName,
                                              java.lang.String indexName,
                                              boolean needsOnTableSuffix)
                                       throws java.sql.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:
java.sql.SQLException - If the index does not contain a name.

buildAddForeignKey

public static java.lang.String buildAddForeignKey(java.lang.String tableName,
                                                  ForeignKeyInfo foreignKeyInfo)
                                           throws java.sql.SQLException
Parameters:
tableName - The name of the table on which to add a foreign key.
foreignKeyInfo - The description of the foreign key.
Returns:
The SQL statement to create the foreign key.
Throws:
java.sql.SQLException - If the foreign key uses unimplemented features.

buildDropForeignKey

public static java.lang.String buildDropForeignKey(java.lang.String tableName,
                                                   java.lang.String foreignKeyName,
                                                   java.lang.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 java.lang.String buildAddColumn(java.lang.String tableName,
                                              ColumnInfo ci,
                                              Dialect dialect,
                                              java.lang.String addColumnCommand)
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 java.lang.String buildDropColumn(java.lang.String tableName,
                                               java.lang.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 java.lang.String buildRenameTable(java.lang.String tableName,
                                                java.lang.String newTableName)
Generate a rename table statement. Please note, that only some RDBMS engines support renaming tables.

Parameters:
tableName - The name of the table which will be renamed.
newTableName - The name of the table after renaming.
Returns:
The SQL statement to rename the table.

buildHexSuffix

public static java.lang.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 © 2007. All Rights Reserved.