Package liquibase.database.core
Class MSSQLDatabase
- java.lang.Object
-
- liquibase.database.AbstractJdbcDatabase
-
- liquibase.database.core.MSSQLDatabase
-
- All Implemented Interfaces:
AutoCloseable
,Database
,PrioritizedService
public class MSSQLDatabase extends AbstractJdbcDatabase
Encapsulates MS-SQL database support.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MSSQLDatabase.MSSQL_SERVER_VERSIONS
-
Field Summary
Fields Modifier and Type Field Description protected static int
MSSQL_DEFAULT_TCP_PORT
static String
PRODUCT_NAME
protected Set<String>
systemTablesAndViews
-
Fields inherited from class liquibase.database.AbstractJdbcDatabase
caseSensitive, currentDateTimeFunction, dateFunctions, defaultAutoIncrementBy, defaultAutoIncrementStartWith, defaultCatalogName, defaultSchemaName, quotingStrategy, sequenceCurrentValueFunction, sequenceNextValueFunction, unmodifiableDataTypes, unquotedObjectsAreUppercased
-
Fields inherited from interface liquibase.database.Database
COMPLETE_SQL_SCOPE_KEY
-
Fields inherited from interface liquibase.servicelocator.PrioritizedService
COMPARATOR, PRIORITY_DATABASE, PRIORITY_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description MSSQLDatabase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
escapeDataTypeName(String dataTypeName)
String
escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
String
escapeObjectName(String catalogName, String schemaName, String objectName, Class<? extends DatabaseObject> objectType)
String
escapeTableName(String catalogName, String schemaName, String tableName)
void
executeStatements(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors)
protected boolean
generateAutoIncrementBy(BigInteger incrementBy)
protected boolean
generateAutoIncrementStartWith(BigInteger startWith)
String
generateDefaultConstraintName(String tableName, String columnName)
protected String
getAutoIncrementByClause()
protected String
getAutoIncrementClause()
protected String
getAutoIncrementStartWithClause()
String
getConcatSql(String... values)
Returns SQL to concat the passed values.protected SqlStatement
getConnectionSchemaNameCallStatement()
Used to obtain the connection schema name through a statement Override this method to change the statement.int
getDataTypeMaxParameters(String dataTypeName)
String
getDateLiteral(String isoDate)
Return a date literal with the same value as a string formatted using ISO 8601.String
getDefaultCatalogName()
protected String
getDefaultDatabaseProductName()
String
getDefaultDriver(String url)
If this database understands the given url, return the default driver class name.int
getDefaultFractionalDigitsForTimestamp()
SQL Standard (Foundation) says: "...ifis not specified, then 6 is implicit." Integer
getDefaultPort()
Integer
getDefaultScaleForNativeDataType(String nativeDataType)
Returns the default precision for a given native data type, e.g.String
getEngineEdition()
Determines the capabilities ("Edition") of the SQL Server database.String
getJdbcSchemaName(CatalogAndSchema schema)
int
getPriority()
protected String
getQuotingEndCharacter()
protected String
getQuotingEndReplacement()
protected String
getQuotingStartCharacter()
String
getShortName()
Returns an all-lower-case short name of the product.protected Set<String>
getSystemTables()
Returns system (undroppable) views.Set<String>
getSystemViews()
Returns system (undroppable) views.String
getViewDefinition(CatalogAndSchema schema, String viewName)
boolean
isAzureDb()
Returns true if the connected MS SQL instance is a Microsoft Cloud ("Azure")-hosted instance of MSSQL.boolean
isCaseSensitive()
boolean
isCorrectDatabaseImplementation(DatabaseConnection conn)
Is this AbstractDatabase subclass the correct one to use for the given connection.boolean
isSystemObject(DatabaseObject example)
boolean
sendsStringParametersAsUnicode()
Determines if the SQL Server instance assigns Unicode data types (e.g.void
setDefaultSchemaName(String schemaName)
boolean
supportsCatalogInObjectName(Class<? extends DatabaseObject> type)
boolean
supportsDatabaseChangeLogHistory()
Does the particular database implementation support the database changelog history feature and associated table?boolean
supportsDropTableCascadeConstraints()
boolean
supportsInitiallyDeferrableColumns()
Returns whether this database support initially deferrable columns.boolean
supportsRestrictForeignKeys()
boolean
supportsSequences()
Does the database type support sequence.boolean
supportsTablespaces()
String
unescapeDataTypeName(String dataTypeName)
String
unescapeDataTypeString(String dataTypeString)
-
Methods inherited from class liquibase.database.AbstractJdbcDatabase
addReservedWords, canCreateChangeLogTable, close, commit, correctObjectName, correctSchema, correctSchema, createsIndexesForForeignKeys, dataTypeIsNotModifiable, disableForeignKeyChecks, doesTagExist, dropDatabaseObjects, enableForeignKeyChecks, equals, escapeColumnName, escapeColumnName, escapeColumnNameList, escapeConstraintName, escapeIndexName, escapeSequenceName, escapeStringForDatabase, escapeViewName, execute, executeRollbackStatements, executeRollbackStatements, filterRollbackVisitors, generateDatabaseFunctionValue, generatePrimaryKeyName, get, getAutoCommitMode, getAutoIncrementClause, getAutoIncrementClause, getAutoIncrementClosing, getAutoIncrementOpening, getConnection, getConnectionCatalogName, getConnectionSchemaName, getContainingObjects, getCurrentDateTimeFunction, getDatabaseChangeLogLockTableName, getDatabaseChangeLogTableName, getDatabaseMajorVersion, getDatabaseMinorVersion, getDatabaseProductName, getDatabaseProductVersion, getDateFunctions, getDateLiteral, getDateLiteral, getDateTimeLiteral, getDefaultSchema, getDefaultSchemaName, getFetchSize, getJdbcCatalogName, getJdbcCatalogName, getJdbcSchemaName, getLineComment, getLiquibaseCatalogName, getLiquibaseSchemaName, getLiquibaseTablespaceName, getMaxFractionalDigitsForTimestamp, getName, getObjectQuotingStrategy, getOutputDefaultCatalog, getOutputDefaultSchema, getRanChangeSet, getRanChangeSetList, getRanDate, getRawDatabaseChangeLogLockTableName, getRawDatabaseChangeLogTableName, getRunStatus, getSchemaAndCatalogCase, getSchemaFromJdbcInfo, getSystemSchema, getTimeLiteral, hashCode, isAutoCommit, isCatalogOrSchemaType, isCurrentTimeFunction, isDateOnly, isDateTime, isDefaultCatalog, isDefaultSchema, isFunction, isLiquibaseObject, isReservedWord, isSafeToRunUpdate, isSystemView, isTimeOnly, isTimestamp, jdbcCallsCatalogsSchemas, markChangeSetExecStatus, mustQuoteObjectName, parseDate, quoteObject, removeRanStatus, requiresExplicitNullForColumns, requiresPassword, requiresUsername, resetInternalState, rollback, saveRollbackStatement, saveStatements, set, setAutoCommit, setCanCacheLiquibaseTableInfo, setCaseSensitive, setConnection, setCurrentDateTimeFunction, setDatabaseChangeLogLockTableName, setDatabaseChangeLogTableName, setDefaultCatalogName, setLiquibaseCatalogName, setLiquibaseSchemaName, setLiquibaseTablespaceName, setObjectQuotingStrategy, setOutputDefaultCatalog, setOutputDefaultSchema, startsWithNumeric, supportsAutoIncrement, supportsBatchUpdates, supportsCatalogs, supportsDDLInTransaction, supportsForeignKeyDisable, supportsNotNullConstraintNames, supportsPrimaryKeyNames, supportsSchemas, tag, toString, validate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface liquibase.database.Database
addCompleteSqlToScope, afterUpdate, dropDatabaseObjects, failOnDefferable, getDisplayName, supportsCreateIfNotExists, temporarilySetObjectQuotingStrategy
-
-
-
-
Field Detail
-
PRODUCT_NAME
public static final String PRODUCT_NAME
- See Also:
- Constant Field Values
-
MSSQL_DEFAULT_TCP_PORT
protected static final int MSSQL_DEFAULT_TCP_PORT
- See Also:
- Constant Field Values
-
-
Method Detail
-
executeStatements
public void executeStatements(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors) throws LiquibaseException
- Specified by:
executeStatements
in interfaceDatabase
- Overrides:
executeStatements
in classAbstractJdbcDatabase
- Throws:
LiquibaseException
-
getDefaultScaleForNativeDataType
public Integer getDefaultScaleForNativeDataType(String nativeDataType)
Description copied from interface:Database
Returns the default precision for a given native data type, e.g. "datetime2" for Microsoft SQL Server.- Specified by:
getDefaultScaleForNativeDataType
in interfaceDatabase
- Overrides:
getDefaultScaleForNativeDataType
in classAbstractJdbcDatabase
- Parameters:
nativeDataType
- the name of the native data type (case-insensitive).- Returns:
- The default precision of the native data type, or null if the type is unknown to this database.
-
setDefaultSchemaName
public void setDefaultSchemaName(String schemaName)
- Specified by:
setDefaultSchemaName
in interfaceDatabase
- Overrides:
setDefaultSchemaName
in classAbstractJdbcDatabase
-
getShortName
public String getShortName()
Description copied from interface:Database
Returns an all-lower-case short name of the product. Used for end-user selecting of database type such as the DBMS precondition.
-
getPriority
public int getPriority()
-
getDefaultDatabaseProductName
protected String getDefaultDatabaseProductName()
- Specified by:
getDefaultDatabaseProductName
in classAbstractJdbcDatabase
-
getDefaultPort
public Integer getDefaultPort()
-
getSystemViews
public Set<String> getSystemViews()
Description copied from class:AbstractJdbcDatabase
Returns system (undroppable) views.- Overrides:
getSystemViews
in classAbstractJdbcDatabase
-
getSystemTables
protected Set<String> getSystemTables()
Description copied from class:AbstractJdbcDatabase
Returns system (undroppable) views.- Overrides:
getSystemTables
in classAbstractJdbcDatabase
-
supportsInitiallyDeferrableColumns
public boolean supportsInitiallyDeferrableColumns()
Description copied from interface:Database
Returns whether this database support initially deferrable columns.
-
supportsSequences
public boolean supportsSequences()
Description copied from class:AbstractJdbcDatabase
Does the database type support sequence.- Specified by:
supportsSequences
in interfaceDatabase
- Overrides:
supportsSequences
in classAbstractJdbcDatabase
-
isCorrectDatabaseImplementation
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException
Description copied from interface:Database
Is this AbstractDatabase subclass the correct one to use for the given connection.- Throws:
DatabaseException
-
getDefaultDriver
public String getDefaultDriver(String url)
Description copied from interface:Database
If this database understands the given url, return the default driver class name. Otherwise return null.
-
getAutoIncrementClause
protected String getAutoIncrementClause()
- Overrides:
getAutoIncrementClause
in classAbstractJdbcDatabase
-
generateAutoIncrementStartWith
protected boolean generateAutoIncrementStartWith(BigInteger startWith)
- Overrides:
generateAutoIncrementStartWith
in classAbstractJdbcDatabase
-
generateAutoIncrementBy
protected boolean generateAutoIncrementBy(BigInteger incrementBy)
- Overrides:
generateAutoIncrementBy
in classAbstractJdbcDatabase
-
getAutoIncrementStartWithClause
protected String getAutoIncrementStartWithClause()
- Overrides:
getAutoIncrementStartWithClause
in classAbstractJdbcDatabase
-
getAutoIncrementByClause
protected String getAutoIncrementByClause()
- Overrides:
getAutoIncrementByClause
in classAbstractJdbcDatabase
-
getDefaultCatalogName
public String getDefaultCatalogName()
- Specified by:
getDefaultCatalogName
in interfaceDatabase
- Overrides:
getDefaultCatalogName
in classAbstractJdbcDatabase
-
getConnectionSchemaNameCallStatement
protected SqlStatement getConnectionSchemaNameCallStatement()
Description copied from class:AbstractJdbcDatabase
Used to obtain the connection schema name through a statement Override this method to change the statement. Only override this if getConnectionSchemaName is left unchanged or is using this method.- Overrides:
getConnectionSchemaNameCallStatement
in classAbstractJdbcDatabase
- See Also:
AbstractJdbcDatabase.getConnectionSchemaName()
-
getConcatSql
public String getConcatSql(String... values)
Description copied from interface:Database
Returns SQL to concat the passed values.- Specified by:
getConcatSql
in interfaceDatabase
- Overrides:
getConcatSql
in classAbstractJdbcDatabase
-
escapeTableName
public String escapeTableName(String catalogName, String schemaName, String tableName)
- Specified by:
escapeTableName
in interfaceDatabase
- Overrides:
escapeTableName
in classAbstractJdbcDatabase
-
supportsTablespaces
public boolean supportsTablespaces()
-
isSystemObject
public boolean isSystemObject(DatabaseObject example)
- Specified by:
isSystemObject
in interfaceDatabase
- Overrides:
isSystemObject
in classAbstractJdbcDatabase
-
generateDefaultConstraintName
public String generateDefaultConstraintName(String tableName, String columnName)
-
escapeObjectName
public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
- Specified by:
escapeObjectName
in interfaceDatabase
- Overrides:
escapeObjectName
in classAbstractJdbcDatabase
-
getDateLiteral
public String getDateLiteral(String isoDate)
Description copied from class:AbstractJdbcDatabase
Return a date literal with the same value as a string formatted using ISO 8601. Note: many databases accept date literals in ISO8601 format with the 'T' replaced with a space. Only databases which do not accept these strings should need to override this method. Implementation restriction: Currently, only the following subsets of ISO8601 are supported: yyyy-MM-dd hh:mm:ss yyyy-MM-ddThh:mm:ss- Specified by:
getDateLiteral
in interfaceDatabase
- Overrides:
getDateLiteral
in classAbstractJdbcDatabase
-
supportsRestrictForeignKeys
public boolean supportsRestrictForeignKeys()
- Specified by:
supportsRestrictForeignKeys
in interfaceDatabase
- Overrides:
supportsRestrictForeignKeys
in classAbstractJdbcDatabase
-
supportsDropTableCascadeConstraints
public boolean supportsDropTableCascadeConstraints()
- Specified by:
supportsDropTableCascadeConstraints
in interfaceDatabase
- Overrides:
supportsDropTableCascadeConstraints
in classAbstractJdbcDatabase
-
supportsCatalogInObjectName
public boolean supportsCatalogInObjectName(Class<? extends DatabaseObject> type)
- Specified by:
supportsCatalogInObjectName
in interfaceDatabase
- Overrides:
supportsCatalogInObjectName
in classAbstractJdbcDatabase
-
getViewDefinition
public String getViewDefinition(CatalogAndSchema schema, String viewName) throws DatabaseException
- Specified by:
getViewDefinition
in interfaceDatabase
- Overrides:
getViewDefinition
in classAbstractJdbcDatabase
- Throws:
DatabaseException
-
escapeObjectName
public String escapeObjectName(String catalogName, String schemaName, String objectName, Class<? extends DatabaseObject> objectType)
- Specified by:
escapeObjectName
in interfaceDatabase
- Overrides:
escapeObjectName
in classAbstractJdbcDatabase
-
getJdbcSchemaName
public String getJdbcSchemaName(CatalogAndSchema schema)
- Overrides:
getJdbcSchemaName
in classAbstractJdbcDatabase
-
isCaseSensitive
public boolean isCaseSensitive()
- Specified by:
isCaseSensitive
in interfaceDatabase
- Overrides:
isCaseSensitive
in classAbstractJdbcDatabase
-
getDataTypeMaxParameters
public int getDataTypeMaxParameters(String dataTypeName)
- Specified by:
getDataTypeMaxParameters
in interfaceDatabase
- Overrides:
getDataTypeMaxParameters
in classAbstractJdbcDatabase
-
escapeDataTypeName
public String escapeDataTypeName(String dataTypeName)
- Specified by:
escapeDataTypeName
in interfaceDatabase
- Overrides:
escapeDataTypeName
in classAbstractJdbcDatabase
-
unescapeDataTypeName
public String unescapeDataTypeName(String dataTypeName)
- Specified by:
unescapeDataTypeName
in interfaceDatabase
- Overrides:
unescapeDataTypeName
in classAbstractJdbcDatabase
-
unescapeDataTypeString
public String unescapeDataTypeString(String dataTypeString)
- Specified by:
unescapeDataTypeString
in interfaceDatabase
- Overrides:
unescapeDataTypeString
in classAbstractJdbcDatabase
-
sendsStringParametersAsUnicode
public boolean sendsStringParametersAsUnicode()
Determines if the SQL Server instance assigns Unicode data types (e.g. nvarchar) to strings.- Returns:
- true if the SQL Server instance uses Unicode types by default, false if not.
-
isAzureDb
public boolean isAzureDb()
Returns true if the connected MS SQL instance is a Microsoft Cloud ("Azure")-hosted instance of MSSQL.- Returns:
- true if instance runs in Microsoft Azure, false otherwise
-
getEngineEdition
public String getEngineEdition()
Determines the capabilities ("Edition") of the SQL Server database. Possible values are currently "Personal", "Standard", "Enterprise" (Developer Edition is also reported as Enterprise), "Express" or "Azure".- Returns:
- one of the strings above
-
getQuotingStartCharacter
protected String getQuotingStartCharacter()
- Overrides:
getQuotingStartCharacter
in classAbstractJdbcDatabase
-
getQuotingEndCharacter
protected String getQuotingEndCharacter()
- Overrides:
getQuotingEndCharacter
in classAbstractJdbcDatabase
-
getDefaultFractionalDigitsForTimestamp
public int getDefaultFractionalDigitsForTimestamp()
Description copied from class:AbstractJdbcDatabase
SQL Standard (Foundation) says: "...ifis not specified, then 6 is implicit." - Specified by:
getDefaultFractionalDigitsForTimestamp
in interfaceDatabase
- Overrides:
getDefaultFractionalDigitsForTimestamp
in classAbstractJdbcDatabase
- Returns:
- the default precision / number of maximum digits in a timestamp if nothing else is specified.
-
getQuotingEndReplacement
protected String getQuotingEndReplacement()
- Overrides:
getQuotingEndReplacement
in classAbstractJdbcDatabase
-
supportsDatabaseChangeLogHistory
public boolean supportsDatabaseChangeLogHistory()
Description copied from interface:Database
Does the particular database implementation support the database changelog history feature and associated table?- Returns:
- true if supported, false otherwise
-
-