liquibase.database.structure
Class SqlDatabaseSnapshot

java.lang.Object
  extended by liquibase.database.structure.SqlDatabaseSnapshot
All Implemented Interfaces:
DatabaseSnapshot
Direct Known Subclasses:
CacheDatabaseSnapshot, DB2DatabaseSnapshot, DerbyDatabaseSnapshot, FirebirdDatabaseSnapshot, HsqlDatabaseSnapshot, MaxDBDatabaseSnapshot, MSSQLDatabaseSnapshot, MySqlDatabaseSnapshot, OracleDatabaseSnapshot, PostgresDatabaseSnapshot, SQLiteDatabaseSnapshot, SybaseASADatabaseSnapshot, UnsupportedDatabaseSnapshot

public abstract class SqlDatabaseSnapshot
extends java.lang.Object
implements DatabaseSnapshot


Field Summary
protected  java.util.Set<Column> columns
           
protected  java.util.Map<java.lang.String,Column> columnsMap
           
protected  Database database
           
protected  java.sql.DatabaseMetaData databaseMetaData
           
protected  java.util.Set<ForeignKey> foreignKeys
           
protected  java.util.Set<Index> indexes
           
protected static java.util.logging.Logger log
           
protected  java.util.Set<PrimaryKey> primaryKeys
           
protected  java.util.Set<Sequence> sequences
           
protected  java.util.Set<Table> tables
           
protected  java.util.Map<java.lang.String,Table> tablesMap
           
protected  java.util.Set<UniqueConstraint> uniqueConstraints
           
protected  java.util.Set<View> views
           
protected  java.util.Map<java.lang.String,View> viewsMap
           
 
Constructor Summary
SqlDatabaseSnapshot()
          Creates an empty database snapshot
SqlDatabaseSnapshot(Database database)
          Creates a snapshot of the given database with no status listeners
SqlDatabaseSnapshot(Database database, java.util.Set<DiffStatusListener> statusListeners)
          Creates a snapshot of the given database.
SqlDatabaseSnapshot(Database database, java.util.Set<DiffStatusListener> statusListeners, java.lang.String requestedSchema)
          Creates a snapshot of the given database.
SqlDatabaseSnapshot(Database database, java.lang.String schema)
          Creates a snapshot of the given database with no status listeners
 
Method Summary
protected  java.lang.String convertFromDatabaseName(java.lang.String objectName)
           
protected  java.lang.String convertPrimaryKeyName(java.lang.String pkName)
           
 Column getColumn(Column column)
           
 Column getColumn(java.lang.String tableName, java.lang.String columnName)
           
 java.util.Set<Column> getColumns()
           
protected  void getColumnTypeAndDefValue(Column columnInfo, java.sql.ResultSet rs, Database database)
          Method assigns correct column type and default value to Column object.
 Database getDatabase()
           
 ForeignKey getForeignKey(java.lang.String foreignKeyName)
           
 java.util.Set<ForeignKey> getForeignKeys()
           
 Index getIndex(java.lang.String indexName)
           
 java.util.Set<Index> getIndexes()
           
 PrimaryKey getPrimaryKey(java.lang.String pkName)
           
 PrimaryKey getPrimaryKeyForTable(java.lang.String tableName)
           
 java.util.Set<PrimaryKey> getPrimaryKeys()
           
 java.lang.String getSchema()
           
 Sequence getSequence(java.lang.String sequenceName)
           
 java.util.Set<Sequence> getSequences()
           
 Table getTable(java.lang.String tableName)
          Returns the table object for the given tableName.
 java.util.Set<Table> getTables()
           
 UniqueConstraint getUniqueConstraint(java.lang.String ucName)
           
 java.util.Set<UniqueConstraint> getUniqueConstraints()
           
 View getView(java.lang.String viewName)
           
 java.util.Set<View> getViews()
           
 boolean hasDatabaseChangeLogTable()
           
