org.apache.ddlutils.platform.mssql
Class MSSqlBuilder

java.lang.Object
  extended byorg.apache.ddlutils.platform.SqlBuilder
      extended byorg.apache.ddlutils.platform.mssql.MSSqlBuilder

public class MSSqlBuilder
extends SqlBuilder

The SQL Builder for the Microsoft SQL Server.

Version:
$Revision: 378736 $
Author:
James Strachan, Thomas Dudziak

Field Summary
 
Fields inherited from class org.apache.ddlutils.platform.SqlBuilder
_log, SIZE_PLACEHOLDER
 
Constructor Summary
MSSqlBuilder(PlatformInfo info)
          Creates a new builder instance.
 
Method Summary
protected  void alterTable(Database currentModel, Table currentTable, Database desiredModel, Table desiredTable, boolean doDrops, boolean modifyColumns)
          Alters the given currently existing table object to match the given desired table object.
 void createTable(Database database, Table table, Map parameters)
          Outputs the DDL to create the table along with any non-external constraints as well as with external primary keys and indices (but not foreign keys).
 void dropExternalForeignKeys(Table table)
          Creates external foreignkey drop statements.
 void dropTable(Table table)
          Outputs the DDL to drop the table.
 String getDeleteSql(Table table, Map pkValues, boolean genPlaceholders)
          Creates the SQL for deleting an object from the specified table. If values are given then a concrete delete statement is created, otherwise an delete statement usable in a prepared statement is build.
 String getInsertSql(Table table, Map columnValues, boolean genPlaceholders)
          Creates the SQL for inserting an object into the specified table. If values are given then a concrete insert statement is created, otherwise an insert statement usable in a prepared statement is build.
protected  String getNativeDefaultValue(Column column)
          Returns the native default value for the column.
 String getUpdateSql(Table table, Map columnValues, boolean genPlaceholders)
          Creates the SQL for updating an object in the specified table. If values are given then a concrete update statement is created, otherwise an update statement usable in a prepared statement is build.
 void writeColumnAlterStmt(Table table, Column column, boolean isNewColumn)
          Generates the alter statement to add or modify a single column on a table.
protected  void writeColumnAutoIncrementStmt(Table table, Column column)
          Prints that the column is an auto increment column.
protected  void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey)
          Generates the statement to drop a foreignkey constraint from the database using an alter table statement.
 void writeExternalIndexDropStmt(Table table, Index index)
          Generates the statement to drop a non-embedded index from the database.
 
Methods inherited from class org.apache.ddlutils.platform.SqlBuilder
addEscapedCharSequence, alterDatabase, alterDatabase, alterDatabase, columnsDiffer, createExternalForeignKeys, createExternalForeignKeys, createTable, createTables, createTables, createTables, dropTables, escapeStringValue, getColumnName, getConstraintName, getDefaultValueHelper, getDelimitedIdentifier, getForeignKeyName, getIndent, getIndexName, getNativeType, getPlatformInfo, getSelectLastInsertId, getSqlType, getTableName, getValueAsString, getValueLocale, getWriter, print, printComment, printEndOfStatement, printIdentifier, printIndent, println, println, printlnIdentifier, printStartOfEmbeddedStatement, setIndent, setValueLocale, setWriter, shortenName, shouldGeneratePrimaryKeys, writeColumn, writeColumnDefaultValue, writeColumnDropStmt, writeColumnNotNullableStmt, writeColumnNullableStmt, writeColumns, writeEmbeddedForeignKeysStmt, writeEmbeddedIndexCreateStmt, writeEmbeddedIndicesStmt, writeEmbeddedPrimaryKeysStmt, writeExternalForeignKeyCreateStmt, writeExternalIndexCreateStmt, writeExternalIndicesCreateStmt, writeExternalPrimaryKeysCreateStmt, writeForeignReferences, writeLocalReferences, writePrimaryKeyStmt, writeTableAlterStmt, writeTableComment, writeTableCreationStmtEnding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MSSqlBuilder

public MSSqlBuilder(PlatformInfo info)
Creates a new builder instance.

Parameters:
info - The platform info
Method Detail

createTable

public void createTable(Database database,
                        Table table,
                        Map parameters)
                 throws IOException
Outputs the DDL to create the table along with any non-external constraints as well as with external primary keys and indices (but not foreign keys).

Overrides:
createTable in class SqlBuilder
Parameters:
database - The database model
table - The table
parameters - Additional platform-specific parameters for the table creation
Throws:
IOException

