Package liquibase.database.core
Class H2Database
- java.lang.Object
-
- liquibase.database.AbstractJdbcDatabase
-
- liquibase.database.core.H2Database
-
- All Implemented Interfaces:
AutoCloseable
,Database
,PrioritizedService
public class H2Database extends AbstractJdbcDatabase
-
-
Field Summary
Fields Modifier and Type Field Description protected static Set<String>
V1_RESERVED_WORDS
protected static Set<String>
V2_RESERVED_WORDS
-
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 H2Database()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
correctObjectName(String objectName, Class<? extends DatabaseObject> objectType)
Fix the object name to the format the database expects, handling changes in case, etc.boolean
createsIndexesForForeignKeys()
String
escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
protected String
getAutoIncrementByClause()
protected String
getAutoIncrementClause()
String
getAutoIncrementClause(BigInteger startWith, BigInteger incrementBy, String generationType, Boolean defaultOnNull)
Returns database-specific auto-increment DDL clause.protected String
getAutoIncrementStartWithClause()
String
getConcatSql(String... values)
Returns SQL to concat the passed values.protected String
getConnectionSchemaName()
Overwrite this method to get the default schema name for the connection.String
getDateLiteral(String isoDate)
Return a date literal with the same value as a string formatted using ISO 8601.protected String
getDefaultDatabaseProductName()
String
getDefaultDriver(String url)
If this database understands the given url, return the default driver class name.Integer
getDefaultPort()
int
getMaxFractionalDigitsForTimestamp()
Most relational databases support 9 fractional digits, and subclasses must overwrite this method if they support less than that.int
getPriority()
protected Set<String>
getReservedWords()
String
getShortName()
Returns an all-lower-case short name of the product.String
getViewDefinition(CatalogAndSchema schema, String name)
boolean
isCorrectDatabaseImplementation(DatabaseConnection conn)
Is this AbstractDatabase subclass the correct one to use for the given connection.boolean
isReservedWord(String objectName)
boolean
isSafeToRunUpdate()
Default implementation of theAbstractJdbcDatabase.isSafeToRunUpdate()
method.protected boolean
mustQuoteObjectName(String objectName, Class<? extends DatabaseObject> objectType)
Date
parseDate(String dateAsString)
void
setConnection(DatabaseConnection conn)
boolean
supportsCreateIfNotExists(Class<? extends DatabaseObject> type)
Does the database support the "if not exits" syntax?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
supportsMinMaxForSequences()
boolean
supportsSequences()
Does the database type support sequence.boolean
supportsTablespaces()
-
Methods inherited from class liquibase.database.AbstractJdbcDatabase
addReservedWords, canCreateChangeLogTable, close, commit, correctSchema, correctSchema, dataTypeIsNotModifiable, disableForeignKeyChecks, doesTagExist, dropDatabaseObjects, enableForeignKeyChecks, equals, escapeColumnName, escapeColumnName, escapeColumnNameList, escapeConstraintName, escapeDataTypeName, escapeIndexName, escapeObjectName, escapeSequenceName, escapeStringForDatabase, escapeTableName, escapeViewName, execute, executeRollbackStatements, executeRollbackStatements, executeStatements, filterRollbackVisitors, generateAutoIncrementBy, generateAutoIncrementStartWith, generateDatabaseFunctionValue, generatePrimaryKeyName, get, getAutoCommitMode, getAutoIncrementClause, getAutoIncrementClosing, getAutoIncrementOpening, getConnection, getConnectionCatalogName, getConnectionSchemaNameCallStatement, getContainingObjects, getCurrentDateTimeFunction, getDatabaseChangeLogLockTableName, getDatabaseChangeLogTableName, getDatabaseMajorVersion, getDatabaseMinorVersion, getDatabaseProductName, getDatabaseProductVersion, getDataTypeMaxParameters, getDateFunctions, getDateLiteral, getDateLiteral, getDateTimeLiteral, getDefaultCatalogName, getDefaultFractionalDigitsForTimestamp, getDefaultScaleForNativeDataType, getDefaultSchema, getDefaultSchemaName, getFetchSize, getJdbcCatalogName, getJdbcCatalogName, getJdbcSchemaName, getJdbcSchemaName, getLineComment, getLiquibaseCatalogName, getLiquibaseSchemaName, getLiquibaseTablespaceName, getName, getObjectQuotingStrategy, getOutputDefaultCatalog, getOutputDefaultSchema, getQuotingEndCharacter, getQuotingEndReplacement, getQuotingStartCharacter, getRanChangeSet, getRanChangeSetList, getRanDate, getRawDatabaseChangeLogLockTableName, getRawDatabaseChangeLogTableName, getRunStatus, getSchemaAndCatalogCase, getSchemaFromJdbcInfo, getSystemSchema, getSystemTables, getSystemViews, getTimeLiteral, hashCode, isAutoCommit, isCaseSensitive, isCatalogOrSchemaType, isCurrentTimeFunction, isDateOnly, isDateTime, isDefaultCatalog, isDefaultSchema, isFunction, isLiquibaseObject, isSystemObject, isSystemView, isTimeOnly, isTimestamp, jdbcCallsCatalogsSchemas, markChangeSetExecStatus, quoteObject, removeRanStatus, requiresExplicitNullForColumns, requiresPassword, requiresUsername, resetInternalState, rollback, saveRollbackStatement, saveStatements, set, setAutoCommit, setCanCacheLiquibaseTableInfo, setCaseSensitive, setCurrentDateTimeFunction, setDatabaseChangeLogLockTableName, setDatabaseChangeLogTableName, setDefaultCatalogName, setDefaultSchemaName, setLiquibaseCatalogName, setLiquibaseSchemaName, setLiquibaseTablespaceName, setObjectQuotingStrategy, setOutputDefaultCatalog, setOutputDefaultSchema, startsWithNumeric, supportsAutoIncrement, supportsBatchUpdates, supportsCatalogInObjectName, supportsCatalogs, supportsDDLInTransaction, supportsForeignKeyDisable, supportsNotNullConstraintNames, supportsPrimaryKeyNames, supportsRestrictForeignKeys, supportsSchemas, tag, toString, unescapeDataTypeName, unescapeDataTypeString, 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, temporarilySetObjectQuotingStrategy
-
-
-
-
Method Detail
-
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.
-
getDefaultPort
public Integer getDefaultPort()
-
getDefaultDatabaseProductName
protected String getDefaultDatabaseProductName()
- Specified by:
getDefaultDatabaseProductName
in classAbstractJdbcDatabase
-
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.
-
getPriority
public int getPriority()
-
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
-
supportsTablespaces
public boolean supportsTablespaces()
-
getViewDefinition
public String getViewDefinition(CatalogAndSchema schema, String name) throws DatabaseException
- Specified by:
getViewDefinition
in interfaceDatabase
- Overrides:
getViewDefinition
in classAbstractJdbcDatabase
- Throws:
DatabaseException
-
parseDate
public Date parseDate(String dateAsString) throws DateParseException
- Specified by:
parseDate
in interfaceDatabase
- Overrides:
parseDate
in classAbstractJdbcDatabase
- Throws:
DateParseException
-
isSafeToRunUpdate
public boolean isSafeToRunUpdate() throws DatabaseException
Description copied from class:AbstractJdbcDatabase
Default implementation of theAbstractJdbcDatabase.isSafeToRunUpdate()
method. It checks if the database connection URL contains "localhost" or "127.0.0.1". If the database returns anull
URL, the method returnsfalse
because it's not known whether it's safe to run the update.- Specified by:
isSafeToRunUpdate
in interfaceDatabase
- Overrides:
isSafeToRunUpdate
in classAbstractJdbcDatabase
- Returns:
true
if the database connection URL contains "localhost" or "127.0.0.1", otherwisefalse
.- Throws:
DatabaseException
- if there is an error accessing the database
-
supportsSequences
public boolean supportsSequences()
Description copied from class:AbstractJdbcDatabase
Does the database type support sequence.- Specified by:
supportsSequences
in interfaceDatabase
- Overrides:
supportsSequences
in classAbstractJdbcDatabase
-
getConnectionSchemaName
protected String getConnectionSchemaName()
Description copied from class:AbstractJdbcDatabase
Overwrite this method to get the default schema name for the connection. If you only need to change the statement that obtains the current schema then override- Overrides:
getConnectionSchemaName
in classAbstractJdbcDatabase
- See Also:
AbstractJdbcDatabase.getConnectionSchemaNameCallStatement()
-
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
-
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
-
isReservedWord
public boolean isReservedWord(String objectName)
- Specified by:
isReservedWord
in interfaceDatabase
- Overrides:
isReservedWord
in classAbstractJdbcDatabase
-
correctObjectName
public String correctObjectName(String objectName, Class<? extends DatabaseObject> objectType)
Description copied from interface:Database
Fix the object name to the format the database expects, handling changes in case, etc.- Specified by:
correctObjectName
in interfaceDatabase
- Overrides:
correctObjectName
in classAbstractJdbcDatabase
-
escapeObjectName
public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
- Specified by:
escapeObjectName
in interfaceDatabase
- Overrides:
escapeObjectName
in classAbstractJdbcDatabase
-
mustQuoteObjectName
protected boolean mustQuoteObjectName(String objectName, Class<? extends DatabaseObject> objectType)
- Overrides:
mustQuoteObjectName
in classAbstractJdbcDatabase
-
supportsInitiallyDeferrableColumns
public boolean supportsInitiallyDeferrableColumns()
Description copied from interface:Database
Returns whether this database support initially deferrable columns.
-
getAutoIncrementClause
protected String getAutoIncrementClause()
- Overrides:
getAutoIncrementClause
in classAbstractJdbcDatabase
-
getAutoIncrementStartWithClause
protected String getAutoIncrementStartWithClause()
- Overrides:
getAutoIncrementStartWithClause
in classAbstractJdbcDatabase
-
getAutoIncrementByClause
protected String getAutoIncrementByClause()
- Overrides:
getAutoIncrementByClause
in classAbstractJdbcDatabase
-
getAutoIncrementClause
public String getAutoIncrementClause(BigInteger startWith, BigInteger incrementBy, String generationType, Boolean defaultOnNull)
Description copied from interface:Database
Returns database-specific auto-increment DDL clause.- Specified by:
getAutoIncrementClause
in interfaceDatabase
- Overrides:
getAutoIncrementClause
in classAbstractJdbcDatabase
-
createsIndexesForForeignKeys
public boolean createsIndexesForForeignKeys()
- Specified by:
createsIndexesForForeignKeys
in interfaceDatabase
- Overrides:
createsIndexesForForeignKeys
in classAbstractJdbcDatabase
-
supportsDropTableCascadeConstraints
public boolean supportsDropTableCascadeConstraints()
- Specified by:
supportsDropTableCascadeConstraints
in interfaceDatabase
- Overrides:
supportsDropTableCascadeConstraints
in classAbstractJdbcDatabase
-
setConnection
public void setConnection(DatabaseConnection conn)
- Specified by:
setConnection
in interfaceDatabase
- Overrides:
setConnection
in classAbstractJdbcDatabase
-
supportsMinMaxForSequences
public boolean supportsMinMaxForSequences()
-
getMaxFractionalDigitsForTimestamp
public int getMaxFractionalDigitsForTimestamp()
Description copied from class:AbstractJdbcDatabase
Most relational databases support 9 fractional digits, and subclasses must overwrite this method if they support less than that.- Specified by:
getMaxFractionalDigitsForTimestamp
in interfaceDatabase
- Overrides:
getMaxFractionalDigitsForTimestamp
in classAbstractJdbcDatabase
- Returns:
- the maximum number of supported fractional digits in TIMESTAMP columns
-
supportsCreateIfNotExists
public boolean supportsCreateIfNotExists(Class<? extends DatabaseObject> type)
Description copied from interface:Database
Does the database support the "if not exits" syntax?- Parameters:
type
- the DatabaseObject type to be checked.- Returns:
- true if the "if not exists" syntax is supported, false otherwise.
-
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
-
-