protected  boolean isPrimaryKey(Column columnInfo)
           
protected  void readColumns(java.lang.String schema)
           
protected  void readForeignKeyInformation(java.lang.String schema)
           
protected  void readIndexes(java.lang.String schema)
           
protected  void readPrimaryKeys(java.lang.String schema)
           
protected  void readSequences(java.lang.String schema)
           
protected  void readTablesAndViews(java.lang.String schema)
           
protected  void readUniqueConstraints(java.lang.String schema)
           
protected  void updateListeners(java.lang.String message)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

databaseMetaData

protected java.sql.DatabaseMetaData databaseMetaData

database

protected Database database

tables

protected java.util.Set<Table> tables

views

protected java.util.Set<View> views

columns

protected java.util.Set<Column> columns

foreignKeys

protected java.util.Set<ForeignKey> foreignKeys

uniqueConstraints

protected java.util.Set<UniqueConstraint> uniqueConstraints

indexes

protected java.util.Set<Index> indexes

primaryKeys

protected java.util.Set<PrimaryKey> primaryKeys

sequences

protected java.util.Set<Sequence> sequences

tablesMap

protected java.util.Map<java.lang.String,Table> tablesMap

viewsMap

protected java.util.Map<java.lang.String,View> viewsMap

columnsMap

protected java.util.Map<java.lang.String,Column> columnsMap

log

protected static final java.util.logging.Logger log
Constructor Detail

SqlDatabaseSnapshot

public SqlDatabaseSnapshot()
Creates an empty database snapshot


SqlDatabaseSnapshot

public SqlDatabaseSnapshot(Database database)
                    throws JDBCException
Creates a snapshot of the given database with no status listeners

Throws:
JDBCException

SqlDatabaseSnapshot

public SqlDatabaseSnapshot(Database database,
                           java.lang.String schema)
                    throws JDBCException
Creates a snapshot of the given database with no status listeners

Throws:
JDBCException

SqlDatabaseSnapshot

public SqlDatabaseSnapshot(Database database,
                           java.util.Set<DiffStatusListener> statusListeners)
                    throws JDBCException
Creates a snapshot of the given database.

Throws:
JDBCException

SqlDatabaseSnapshot

public SqlDatabaseSnapshot(Database database,
                           java.util.Set<DiffStatusListener> statusListeners,
                           java.lang.String requestedSchema)
                    throws JDBCException
Creates a snapshot of the given database.

Throws:
JDBCException
Method Detail

getDatabase

public Database getDatabase()
Specified by:
getDatabase in interface DatabaseSnapshot

getTables

public java.util.Set<Table> getTables()
Specified by:
getTables in interface DatabaseSnapshot

getViews

public java.util.Set<View> getViews()
Specified by:
getViews in interface DatabaseSnapshot

getColumn

public Column getColumn(Column column)
Specified by:
getColumn in interface DatabaseSnapshot

getColumn

public Column getColumn(java.lang.String tableName,
                        java.lang.String columnName)
Specified by:
getColumn in interface DatabaseSnapshot

getColumns

public java.util.Set<Column> getColumns()
Specified by:
getColumns in interface DatabaseSnapshot

getForeignKeys

public java.util.Set<ForeignKey> getForeignKeys()
Specified by:
getForeignKeys in interface DatabaseSnapshot

getIndexes

public java.util.Set<Index> getIndexes()
Specified by:
getIndexes in interface DatabaseSnapshot

getPrimaryKeys

public java.util.Set<PrimaryKey> getPrimaryKeys()
Specified by:
getPrimaryKeys in interface DatabaseSnapshot

getSequences

public java.util.Set<Sequence> getSequences()
Specified by:
getSequences in interface DatabaseSnapshot

getUniqueConstraints

public java.util.Set<UniqueConstraint> getUniqueConstraints()
Specified by:
getUniqueConstraints in interface DatabaseSnapshot

