org.dbmaintain.structure.clean.impl
Class DefaultDBCleaner

java.lang.Object
  extended by org.dbmaintain.structure.clean.impl.DefaultDBCleaner
All Implemented Interfaces:
DBCleaner

public class DefaultDBCleaner
extends Object
implements DBCleaner

Implementation of DBCleaner. This implementation will delete all data from a database, except for the tables that are configured as tables to preserve.

Author:
Tim Ducheyne, Filip Neven

Field Summary
protected  Databases databases
           
protected  Set<DbItemIdentifier> itemsToPreserve
           
protected  SQLHandler sqlHandler
           
 
Constructor Summary
DefaultDBCleaner(Databases databases, Set<DbItemIdentifier> itemsToPreserve, SQLHandler sqlHandler)
          Constructor for DefaultDBCleaner.
 
Method Summary
protected  void assertItemsToPreserveExist(Set<DbItemIdentifier> itemsToPreserve)
           
 void cleanDatabase()
          Deletes all data from the database, except for the tables that have been configured as tablesToPreserve , and the table in which the database version is stored
protected  void cleanTable(Database database, String schemaName, String tableName)
          Deletes the data in the table with the given name.
protected  Set<DbItemIdentifier> toDbItemIdentifiers(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

itemsToPreserve

protected Set<DbItemIdentifier> itemsToPreserve

databases

protected Databases databases

sqlHandler

protected SQLHandler sqlHandler
Constructor Detail

DefaultDBCleaner

public DefaultDBCleaner(Databases databases,
                        Set<DbItemIdentifier> itemsToPreserve,
                        SQLHandler sqlHandler)
Constructor for DefaultDBCleaner.

Parameters:
databases - The db support instances, not null
itemsToPreserve - The schema's and tables that should not be cleaned, not null
sqlHandler - The sql handler that will execute the statements, not null
Method Detail

cleanDatabase

public void cleanDatabase()
Deletes all data from the database, except for the tables that have been configured as tablesToPreserve , and the table in which the database version is stored

Specified by:
cleanDatabase in interface DBCleaner

cleanTable

protected void cleanTable(Database database,
                          String schemaName,
                          String tableName)
Deletes the data in the table with the given name. Note: the table name is surrounded with quotes, to make sure that case-sensitive table names are also deleted correctly.

Parameters:
database - The database support, not null
schemaName - The schema name, not null
tableName - The name of the table that need to be cleared, not null

assertItemsToPreserveExist

protected void assertItemsToPreserveExist(Set<DbItemIdentifier> itemsToPreserve)

toDbItemIdentifiers

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


Copyright © 2011. All Rights Reserved.