org.dbmaintain.database.impl
Class MsSqlDatabase

java.lang.Object
  extended by org.dbmaintain.database.Database
      extended by org.dbmaintain.database.impl.MsSqlDatabase

public class MsSqlDatabase
extends Database

Implementation of Database for a MsSQL database.

Special thanks to Niki Driessen who donated the initial version of the MsSql support code.

Author:
Tim Ducheyne, Niki Driessen, Filip Neven

Field Summary
 
Fields inherited from class org.dbmaintain.database.Database
databaseConnection, identifierProcessor, schemaNames
 
Constructor Summary
MsSqlDatabase(DatabaseConnection databaseConnection, IdentifierProcessor identifierProcessor)
           
 
Method Summary
 void disableCheckConstraints(String schemaName)
          Drops all check constraints from the given schema
 void disableNotNullConstraints(String schemaName)
          Drops not-null constraints on the given table.
 void disableReferentialConstraints(String schemaName)
          Disables all referential constraints (e.g. foreign keys) on all table in the schema
 void disableUniqueConstraints(String schemaName)
          Drops all unique constraints from the given schema (not the primary key constraints)
 void disableValueConstraints(String schemaName)
          Disables all value constraints (e.g. not null) on all tables in the schema
 Set<String> getColumnNames(String schemaName, String tableName)
          Gets the names of all columns of the given table.
 Set<String> getIdentityColumnNames(String schemaName, String tableName)
          Gets the names of all identity columns of the given table.
 Set<String> getRuleNames(String schemaName)
          Retrieves the names of all the rules in the database schema.
 Set<String> getStoredProcedureNames(String schemaName)
          Retrieves the names of all the stored procedures in the database schema.
 String getSupportedDatabaseDialect()
           
 Set<String> getSynonymNames(String schemaName)
          Retrieves the names of all synonyms in the database schema.
 Set<String> getTableNames(String schemaName)
          Returns the names of all tables in the database.
protected  Map<String,Set<String>> getTablePrimaryKeyColumnsMap(String schemaName)
           
 Set<String> getTriggerNames(String schemaName)
          Retrieves the names of all the triggers in the database schema.
 Set<String> getTypeNames(String schemaName)
          Retrieves the names of all the types in the database schema.
 Set<String> getViewNames(String schemaName)
          Retrieves the names of all the views in the database schema.
 void incrementIdentityColumnToValue(String schemaName, String tableName, String identityColumnName, long identityValue)
          Increments the identity value for the specified identity column on the specified table to the given value.
 void setSettingIdentityColumnValueEnabled(String schemaName, String tableName, boolean enabled)
          Enables or disables the setting of identity value in insert and update statements.
 boolean supportsIdentityColumns()
          Identity columns are supported.
 boolean supportsRules()
          Rules are supported
 boolean supportsStoredProcedures()
          Stored procedures are supported.
 boolean supportsSynonyms()
          Synonyms are supported.
 boolean supportsTriggers()
          Triggers are supported.
 boolean supportsTypes()
          Types are supported
 
Methods inherited from class org.dbmaintain.database.Database
disableReferentialConstraints, disableValueConstraints, dropMaterializedView, dropMaterializedView, dropRule, dropSequence, dropSequence, dropStoredProcedure, dropStoredProcedure, dropSynonym, dropSynonym, dropTable, dropTable, dropTrigger, dropTrigger, dropType, dropType, dropView, dropView, getColumnNames, getDatabaseInfo, getDatabaseName, getDataSource, getDefaultSchemaName, getIdentifierQuoteString, getIdentityColumnNames, getLongDataType, getMaterializedViewNames, getMaterializedViewNames, getSchemaNames, getSequenceNames, getSequenceNames, getSequenceValue, getSequenceValue, getSQLHandler, getStoredIdentifierCase, getStoredProcedureNames, getSynonymNames, getTableNames, getTextDataType, getTriggerNames, getTypeNames, getViewNames, incrementIdentityColumnToValue, incrementSequenceToValue, incrementSequenceToValue, isQuoted, qualified, qualified, quoted, removeIdentifierQuotes, setDatabaseDefaultSchema, setSettingIdentityColumnValueEnabled, supportsCascade, supportsMaterializedViews, supportsSequences, supportsSetDatabaseDefaultSchema, toCorrectCaseIdentifier
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MsSqlDatabase

public MsSqlDatabase(DatabaseConnection databaseConnection,
                     IdentifierProcessor identifierProcessor)
Method Detail

getSupportedDatabaseDialect

public String getSupportedDatabaseDialect()
Specified by:
getSupportedDatabaseDialect in class Database
Returns:
the database dialect supported by this db support class, not null

getTableNames

public Set<String> getTableNames(String schemaName)
Returns the names of all tables in the database.

Specified by:
getTableNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all tables in the database

getColumnNames

public Set<String> getColumnNames(String schemaName,
                                  String tableName)
