Package liquibase.database.core
Class PostgresDatabase
- java.lang.Object
-
- liquibase.database.AbstractJdbcDatabase
-
- liquibase.database.core.PostgresDatabase
-
- All Implemented Interfaces:
AutoCloseable
,Database
,PrioritizedService
- Direct Known Subclasses:
CockroachDatabase
,EnterpriseDBDatabase
public class PostgresDatabase extends AbstractJdbcDatabase
Encapsulates PostgreSQL database support.
-
-
Field Summary
Fields Modifier and Type Field Description static int
MINIMUM_DBMS_MAJOR_VERSION
static int
MINIMUM_DBMS_MINOR_VERSION
static String
PRODUCT_NAME
static List<String>
VALID_AUTO_INCREMENT_COLUMN_TYPE_NAMES
The data type names which are valid for auto-increment columns.-
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 PostgresDatabase()
-
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
equals(Object o)
String
escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
This has special case logic to handle NOT quoting column names if they are of type 'LiquibaseColumn' - columns in the DATABASECHANGELOG or DATABASECHANGELOGLOCK tables.boolean
generateAutoIncrementBy(BigInteger incrementBy)
boolean
generateAutoIncrementStartWith(BigInteger startWith)
String
generatePrimaryKeyName(String tableName)
Generates PK followingPostgreSQL
conventions: Postgres PK size is limited with 63 bytes.String
getAutoIncrementClause()
protected String
getAutoIncrementClause(String generationType, Boolean defaultOnNull)
Default implementation.protected SqlStatement
getConnectionSchemaNameCallStatement()
Used to obtain the connection schema name through a statement Override this method to change the statement.String
getDatabaseChangeLogLockTableName()
String
getDatabaseChangeLogTableName()
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()
CatalogAndSchema.CatalogAndSchemaCase
getSchemaAndCatalogCase()
This logic is used when db support catalogsString
getShortName()
Returns an all-lower-case short name of the product.Set<String>
getSystemViews()
Returns system (undroppable) views.int
hashCode()
protected boolean
hasMixedCase(String tableName)
boolean
isCorrectDatabaseImplementation(DatabaseConnection conn)
Is this AbstractDatabase subclass the correct one to use for the given connection.boolean
isReservedWord(String tableName)
boolean
isSystemObject(DatabaseObject example)
void
rollback()
void
setConnection(DatabaseConnection conn)
void
setDefaultCatalogName(String defaultCatalogName)
boolean
supportsCatalogInObjectName(Class<? extends DatabaseObject> type)
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
supportsInitiallyDeferrableColumns()
Returns whether this database support initially deferrable columns.boolean
supportsSequences()
Does the database type support sequence.boolean
supportsTablespaces()
String
unescapeDataTypeName(String dataTypeName)
boolean
useSerialDatatypes()
Should the database use "serial" datatypes vs.-
Methods inherited from class liquibase.database.AbstractJdbcDatabase
addReservedWords, canCreateChangeLogTable, close, commit, correctSchema, correctSchema, createsIndexesForForeignKeys, dataTypeIsNotModifiable, disableForeignKeyChecks, doesTagExist, dropDatabaseObjects, enableForeignKeyChecks, escapeColumnName, escapeColumnName, escapeColumnNameList, escapeConstraintName, escapeDataTypeName, escapeIndexName, escapeObjectName, escapeSequenceName, escapeStringForDatabase, escapeTableName, escapeViewName, execute, executeRollbackStatements, executeRollbackStatements, executeStatements, filterRollbackVisitors, generateDatabaseFunctionValue, get, getAutoCommitMode, getAutoIncrementByClause, getAutoIncrementClause, getAutoIncrementClosing, getAutoIncrementOpening, getAutoIncrementStartWithClause, getConcatSql, getConnection, getConnectionCatalogName, getConnectionSchemaName, getContainingObjects, getCurrentDateTimeFunction, getDatabaseMajorVersion, getDatabaseMinorVersion, getDatabaseProductName, getDatabaseProductVersion, getDataTypeMaxParameters, getDateFunctions, getDateLiteral, 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, getSchemaFromJdbcInfo, getSystemSchema, getSystemTables, getTimeLiteral, getViewDefinition, isAutoCommit, isCaseSensitive, isCatalogOrSchemaType, isCurrentTimeFunction, isDateOnly, isDateTime, isDefaultCatalog, isDefaultSchema, isFunction, isLiquibaseObject, isSafeToRunUpdate, isSystemView, isTimeOnly, isTimestamp, jdbcCallsCatalogsSchemas, markChangeSetExecStatus, mustQuoteObjectName, parseDate, quoteObject, removeRanStatus, requiresExplicitNullForColumns, requiresPassword, requiresUsername, resetInternalState, saveRollbackStatement, saveStatements, set, setAutoCommit, setCanCacheLiquibaseTableInfo, setCaseSensitive, setCurrentDateTimeFunction, setDatabaseChangeLogLockTableName, setDatabaseChangeLogTableName, setDefaultSchemaName, setLiquibaseCatalogName, setLiquibaseSchemaName, setLiquibaseTablespaceName, setObjectQuotingStrategy, setOutputDefaultCatalog, setOutputDefaultSchema, startsWithNumeric, supportsAutoIncrement, supportsBatchUpdates, supportsCatalogs, supportsDDLInTransaction, supportsDropTableCascadeConstraints, supportsForeignKeyDisable, supportsNotNullConstraintNames, supportsPrimaryKeyNames, supportsRestrictForeignKeys, supportsSchemas, tag, toString, 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
-
-
-
-
Field Detail
-
PRODUCT_NAME
public static final String PRODUCT_NAME
- See Also:
- Constant Field Values
-
MINIMUM_DBMS_MAJOR_VERSION
public static final int MINIMUM_DBMS_MAJOR_VERSION
- See Also:
- Constant Field Values
-
MINIMUM_DBMS_MINOR_VERSION
public static final int MINIMUM_DBMS_MINOR_VERSION
- See Also:
- Constant Field Values
-
-
Method Detail
-
equals
public boolean equals(Object o)
- Overrides:
equals
in classAbstractJdbcDatabase
-
hashCode
public int hashCode()
- Overrides:
hashCode
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.
-
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
-
getPriority
public int getPriority()
-
supportsInitiallyDeferrableColumns
public boolean supportsInitiallyDeferrableColumns()
Description copied from interface:Database
Returns whether this database support initially deferrable columns.
-
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.
-
supportsCatalogInObjectName
public boolean supportsCatalogInObjectName(Class<? extends DatabaseObject> type)
- Specified by:
supportsCatalogInObjectName
in interfaceDatabase
- Overrides:
supportsCatalogInObjectName
in classAbstractJdbcDatabase
-
supportsSequences
public boolean supportsSequences()
Description copied from class:AbstractJdbcDatabase
Does the database type support sequence.- Specified by:
supportsSequences
in interfaceDatabase
- Overrides:
supportsSequences
in classAbstractJdbcDatabase
-
getDatabaseChangeLogTableName
public String getDatabaseChangeLogTableName()
- Specified by:
getDatabaseChangeLogTableName
in interfaceDatabase
- Overrides:
getDatabaseChangeLogTableName
in classAbstractJdbcDatabase
-
getDatabaseChangeLogLockTableName
public String getDatabaseChangeLogLockTableName()
- Specified by:
getDatabaseChangeLogLockTableName
in interfaceDatabase
- Overrides:
getDatabaseChangeLogLockTableName
in classAbstractJdbcDatabase
-
setConnection
public void setConnection(DatabaseConnection conn)
- Specified by:
setConnection
in interfaceDatabase
- Overrides:
setConnection
in classAbstractJdbcDatabase
-
unescapeDataTypeName
public String unescapeDataTypeName(String dataTypeName)
- Specified by:
unescapeDataTypeName
in interfaceDatabase
- Overrides:
unescapeDataTypeName
in classAbstractJdbcDatabase
-
isSystemObject
public boolean isSystemObject(DatabaseObject example)
- Specified by:
isSystemObject
in interfaceDatabase
- Overrides:
isSystemObject
in classAbstractJdbcDatabase
-
supportsTablespaces
public boolean supportsTablespaces()
-
getAutoIncrementClause
public String getAutoIncrementClause()
- Overrides:
getAutoIncrementClause
in classAbstractJdbcDatabase
-
useSerialDatatypes
public boolean useSerialDatatypes()
Should the database use "serial" datatypes vs. "generated by default as identity"
-
getAutoIncrementClause
protected String getAutoIncrementClause(String generationType, Boolean defaultOnNull)
Description copied from class:AbstractJdbcDatabase
Default implementation. Intended for override in database specific cases- Overrides:
getAutoIncrementClause
in classAbstractJdbcDatabase
-
generateAutoIncrementStartWith
public boolean generateAutoIncrementStartWith(BigInteger startWith)
- Overrides:
generateAutoIncrementStartWith
in classAbstractJdbcDatabase
-
generateAutoIncrementBy
public boolean generateAutoIncrementBy(BigInteger incrementBy)
- Overrides:
generateAutoIncrementBy
in classAbstractJdbcDatabase
-
escapeObjectName
public String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
This has special case logic to handle NOT quoting column names if they are of type 'LiquibaseColumn' - columns in the DATABASECHANGELOG or DATABASECHANGELOGLOCK tables.- Specified by:
escapeObjectName
in interfaceDatabase
- Overrides:
escapeObjectName
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
-
hasMixedCase
protected boolean hasMixedCase(String tableName)
-
isReservedWord
public boolean isReservedWord(String tableName)
- Specified by:
isReservedWord
in interfaceDatabase
- Overrides:
isReservedWord
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()
-
generatePrimaryKeyName
public String generatePrimaryKeyName(String tableName)
Generates PK followingPostgreSQL
conventions:- Postgres PK size is limited with 63 bytes.
- Postgres PK is suffixed with '_pkey'.
- Specified by:
generatePrimaryKeyName
in interfaceDatabase
- Overrides:
generatePrimaryKeyName
in classAbstractJdbcDatabase
- Parameters:
tableName
- Table name as the base name for the generated PK.- Returns:
- PK name.
-
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
-
getSchemaAndCatalogCase
public CatalogAndSchema.CatalogAndSchemaCase getSchemaAndCatalogCase()
Description copied from class:AbstractJdbcDatabase
This logic is used when db support catalogs- Specified by:
getSchemaAndCatalogCase
in interfaceDatabase
- Overrides:
getSchemaAndCatalogCase
in classAbstractJdbcDatabase
- Returns:
- UPPER_CASE by default
-
rollback
public void rollback() throws DatabaseException
- Specified by:
rollback
in interfaceDatabase
- Overrides:
rollback
in classAbstractJdbcDatabase
- Throws:
DatabaseException
-
setDefaultCatalogName
public void setDefaultCatalogName(String defaultCatalogName)
- Specified by:
setDefaultCatalogName
in interfaceDatabase
- Overrides:
setDefaultCatalogName
in classAbstractJdbcDatabase
-
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
-
-