liquibase.database
Class AbstractDatabase

java.lang.Object
  extended by liquibase.database.AbstractDatabase
All Implemented Interfaces:
Database, DatabaseObject, PrioritizedService
Direct Known Subclasses:
CacheDatabase, DB2Database, DerbyDatabase, FirebirdDatabase, H2Database, HsqlDatabase, InformixDatabase, MaxDBDatabase, MSSQLDatabase, MySQLDatabase, OracleDatabase, PostgresDatabase, SQLiteDatabase, SybaseASADatabase, SybaseDatabase, UnsupportedDatabase

public abstract class AbstractDatabase
extends Object
implements Database

AbstractDatabase is extended by all supported databases as a facade to the underlying database. The physical connection can be retrieved from the AbstractDatabase implementation, as well as any database-specific characteristics such as the datatype for "boolean" fields.


Field Summary
protected  String currentDateTimeFunction
           
protected  List<DatabaseFunction> databaseFunctions
           
 
Fields inherited from interface liquibase.servicelocator.PrioritizedService
PRIORITY_DATABASE, PRIORITY_DEFAULT
 
Constructor Summary
protected AbstractDatabase()
           
 
Method Summary
protected  boolean canCreateChangeLogTable()
           
 void checkDatabaseChangeLogLockTable()
          This method will check the database ChangeLogLock table used to keep track of if a machine is updating the database.
 void checkDatabaseChangeLogTable(boolean updateExistingNullChecksums, DatabaseChangeLog databaseChangeLog, String... contexts)
          This method will check the database ChangeLog table used to keep track of the changes in the file.
 void close()
           
 void commit()
           
 String convertRequestedSchemaToCatalog(String requestedSchema)
           
 String convertRequestedSchemaToSchema(String requestedSchema)
           
 boolean disableForeignKeyChecks()
           
 boolean doesTagExist(String tag)
           
 void dropDatabaseObjects(String schema)
          Drops all objects owned by the connected user.
 void enableForeignKeyChecks()
           
 boolean equals(Object o)
           
 String escapeColumnName(String schemaName, String tableName, String columnName)
          Escapes a single column name in a database-dependent manner so reserved words can be used as a column name (i.e.
 String escapeColumnNameList(String columnNames)
          Escapes a list of column names in a database-dependent manner so reserved words can be used as a column name (i.e.
 String escapeConstraintName(String constraintName)
           
 String escapeDatabaseObject(String objectName)
           
 String escapeIndexName(String schemaName, String indexName)
           
 String escapeSequenceName(String schemaName, String sequenceName)
           
 String escapeStringForDatabase(String string)
           
 String escapeTableName(String schemaName, String tableName)
          Escapes the table name in a database-dependent manner so reserved words can be used as a table name (i.e.
 String escapeViewName(String schemaName, String viewName)
           
 void execute(SqlStatement[] statements, List<SqlVisitor> sqlVisitors)
           
 void executeRollbackStatements(Change change, List<SqlVisitor> sqlVisitors)
           
 void executeStatements(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors)
           
 String generatePrimaryKeyName(String tableName)
           
 boolean getAutoCommitMode()
          Auto-commit mode to run in
 String getAutoIncrementClause()
          Returns database-specific auto-increment DDL clause.
 String getConcatSql(String... values)
          Returns SQL to concat the passed values.
 DatabaseConnection getConnection()
           
 DatabaseObject[] getContainingObjects()
           
 String getDatabaseChangeLogLockTableName()
           
 String getDatabaseChangeLogTableName()
           
 List<DatabaseFunction> getDatabaseFunctions()
          Returns list of database native functions
 int getDatabaseMajorVersion()
           
 int getDatabaseMinorVersion()
           
 String getDatabaseProductName()
          Returns the name of the database product according to the underlying database.
 String getDatabaseProductVersion()
           
 String getDateLiteral(Date date)
           
 String getDateLiteral(Date date)
           
 String getDateLiteral(String isoDate)
          Return a date literal with the same value as a string formatted using ISO 8601.
 String getDateTimeLiteral(Timestamp date)
           
 String getDefaultCatalogName()
           
protected  String getDefaultDatabaseSchemaName()
           
 String getDefaultSchemaName()
           
 String getLineComment()
          Returns database-specific line comment string.
 String getLiquibaseSchemaName()
           
 int getNextChangeSetSequenceValue()
           
 RanChangeSet getRanChangeSet(ChangeSet changeSet)
           
 List<RanChangeSet> getRanChangeSetList()
          Returns the ChangeSets that have been run against the current database.
 Date getRanDate(ChangeSet changeSet)
           
 ChangeSet.RunStatus getRunStatus(ChangeSet changeSet)
          Returns the run status for the given ChangeSet
protected  Set<String> getSystemTablesAndViews()
          Returns system (undroppable) tables and views.
 Table getTable(String schemaName, String tableName)
           
 String getTimeLiteral(Time date)
           
 String getViewDefinition(String schemaName, String viewName)
           
 boolean hasDatabaseChangeLogLockTable()
           
 boolean hasDatabaseChangeLogTable()
           
 int hashCode()
           
 boolean isAutoCommit()
           
protected  boolean isDateOnly(String isoDate)
           
protected  boolean isDateTime(String isoDate)
           
 boolean isLiquibaseTable(String tableName)
           
 boolean isLocalDatabase()
          Default implementation, just look for "local" IPs
 boolean isReservedWord(String string)
           
 boolean isSystemTable(String catalogName, String schemaName, String tableName)
           
 boolean isSystemView(String catalogName, String schemaName, String viewName)
           
protected  boolean isTimeOnly(String isoDate)
           
 void markChangeSetExecStatus(ChangeSet changeSet, ChangeSet.ExecType execType)
          After the change set has been ran against the database this method will update the change log table with the information.
 Date parseDate(String dateAsString)
           
 void removeRanStatus(ChangeSet changeSet)
           
 boolean requiresPassword()
           
 boolean requiresUsername()
           
 void reset()
           
 void rollback()
           
 void saveRollbackStatement(Change change, List<SqlVisitor> sqlVisitors, Writer writer)
           
 void saveStatements(Change change, List<SqlVisitor> sqlVisitors, Writer writer)
           
 void setAutoCommit(boolean b)
           
 void setCanCacheLiquibaseTableInfo(boolean canCacheLiquibaseTableInfo)
           
 void setConnection(DatabaseConnection conn)
           
 void setCurrentDateTimeFunction(String function)
           
 void setDatabaseChangeLogLockTableName(String tableName)
          Set the table name of the change log lock to the given table name
 void setDatabaseChangeLogTableName(String tableName)
          Set the table name of the change log to the given table name
 void setDefaultSchemaName(String schemaName)
           
 boolean shouldQuoteValue(String value)
           
 boolean supportsAutoIncrement()
           
 boolean supportsDDLInTransaction()
          By default databases should support DDL within a transaction.
 boolean supportsDropTableCascadeConstraints()
           
 boolean supportsForeignKeyDisable()
           
 boolean supportsRestrictForeignKeys()
           
 boolean supportsSchemas()
           
 boolean supportsSequences()
          Does the database type support sequence.
 void tag(String tagString)
          Tags the database changelog with the given string.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface liquibase.database.Database
getCurrentDateTimeFunction, getDefaultDriver, getTypeName, isCorrectDatabaseImplementation, supportsInitiallyDeferrableColumns, supportsTablespaces
 
Methods inherited from interface liquibase.servicelocator.PrioritizedService
getPriority
 

Field Detail

currentDateTimeFunction

protected String currentDateTimeFunction

databaseFunctions

protected List<DatabaseFunction> databaseFunctions
Constructor Detail

AbstractDatabase

protected AbstractDatabase()
Method Detail

requiresPassword

public boolean requiresPassword()
Specified by:
requiresPassword in interface Database

requiresUsername

public boolean requiresUsername()
Specified by:
requiresUsername in interface Database

getContainingObjects

public DatabaseObject[] getContainingObjects()
Specified by:
getContainingObjects in interface DatabaseObject

getConnection

public DatabaseConnection getConnection()
Specified by:
getConnection in interface Database

setConnection

public void setConnection(DatabaseConnection conn)
Specified by:
setConnection in interface Database

getAutoCommitMode

public boolean getAutoCommitMode()
Auto-commit mode to run in

Specified by:
getAutoCommitMode in interface Database

supportsDDLInTransaction

public boolean supportsDDLInTransaction()
By default databases should support DDL within a transaction.

Specified by:
supportsDDLInTransaction in interface Database
Returns:
True if the database supports DDL within a transaction, otherwise false.

getDatabaseProductName

public String getDatabaseProductName()
Returns the name of the database product according to the underlying database.

Specified by:
getDatabaseProductName in interface Database

getDatabaseProductVersion

public String getDatabaseProductVersion()
                                 throws DatabaseException
Specified by:
getDatabaseProductVersion in interface Database
Throws:
DatabaseException

getDatabaseMajorVersion

public int getDatabaseMajorVersion()
                            throws DatabaseException
Specified by:
getDatabaseMajorVersion in interface Database
Throws:
DatabaseException

getDatabaseMinorVersion

public int getDatabaseMinorVersion()
                            throws DatabaseException
Specified by:
getDatabaseMinorVersion in interface Database
Throws:
DatabaseException

getDefaultCatalogName

public String getDefaultCatalogName()
                             throws DatabaseException
Specified by:
getDefaultCatalogName in interface Database
Throws:
DatabaseException

getDefaultDatabaseSchemaName

protected String getDefaultDatabaseSchemaName()
                                       throws DatabaseException
Throws:
DatabaseException

getDefaultSchemaName

public String getDefaultSchemaName()
Specified by:
getDefaultSchemaName in interface Database

setDefaultSchemaName

public void setDefaultSchemaName(String schemaName)
                          throws DatabaseException
Specified by:
setDefaultSchemaName in interface Database
Throws:
DatabaseException

getSystemTablesAndViews

protected Set<String> getSystemTablesAndViews()
Returns system (undroppable) tables and views.


supportsSequences

public boolean supportsSequences()
Does the database type support sequence.

Specified by:
supportsSequences in interface Database

supportsAutoIncrement

public boolean supportsAutoIncrement()
Specified by:
supportsAutoIncrement in interface Database

setCurrentDateTimeFunction

public void setCurrentDateTimeFunction(String function)
Specified by:
setCurrentDateTimeFunction in interface Database

getDateLiteral

public String getDateLiteral(String isoDate)
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 interface Database

getDateTimeLiteral

public String getDateTimeLiteral(Timestamp date)
Specified by:
getDateTimeLiteral in interface Database

getDateLiteral

public String getDateLiteral(Date date)
Specified by:
getDateLiteral in interface Database

getTimeLiteral

public String getTimeLiteral(Time date)
Specified by:
getTimeLiteral in interface Database

getDateLiteral

public String getDateLiteral(Date date)
Specified by:
getDateLiteral in interface Database

parseDate

public Date parseDate(String dateAsString)
               throws DateParseException
Specified by:
parseDate in interface Database
Throws:
DateParseException

isDateOnly

protected boolean isDateOnly(String isoDate)

isDateTime

protected boolean isDateTime(String isoDate)

isTimeOnly

protected boolean isTimeOnly(String isoDate)

getLineComment

public String getLineComment()
Returns database-specific line comment string.

Specified by:
getLineComment in interface Database

getAutoIncrementClause

public String getAutoIncrementClause()
Returns database-specific auto-increment DDL clause.

Specified by:
getAutoIncrementClause in interface Database

getConcatSql

public String getConcatSql(String... values)
Description copied from interface: Database
Returns SQL to concat the passed values.

Specified by:
getConcatSql in interface Database

getDatabaseChangeLogTableName

public String getDatabaseChangeLogTableName()
Specified by:
getDatabaseChangeLogTableName in interface Database
See Also:
Database.getDatabaseChangeLogTableName()

getDatabaseChangeLogLockTableName

public String getDatabaseChangeLogLockTableName()
Specified by:
getDatabaseChangeLogLockTableName in interface Database
See Also:
Database.getDatabaseChangeLogLockTableName()

setDatabaseChangeLogTableName

public void setDatabaseChangeLogTableName(String tableName)
Description copied from interface: Database
Set the table name of the change log to the given table name

Specified by:
setDatabaseChangeLogTableName in interface Database
See Also:
Database.setDatabaseChangeLogTableName(java.lang.String)

setDatabaseChangeLogLockTableName

public void setDatabaseChangeLogLockTableName(String tableName)
Description copied from interface: Database
Set the table name of the change log lock to the given table name

Specified by:
setDatabaseChangeLogLockTableName in interface Database
See Also:
Database.setDatabaseChangeLogLockTableName(java.lang.String)

checkDatabaseChangeLogTable

public void checkDatabaseChangeLogTable(boolean updateExistingNullChecksums,
                                        DatabaseChangeLog databaseChangeLog,
                                        String... contexts)
                                 throws DatabaseException
This method will check the database ChangeLog table used to keep track of the changes in the file. If the table does not exist it will create one otherwise it will not do anything besides outputting a log message.

Specified by:
checkDatabaseChangeLogTable in interface Database
Parameters:
updateExistingNullChecksums -
contexts -
Throws:
DatabaseException

canCreateChangeLogTable

protected boolean canCreateChangeLogTable()
                                   throws DatabaseException
Throws:
DatabaseException

setCanCacheLiquibaseTableInfo

public void setCanCacheLiquibaseTableInfo(boolean canCacheLiquibaseTableInfo)
Specified by:
setCanCacheLiquibaseTableInfo in interface Database

hasDatabaseChangeLogTable

public boolean hasDatabaseChangeLogTable()
                                  throws DatabaseException
Specified by:
hasDatabaseChangeLogTable in interface Database
Throws:
DatabaseException

hasDatabaseChangeLogLockTable

public boolean hasDatabaseChangeLogLockTable()
                                      throws DatabaseException
Specified by:
hasDatabaseChangeLogLockTable in interface Database
Throws:
DatabaseException

getLiquibaseSchemaName

public String getLiquibaseSchemaName()
Specified by:
getLiquibaseSchemaName in interface Database

checkDatabaseChangeLogLockTable

public void checkDatabaseChangeLogLockTable()
                                     throws DatabaseException
This method will check the database ChangeLogLock table used to keep track of if a machine is updating the database. If the table does not exist it will create one otherwise it will not do anything besides outputting a log message.

Specified by:
checkDatabaseChangeLogLockTable in interface Database
Throws:
DatabaseException

isReservedWord

public boolean isReservedWord(String string)
Specified by:
isReservedWord in interface Database

dropDatabaseObjects

public void dropDatabaseObjects(String schema)
                         throws DatabaseException
Drops all objects owned by the connected user.

Specified by:
dropDatabaseObjects in interface Database
Parameters:
schema -
Throws:
DatabaseException

supportsDropTableCascadeConstraints

public boolean supportsDropTableCascadeConstraints()
Specified by:
supportsDropTableCascadeConstraints in interface Database

isSystemTable

public boolean isSystemTable(String catalogName,
                             String schemaName,
                             String tableName)
Specified by:
isSystemTable in interface Database

isSystemView

public boolean isSystemView(String catalogName,
                            String schemaName,
                            String viewName)
Specified by:
isSystemView in interface Database

isLiquibaseTable

public boolean isLiquibaseTable(String tableName)
Specified by:
isLiquibaseTable in interface Database

tag

public void tag(String tagString)
         throws DatabaseException
Tags the database changelog with the given string.

Specified by:
tag in interface Database
Throws:
DatabaseException

doesTagExist

public boolean doesTagExist(String tag)
                     throws DatabaseException
Specified by:
doesTagExist in interface Database
Throws:
DatabaseException

toString

public String toString()
Overrides:
toString in class Object

shouldQuoteValue

public boolean shouldQuoteValue(String value)
Specified by:
shouldQuoteValue in interface Database

getViewDefinition

public String getViewDefinition(String schemaName,
                                String viewName)
                         throws DatabaseException
Specified by:
getViewDefinition in interface Database
Throws:
DatabaseException

escapeTableName

public String escapeTableName(String schemaName,
                              String tableName)
Description copied from interface: Database
Escapes the table name in a database-dependent manner so reserved words can be used as a table name (i.e. "order"). Currently only escapes MS-SQL because other DBMSs store table names case-sensitively when escaping is used which could confuse end-users. Pass null to schemaName to use the default schema

Specified by:
escapeTableName in interface Database

escapeDatabaseObject

public String escapeDatabaseObject(String objectName)
Specified by:
escapeDatabaseObject in interface Database

escapeIndexName

public String escapeIndexName(String schemaName,
                              String indexName)
Specified by:
escapeIndexName in interface Database

escapeSequenceName

public String escapeSequenceName(String schemaName,
                                 String sequenceName)
Specified by:
escapeSequenceName in interface Database

escapeConstraintName

public String escapeConstraintName(String constraintName)
Specified by:
escapeConstraintName in interface Database

escapeColumnName

public String escapeColumnName(String schemaName,
                               String tableName,
                               String columnName)
Description copied from interface: Database
Escapes a single column name in a database-dependent manner so reserved words can be used as a column name (i.e. "return").

Specified by:
escapeColumnName in interface Database
columnName - column name
Returns:
escaped column name

escapeColumnNameList

public String escapeColumnNameList(String columnNames)
Description copied from interface: Database
Escapes a list of column names in a database-dependent manner so reserved words can be used as a column name (i.e. "return").

Specified by:
escapeColumnNameList in interface Database
Parameters:
columnNames - list of column names
Returns:
escaped column name list

convertRequestedSchemaToCatalog

public String convertRequestedSchemaToCatalog(String requestedSchema)
                                       throws DatabaseException
Specified by:
convertRequestedSchemaToCatalog in interface Database
Throws:
DatabaseException

convertRequestedSchemaToSchema

public String convertRequestedSchemaToSchema(String requestedSchema)
                                      throws DatabaseException
Specified by:
convertRequestedSchemaToSchema in interface Database
Throws:
DatabaseException

supportsSchemas

public boolean supportsSchemas()
Specified by:
supportsSchemas in interface Database

generatePrimaryKeyName

public String generatePrimaryKeyName(String tableName)
Specified by:
generatePrimaryKeyName in interface Database

escapeViewName

public String escapeViewName(String schemaName,
                             String viewName)
Specified by:
escapeViewName in interface Database

getRunStatus

public ChangeSet.RunStatus getRunStatus(ChangeSet changeSet)
                                 throws DatabaseException,
                                        DatabaseHistoryException
Returns the run status for the given ChangeSet

Specified by:
getRunStatus in interface Database
Throws:
DatabaseException
DatabaseHistoryException

getRanChangeSet

public RanChangeSet getRanChangeSet(ChangeSet changeSet)
                             throws DatabaseException,
                                    DatabaseHistoryException
Specified by:
getRanChangeSet in interface Database
Throws:
DatabaseException
DatabaseHistoryException

getRanChangeSetList

public List<RanChangeSet> getRanChangeSetList()
                                       throws DatabaseException
Returns the ChangeSets that have been run against the current database.

Specified by:
getRanChangeSetList in interface Database
Throws:
DatabaseException

getRanDate

public Date getRanDate(ChangeSet changeSet)
                throws DatabaseException,
                       DatabaseHistoryException
Specified by:
getRanDate in interface Database
Throws:
DatabaseException
DatabaseHistoryException

markChangeSetExecStatus

public void markChangeSetExecStatus(ChangeSet changeSet,
                                    ChangeSet.ExecType execType)
                             throws DatabaseException
After the change set has been ran against the database this method will update the change log table with the information.

Specified by:
markChangeSetExecStatus in interface Database
Throws:
DatabaseException

removeRanStatus

public void removeRanStatus(ChangeSet changeSet)
                     throws DatabaseException
Specified by:
removeRanStatus in interface Database
Throws:
DatabaseException

escapeStringForDatabase

public String escapeStringForDatabase(String string)
Specified by:
escapeStringForDatabase in interface Database

commit

public void commit()
            throws DatabaseException
Specified by:
commit in interface Database
Throws:
DatabaseException

rollback

public void rollback()
              throws DatabaseException
Specified by:
rollback in interface Database
Throws:
DatabaseException

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

close

public void close()
           throws DatabaseException
Specified by:
close in interface Database
Throws:
DatabaseException

supportsRestrictForeignKeys

public boolean supportsRestrictForeignKeys()
Specified by:
supportsRestrictForeignKeys in interface Database

isAutoCommit

public boolean isAutoCommit()
                     throws DatabaseException
Specified by:
isAutoCommit in interface Database
Throws:
DatabaseException

setAutoCommit

public void setAutoCommit(boolean b)
                   throws DatabaseException
Specified by:
setAutoCommit in interface Database
Throws:
DatabaseException

isLocalDatabase

public boolean isLocalDatabase()
                        throws DatabaseException
Default implementation, just look for "local" IPs

Specified by:
isLocalDatabase in interface Database
Throws:
DatabaseException

executeStatements

public void executeStatements(Change change,
                              DatabaseChangeLog changeLog,
                              List<SqlVisitor> sqlVisitors)
                       throws LiquibaseException,
                              UnsupportedChangeException
Specified by:
executeStatements in interface Database
Throws:
LiquibaseException
UnsupportedChangeException

execute

public void execute(SqlStatement[] statements,
                    List<SqlVisitor> sqlVisitors)
             throws LiquibaseException
Specified by:
execute in interface Database
Throws:
LiquibaseException

saveStatements

public void saveStatements(Change change,
                           List<SqlVisitor> sqlVisitors,
                           Writer writer)
                    throws IOException,
                           UnsupportedChangeException,
                           StatementNotSupportedOnDatabaseException,
                           LiquibaseException
Specified by:
saveStatements in interface Database
Throws:
IOException
UnsupportedChangeException
StatementNotSupportedOnDatabaseException
LiquibaseException

executeRollbackStatements

public void executeRollbackStatements(Change change,
                                      List<SqlVisitor> sqlVisitors)
                               throws LiquibaseException,
                                      UnsupportedChangeException,
                                      RollbackImpossibleException
Specified by:
executeRollbackStatements in interface Database
Throws:
LiquibaseException
UnsupportedChangeException
RollbackImpossibleException

saveRollbackStatement

public void saveRollbackStatement(Change change,
                                  List<SqlVisitor> sqlVisitors,
                                  Writer writer)
                           throws IOException,
                                  UnsupportedChangeException,
                                  RollbackImpossibleException,
                                  StatementNotSupportedOnDatabaseException,
                                  LiquibaseException
Specified by:
saveRollbackStatement in interface Database
Throws:
IOException
UnsupportedChangeException
RollbackImpossibleException
StatementNotSupportedOnDatabaseException
LiquibaseException

getNextChangeSetSequenceValue

public int getNextChangeSetSequenceValue()
                                  throws LiquibaseException
Specified by:
getNextChangeSetSequenceValue in interface Database
Throws:
LiquibaseException

getTable

public Table getTable(String schemaName,
                      String tableName)
               throws DatabaseException
Throws:
DatabaseException

getDatabaseFunctions

public List<DatabaseFunction> getDatabaseFunctions()
Description copied from interface: Database
Returns list of database native functions

Specified by:
getDatabaseFunctions in interface Database

reset

public void reset()
Specified by:
reset in interface Database

supportsForeignKeyDisable

public boolean supportsForeignKeyDisable()
Specified by:
supportsForeignKeyDisable in interface Database

disableForeignKeyChecks

public boolean disableForeignKeyChecks()
                                throws DatabaseException
Specified by:
disableForeignKeyChecks in interface Database
Throws:
DatabaseException

enableForeignKeyChecks

public void enableForeignKeyChecks()
                            throws DatabaseException
Specified by:
enableForeignKeyChecks in interface Database
Throws:
DatabaseException


Copyright © 2004-2011 Liquibase.org. All Rights Reserved.