alterTable

protected void alterTable(Database currentModel,
                          Table currentTable,
                          Database desiredModel,
                          Table desiredTable,
                          boolean doDrops,
                          boolean modifyColumns)
                   throws IOException
Alters the given currently existing table object to match the given desired table object.

Overrides:
alterTable in class SqlBuilder
Parameters:
currentModel - The current model
currentTable - The current table definition
desiredModel - The desired model
desiredTable - The desired table definition
doDrops - Whether columns and indexes should be dropped if not in the new schema
modifyColumns - Whether columns should be altered for datatype, size as required
Throws:
IOException

dropTable

public void dropTable(Table table)
               throws IOException
Outputs the DDL to drop the table.

Overrides:
dropTable in class SqlBuilder
Parameters:
table - The table to drop
Throws:
IOException

dropExternalForeignKeys

public void dropExternalForeignKeys(Table table)
                             throws IOException
Creates external foreignkey drop statements.

Overrides:
dropExternalForeignKeys in class SqlBuilder
Parameters:
table - The table
Throws:
IOException

getNativeDefaultValue

protected String getNativeDefaultValue(Column column)
Returns the native default value for the column.

Overrides:
getNativeDefaultValue in class SqlBuilder
Parameters:
column - The column
Returns:
The native default value

writeColumnAutoIncrementStmt

protected void writeColumnAutoIncrementStmt(Table table,
                                            Column column)
                                     throws IOException
Prints that the column is an auto increment column.

Overrides:
writeColumnAutoIncrementStmt in class SqlBuilder
Parameters:
table - The table
column - The column
Throws:
IOException

writeExternalIndexDropStmt

public void writeExternalIndexDropStmt(Table table,
                                       Index index)
                                throws IOException
Generates the statement to drop a non-embedded index from the database.

Overrides:
writeExternalIndexDropStmt in class SqlBuilder
Parameters:
table - The table the index is on
index - The index to drop
Throws:
IOException

writeColumnAlterStmt

public void writeColumnAlterStmt(Table table,
                                 Column column,
                                 boolean isNewColumn)
                          throws IOException
Generates the alter statement to add or modify a single column on a table.

Overrides:
writeColumnAlterStmt in class SqlBuilder
Parameters:
table - The table the index is on
column - The column to drop
isNewColumn - Whether the column should be added
Throws:
IOException

writeExternalForeignKeyDropStmt

protected void writeExternalForeignKeyDropStmt(Table table,
                                               ForeignKey foreignKey)
                                        throws IOException
Generates the statement to drop a foreignkey constraint from the database using an alter table statement.

Overrides:
writeExternalForeignKeyDropStmt in class SqlBuilder
Parameters:
table - The table
foreignKey - The foreign key
Throws:
IOException

getDeleteSql

public String getDeleteSql(Table table,
                           Map pkValues,
                           boolean genPlaceholders)
Creates the SQL for deleting an object from the specified table. If values are given then a concrete delete statement is created, otherwise an delete statement usable in a prepared statement is build.

Overrides:
getDeleteSql in class SqlBuilder
Parameters:
table - The table
pkValues - The primary key values indexed by the column names, can be empty
genPlaceholders - Whether to generate value placeholders for a prepared statement
Returns:
The delete sql

getInsertSql

public String getInsertSql(Table table,
                           Map columnValues,
                           boolean genPlaceholders)
Creates the SQL for inserting an object into the specified table. If values are given then a concrete insert statement is created, otherwise an insert statement usable in a prepared statement is build.

Overrides:
getInsertSql in class SqlBuilder
Parameters:
table - The table
columnValues - The columns values indexed by the column names
genPlaceholders - Whether to generate value placeholders for a prepared statement
Returns:
The insertion sql

getUpdateSql

public String getUpdateSql(Table table,
                           Map columnValues,
                           boolean genPlaceholders)
Creates the SQL for updating an object in the specified table. If values are given then a concrete update statement is created, otherwise an update statement usable in a prepared statement is build.

Overrides:
getUpdateSql in class SqlBuilder
Parameters:
table - The table
columnValues - Contains the values for the columns to update, and should also contain the primary key values to identify the object to update in case genPlaceholders is false
genPlaceholders - Whether to generate value placeholders for a prepared statement (both for the pk values and the object values)
Returns:
The update sql


Copyright © 2005 Apache Software Foundation. All Rights Reserved.