readTablesAndViews

protected void readTablesAndViews(java.lang.String schema)
                           throws java.sql.SQLException,
                                  JDBCException
Throws:
java.sql.SQLException
JDBCException

convertFromDatabaseName

protected java.lang.String convertFromDatabaseName(java.lang.String objectName)

readColumns

protected void readColumns(java.lang.String schema)
                    throws java.sql.SQLException,
                           JDBCException
Throws:
java.sql.SQLException
JDBCException

getColumnTypeAndDefValue

protected void getColumnTypeAndDefValue(Column columnInfo,
                                        java.sql.ResultSet rs,
                                        Database database)
                                 throws java.sql.SQLException,
                                        JDBCException
Method assigns correct column type and default value to Column object.

This method should be database engine specific. JDBC implementation requires database engine vendors to convert native DB types to java objects. During conversion some metadata information are being lost or reported incorrectly via DatabaseMetaData objects. This method, if necessary, must be overriden. It must go below DatabaseMetaData implementation and talk directly to database to get correct metadata information.

Parameters:
rs -
Throws:
java.sql.SQLException
JDBCException

isPrimaryKey

protected boolean isPrimaryKey(Column columnInfo)

readForeignKeyInformation

protected void readForeignKeyInformation(java.lang.String schema)
                                  throws JDBCException,
                                         java.sql.SQLException
Throws:
JDBCException
java.sql.SQLException

readIndexes

protected void readIndexes(java.lang.String schema)
                    throws JDBCException,
                           java.sql.SQLException
Throws:
JDBCException
java.sql.SQLException

readPrimaryKeys

protected void readPrimaryKeys(java.lang.String schema)
                        throws JDBCException,
                               java.sql.SQLException
Throws:
JDBCException
java.sql.SQLException

convertPrimaryKeyName

protected java.lang.String convertPrimaryKeyName(java.lang.String pkName)
                                          throws java.sql.SQLException
Throws:
java.sql.SQLException

readUniqueConstraints

protected void readUniqueConstraints(java.lang.String schema)
                              throws JDBCException,
                                     java.sql.SQLException
Throws:
JDBCException
java.sql.SQLException

readSequences

protected void readSequences(java.lang.String schema)
                      throws JDBCException
Throws:
JDBCException

updateListeners

protected void updateListeners(java.lang.String message)

getTable

public Table getTable(java.lang.String tableName)
Description copied from interface: DatabaseSnapshot
Returns the table object for the given tableName. If table does not exist, returns null

Specified by:
getTable in interface DatabaseSnapshot

getForeignKey

public ForeignKey getForeignKey(java.lang.String foreignKeyName)
Specified by:
getForeignKey in interface DatabaseSnapshot

getSequence

public Sequence getSequence(java.lang.String sequenceName)
Specified by:
getSequence in interface DatabaseSnapshot

getIndex

public Index getIndex(java.lang.String indexName)
Specified by:
getIndex in interface DatabaseSnapshot

getView

public View getView(java.lang.String viewName)
Specified by:
getView in interface DatabaseSnapshot

getPrimaryKey

public PrimaryKey getPrimaryKey(java.lang.String pkName)
Specified by:
getPrimaryKey in interface DatabaseSnapshot

getPrimaryKeyForTable

public PrimaryKey getPrimaryKeyForTable(java.lang.String tableName)
Specified by:
getPrimaryKeyForTable in interface DatabaseSnapshot

getUniqueConstraint

public UniqueConstraint getUniqueConstraint(java.lang.String ucName)
Specified by:
getUniqueConstraint in interface DatabaseSnapshot

getSchema

public java.lang.String getSchema()
Specified by:
getSchema in interface DatabaseSnapshot

hasDatabaseChangeLogTable

public boolean hasDatabaseChangeLogTable()
Specified by:
hasDatabaseChangeLogTable in interface DatabaseSnapshot