Gets the names of all columns of the given table.

Specified by:
getColumnNames in class Database
Parameters:
tableName - The table, not null
schemaName - The schema, not null
Returns:
The names of the columns of the table with the given name

getViewNames

public Set<String> getViewNames(String schemaName)
Retrieves the names of all the views in the database schema.

Specified by:
getViewNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all views in the database

getSynonymNames

public Set<String> getSynonymNames(String schemaName)
Retrieves the names of all synonyms in the database schema.

Overrides:
getSynonymNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all synonyms in the database

getTriggerNames

public Set<String> getTriggerNames(String schemaName)
Retrieves the names of all the triggers in the database schema.

Overrides:
getTriggerNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all triggers in the database

getStoredProcedureNames

public Set<String> getStoredProcedureNames(String schemaName)
Retrieves the names of all the stored procedures in the database schema.

Overrides:
getStoredProcedureNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all stored procedures in the database

getTypeNames

public Set<String> getTypeNames(String schemaName)
Retrieves the names of all the types in the database schema.

Overrides:
getTypeNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all types in the database

getRuleNames

public Set<String> getRuleNames(String schemaName)
Retrieves the names of all the rules in the database schema.

Overrides:
getRuleNames in class Database
Parameters:
schemaName - The schema, not null
Returns:
The names of all rules in the database

getIdentityColumnNames

public Set<String> getIdentityColumnNames(String schemaName,
                                          String tableName)
Gets the names of all identity columns of the given table.

Overrides:
getIdentityColumnNames in class Database
Parameters:
tableName - The table, not null
schemaName - The schema, not null
Returns:
The names of the identity columns of the table with the given name

incrementIdentityColumnToValue

public void incrementIdentityColumnToValue(String schemaName,
                                           String tableName,
                                           String identityColumnName,
                                           long identityValue)
Increments the identity value for the specified identity column on the specified table to the given value. If there is no identity specified on the given primary key, the method silently finishes without effect.

Overrides:
incrementIdentityColumnToValue in class Database
Parameters:
tableName - The table with the identity column, not null
identityColumnName - The column, not null
identityValue - The new value
schemaName - The schema, not null

disableReferentialConstraints

public void disableReferentialConstraints(String schemaName)
Disables all referential constraints (e.g. foreign keys) on all table in the schema

Specified by:
disableReferentialConstraints in class Database
Parameters:
schemaName - The schema, not null

disableValueConstraints

public void disableValueConstraints(String schemaName)
Disables all value constraints (e.g. not null) on all tables in the schema

Specified by:
disableValueConstraints in class Database
Parameters:
schemaName - The schema name, not null

disableUniqueConstraints

public void disableUniqueConstraints(String schemaName)
Drops all unique constraints from the given schema (not the primary key constraints)

Parameters:
schemaName - the schema name, not null

disableCheckConstraints

public void disableCheckConstraints(String schemaName)
Drops all check constraints from the given schema

Parameters:
schemaName - the schema name, not null

disableNotNullConstraints

public void disableNotNullConstraints(String schemaName)
Drops not-null constraints on the given table.

For primary keys, row-guid, identity and computed columns not-null constrains cannot be disabled in MS-Sql.

Parameters:
schemaName - the schema name, not null

getTablePrimaryKeyColumnsMap

protected Map<String,Set<String>> getTablePrimaryKeyColumnsMap(String schemaName)
Parameters:
schemaName - the schema name, not null
Returns:
a map with the table names of the given schema as key and a set containing the primary key column names as value

setSettingIdentityColumnValueEnabled

public void setSettingIdentityColumnValueEnabled(String schemaName,
                                                 String tableName,
                                                 boolean enabled)
Enables or disables the setting of identity value in insert and update statements. By default some databases do not allow to set values of identity columns directly from insert/update statements. If supported, this method will enable/disable this behavior.

Overrides:
setSettingIdentityColumnValueEnabled in class Database
Parameters:
schemaName - The schema name, not null
tableName - The table with the identity column, not null
enabled - True to enable, false to disable

supportsSynonyms

public boolean supportsSynonyms()
Synonyms are supported.

Overrides:
supportsSynonyms in class Database
Returns:
True

supportsTriggers

public boolean supportsTriggers()
Triggers are supported.

Overrides:
supportsTriggers in class Database
Returns:
True

supportsStoredProcedures

public boolean supportsStoredProcedures()
Stored procedures are supported.

Overrides:
supportsStoredProcedures in class Database
Returns:
True

supportsTypes

public boolean supportsTypes()
Types are supported

Overrides:
supportsTypes in class Database
Returns:
true

supportsRules

public boolean supportsRules()
Rules are supported

Overrides:
supportsRules in class Database
Returns:
true

supportsIdentityColumns

public boolean supportsIdentityColumns()
Identity columns are supported.

Overrides:
supportsIdentityColumns in class Database
Returns:
True


Copyright © 2011. All Rights Reserved.