org.dbmaintain.structure.clear.impl
Class DefaultDBClearer

java.lang.Object
  extended by org.dbmaintain.structure.clear.impl.DefaultDBClearer
All Implemented Interfaces:
DBClearer

public class DefaultDBClearer
extends Object
implements DBClearer

Implementation of DBClearer. This implementation individually drops every table, view, materialized view, synonym, trigger and sequence in the database. A list of tables, views, ... that should be preserved can be specified at construction.

NOTE: FK constraints give problems in MySQL and Derby The cascade in 'drop table A cascade;' does not work in MySQL-5.0 The foreign key constraints will be disabled before this method is called.

Author:
Tim Ducheyne, Filip Neven

Field Summary
protected  ConstraintsDisabler constraintsDisabler
           
protected  Databases databases
           
protected  ExecutedScriptInfoSource executedScriptInfoSource
           
protected  Set<DbItemIdentifier> itemsToPreserve
           
 
Constructor Summary
DefaultDBClearer(Databases databases, Set<DbItemIdentifier> itemsToPreserve, ConstraintsDisabler constraintsDisabler, ExecutedScriptInfoSource executedScriptInfoSource)
           
 
Method Summary
protected  void assertItemsToPreserveExist(Set<DbItemIdentifier> itemsToPreserve)
           
 void clearDatabase()
          Clears the database schemas.
protected  void clearDatabase(Database database)
           
protected  void dropMaterializedViews(Database database, String schemaName)
          Drops all materialized views.
protected  void dropRules(Database database, String schemaName)
          Drops all rules.
protected  void dropSequences(Database database, String schemaName)
          Drops all sequences
protected  void dropStoredProcedures(Database database, String schemaName)
           
protected  void dropSynonyms(Database database, String schemaName)
          Drops all synonyms
protected  void dropTables(Database database, String schemaName)
          Drops all tables.
protected  void dropTriggers(Database database, String schemaName)
          Drops all triggers
protected  void dropTypes(Database database, String schemaName)
          Drops all types.
protected  void dropViews(Database database, String schemaName)
          Drops all views.
protected  Set<DbItemIdentifier> toDbItemIdentifiers(DbItemType type, Database database, String schemaName, Set<String> itemNames)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constraintsDisabler

protected ConstraintsDisabler constraintsDisabler

executedScriptInfoSource

protected ExecutedScriptInfoSource executedScriptInfoSource

itemsToPreserve

protected Set<DbItemIdentifier> itemsToPreserve

databases

protected Databases databases
Constructor Detail

DefaultDBClearer

public DefaultDBClearer(Databases databases,
                        Set<DbItemIdentifier> itemsToPreserve,
                        ConstraintsDisabler constraintsDisabler,
                        ExecutedScriptInfoSource executedScriptInfoSource)
Parameters:
databases - The db support instances, not null
itemsToPreserve - The schema's, tables, triggers etc that should not be dropped, not null
constraintsDisabler - Disables of constraints before clearing the database, not null
executedScriptInfoSource - Clears the executed scripts table, not null
Method Detail

clearDatabase

public void clearDatabase()
Clears the database schemas. This means, all the tables, views, constraints, triggers and sequences are dropped, so that the database schema is empty. The database items that are configured as items to preserve, are left untouched.

Specified by:
clearDatabase in interface DBClearer

clearDatabase

protected void clearDatabase(Database database)

dropTables

protected void dropTables(Database database,
                          String schemaName)
Drops all tables.

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop tables from, not null

dropViews

protected void dropViews(Database database,
                         String schemaName)
Drops all views.

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop views from, not null

dropMaterializedViews

protected void dropMaterializedViews(Database database,
                                     String schemaName)
Drops all materialized views.

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop materialized views from, not null

dropSynonyms

protected void dropSynonyms(Database database,
                            String schemaName)
Drops all synonyms

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop synonyms from, not null

dropSequences

protected void dropSequences(Database database,
                             String schemaName)
Drops all sequences

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop sequences from, not null

dropTriggers

protected void dropTriggers(Database database,
                            String schemaName)
Drops all triggers

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop triggers from, not null

dropStoredProcedures

protected void dropStoredProcedures(Database database,
                                    String schemaName)

dropTypes

protected void dropTypes(Database database,
                         String schemaName)
Drops all types.

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop types from, not null

dropRules

protected void dropRules(Database database,
                         String schemaName)
Drops all rules.

Parameters:
database - The database support, not null
schemaName - The name of the schema to drop rules from, not null

assertItemsToPreserveExist

protected void assertItemsToPreserveExist(Set<DbItemIdentifier> itemsToPreserve)

toDbItemIdentifiers

protected Set<DbItemIdentifier> toDbItemIdentifiers(DbItemType type,
                                                    Database database,
                                                    String schemaName,
                                                    Set<String> itemNames)


Copyright © 2011. All Rights Reserved.