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 classMSSQLDatabase.MSSQL_SERVER_VERSIONS
-
Field Summary
Fields Modifier and Type Field Description protected static intMSSQL_DEFAULT_TCP_PORTstatic StringPRODUCT_NAMEprotected 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.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 StringescapeDataTypeName(String dataTypeName)StringescapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)StringescapeObjectName(String catalogName, String schemaName, String objectName, Class<? extends DatabaseObject> objectType)StringescapeTableName(String catalogName, String schemaName, String tableName)voidexecuteStatements(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors)protected booleangenerateAutoIncrementBy(BigInteger incrementBy)protected booleangenerateAutoIncrementStartWith(BigInteger startWith)StringgenerateDefaultConstraintName(String tableName, String columnName)protected StringgetAutoIncrementByClause()protected StringgetAutoIncrementClause()protected StringgetAutoIncrementStartWithClause()StringgetConcatSql(String... values)Returns SQL to concat the passed values.protected SqlStatementgetConnectionSchemaNameCallStatement()Used to obtain the connection schema name through a statement Override this method to change the statement.intgetDataTypeMaxParameters(String dataTypeName)StringgetDateLiteral(String isoDate)Return a date literal with the same value as a string formatted using ISO 8601.StringgetDefaultCatalogName()protected StringgetDefaultDatabaseProductName()StringgetDefaultDriver(String url)If this database understands the given url, return the default driver class name.intgetDefaultFractionalDigitsForTimestamp()SQL Standard (Foundation) says: "...ifis not specified, then 6 is implicit." IntegergetDefaultPort()IntegergetDefaultScaleForNativeDataType(String nativeDataType)Returns the default precision for a given native data type, e.g.StringgetEngineEdition()Determines the capabilities ("Edition") of the SQL Server database.StringgetJdbcSchemaName(CatalogAndSchema schema)intgetPriority()protected StringgetQuotingEndCharacter()protected StringgetQuotingEndReplacement()protected StringgetQuotingStartCharacter()StringgetShortName()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.StringgetViewDefinition(CatalogAndSchema schema, String viewName)booleanisAzureDb()Returns true if the connected MS SQL instance is a Microsoft Cloud ("Azure")-hosted instance of MSSQL.booleanisCaseSensitive()booleanisCorrectDatabaseImplementation(DatabaseConnection conn)Is this AbstractDatabase subclass the correct one to use for the given connection.booleanisSystemObject(DatabaseObject example)booleansendsStringParametersAsUnicode()Determines if the SQL Server instance assigns Unicode data types (e.g.voidsetDefaultSchemaName(String schemaName)booleansupportsCatalogInObjectName(Class<? extends DatabaseObject> type)booleansupportsDropTableCascadeConstraints()booleansupportsInitiallyDeferrableColumns()Returns whether this database support initially deferrable columns.booleansupportsRestrictForeignKeys()booleansupportsSequences()Does the database type support sequence.booleansupportsTablespaces()StringunescapeDataTypeName(String dataTypeName)StringunescapeDataTypeString(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, getRunStatus, getSchemaAndCatalogCase, getSchemaFromJdbcInfo, getSystemSchema, getTimeLiteral, hashCode, isAutoCommit, 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
getDisplayName
-
-
-
-
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:
executeStatementsin interfaceDatabase- Overrides:
executeStatementsin classAbstractJdbcDatabase- Throws:
LiquibaseException
-
getDefaultScaleForNativeDataType
public Integer getDefaultScaleForNativeDataType(String nativeDataType)
Description copied from interface:DatabaseReturns the default precision for a given native data type, e.g. "datetime2" for Microsoft SQL Server.- Specified by:
getDefaultScaleForNativeDataTypein interfaceDatabase- Overrides:
getDefaultScaleForNativeDataTypein 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:
setDefaultSchemaNamein interfaceDatabase- Overrides:
setDefaultSchemaNamein classAbstractJdbcDatabase
-
getShortName
public String getShortName()
Description copied from interface:DatabaseReturns 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:
getDefaultDatabaseProductNamein classAbstractJdbcDatabase
-
getDefaultPort
public Integer getDefaultPort()
-
getSystemViews
public Set<String> getSystemViews()
Description copied from class:AbstractJdbcDatabaseReturns system (undroppable) views.- Overrides:
getSystemViewsin classAbstractJdbcDatabase
-
getSystemTables
protected Set<String> getSystemTables()
Description copied from class:AbstractJdbcDatabaseReturns system (undroppable) views.- Overrides:
getSystemTablesin classAbstractJdbcDatabase
-
supportsInitiallyDeferrableColumns
public boolean supportsInitiallyDeferrableColumns()
Description copied from interface:DatabaseReturns whether this database support initially deferrable columns.
-
supportsSequences
public boolean supportsSequences()
Description copied from class:AbstractJdbcDatabaseDoes the database type support sequence.- Specified by:
supportsSequencesin interfaceDatabase- Overrides:
supportsSequencesin classAbstractJdbcDatabase
-
isCorrectDatabaseImplementation
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException
Description copied from interface:DatabaseIs this AbstractDatabase subclass the correct one to use for the given connection.- Throws:
DatabaseException
-
getDefaultDriver
public String getDefaultDriver(String url)
Description copied from interface:DatabaseIf this database understands the given url, return the default driver class name. Otherwise return null.
-
getAutoIncrementClause
protected String getAutoIncrementClause()
- Overrides:
getAutoIncrementClausein classAbstractJdbcDatabase
-
generateAutoIncrementStartWith
protected boolean generateAutoIncrementStartWith(BigInteger startWith)
- Overrides:
generateAutoIncrementStartWithin classAbstractJdbcDatabase
-
generateAutoIncrementBy
protected boolean generateAutoIncrementBy(BigInteger incrementBy)
- Overrides:
generateAutoIncrementByin classAbstractJdbcDatabase
-
getAutoIncrementStartWithClause
protected String getAutoIncrementStartWithClause()
- Overrides:
getAutoIncrementStartWithClausein classAbstractJdbcDatabase
-
getAutoIncrementByClause
protected String getAutoIncrementByClause()
- Overrides:
getAutoIncrementByClausein classAbstractJdbcDatabase
-
getDefaultCatalogName
public String getDefaultCatalogName()
- Specified by:
getDefaultCatalogNamein interfaceDatabase- Overrides:
getDefaultCatalogNamein classAbstractJdbcDatabase
-
getConnectionSchemaNameCallStatement
protected SqlStatement getConnectionSchemaNameCallStatement()
Description copied from class:AbstractJdbcDatabaseUsed to obtain the connection schema name through a statement Override this method to change the statement. Only override this if getConnectionSchemaName is left unchanges or is using this method.- Overrides:
getConnectionSchemaNameCallStatementin classAbstractJdbcDatabase- See Also:
AbstractJdbcDatabase.getConnectionSchemaName()
-
getConcatSql
public String getConcatSql(String... values)
Description copied from interface:DatabaseReturns SQL to concat the passed values.- Specified by:
getConcatSqlin interfaceDatabase- Overrides:
getConcatSqlin classAbstractJdbcDatabase
-
escapeTableName
public String escapeTableName(String catalogName, String schemaName, String tableName)
- Specified by:
escapeTableNamein interfaceDatabase- Overrides:
escapeTableNamein classAbstractJdbcDatabase
-
supportsTablespaces
public boolean supportsTablespaces()
-
isSystemObject
public boolean isSystemObject(DatabaseObject example)
- Specified by:
isSystemObjectin interfaceDatabase- Overrides:
isSystemObjectin classAbstractJdbcDatabase
-
generateDefaultConstraintName
public String generateDefaultConstraintName(String tableName, String columnName)
-
escapeObjectName
public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
- Specified by:
escapeObjectNamein interfaceDatabase- Overrides:
escapeObjectNamein classAbstractJdbcDatabase
-
getDateLiteral
public String getDateLiteral(String isoDate)
Description copied from class:AbstractJdbcDatabaseReturn 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:
getDateLiteralin interfaceDatabase- Overrides:
getDateLiteralin classAbstractJdbcDatabase
-
supportsRestrictForeignKeys
public boolean supportsRestrictForeignKeys()
- Specified by:
supportsRestrictForeignKeysin interfaceDatabase- Overrides:
supportsRestrictForeignKeysin classAbstractJdbcDatabase
-
supportsDropTableCascadeConstraints
public boolean supportsDropTableCascadeConstraints()
- Specified by:
supportsDropTableCascadeConstraintsin interfaceDatabase- Overrides:
supportsDropTableCascadeConstraintsin classAbstractJdbcDatabase
-
supportsCatalogInObjectName
public boolean supportsCatalogInObjectName(Class<? extends DatabaseObject> type)
- Specified by:
supportsCatalogInObjectNamein interfaceDatabase- Overrides:
supportsCatalogInObjectNamein classAbstractJdbcDatabase
-
getViewDefinition
public String getViewDefinition(CatalogAndSchema schema, String viewName) throws DatabaseException
- Specified by:
getViewDefinitionin interfaceDatabase- Overrides:
getViewDefinitionin classAbstractJdbcDatabase- Throws:
DatabaseException
-
escapeObjectName
public String escapeObjectName(String catalogName, String schemaName, String objectName, Class<? extends DatabaseObject> objectType)
- Specified by:
escapeObjectNamein interfaceDatabase- Overrides:
escapeObjectNamein classAbstractJdbcDatabase
-
getJdbcSchemaName
public String getJdbcSchemaName(CatalogAndSchema schema)
- Overrides:
getJdbcSchemaNamein classAbstractJdbcDatabase
-
isCaseSensitive
public boolean isCaseSensitive()
- Specified by:
isCaseSensitivein interfaceDatabase- Overrides:
isCaseSensitivein classAbstractJdbcDatabase
-
getDataTypeMaxParameters
public int getDataTypeMaxParameters(String dataTypeName)
- Specified by:
getDataTypeMaxParametersin interfaceDatabase- Overrides:
getDataTypeMaxParametersin classAbstractJdbcDatabase
-
escapeDataTypeName
public String escapeDataTypeName(String dataTypeName)
- Specified by:
escapeDataTypeNamein interfaceDatabase- Overrides:
escapeDataTypeNamein classAbstractJdbcDatabase
-
unescapeDataTypeName
public String unescapeDataTypeName(String dataTypeName)
- Specified by:
unescapeDataTypeNamein interfaceDatabase- Overrides:
unescapeDataTypeNamein classAbstractJdbcDatabase
-
unescapeDataTypeString
public String unescapeDataTypeString(String dataTypeString)
- Specified by:
unescapeDataTypeStringin interfaceDatabase- Overrides:
unescapeDataTypeStringin 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:
getQuotingStartCharacterin classAbstractJdbcDatabase
-
getQuotingEndCharacter
protected String getQuotingEndCharacter()
- Overrides:
getQuotingEndCharacterin classAbstractJdbcDatabase
-
getDefaultFractionalDigitsForTimestamp
public int getDefaultFractionalDigitsForTimestamp()
Description copied from class:AbstractJdbcDatabaseSQL Standard (Foundation) says: "...ifis not specified, then 6 is implicit." - Specified by:
getDefaultFractionalDigitsForTimestampin interfaceDatabase- Overrides:
getDefaultFractionalDigitsForTimestampin classAbstractJdbcDatabase- Returns:
- the default precision / number of maximum digits in a timestamp if nothing else is specified.
-
getQuotingEndReplacement
protected String getQuotingEndReplacement()
- Overrides:
getQuotingEndReplacementin classAbstractJdbcDatabase
-
-