org.unitils.dbmaintainer.clean.impl
Class DefaultDBCleaner

java.lang.Object
  extended by org.unitils.dbmaintainer.util.BaseDatabaseAccessor
      extended by org.unitils.dbmaintainer.clean.impl.DefaultDBCleaner
All Implemented Interfaces:
DBCleaner, DatabaseAccessing

public class DefaultDBCleaner
extends BaseDatabaseAccessor
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. This includes the tables that are listed in the property PROPKEY_PRESERVE_TABLES, PROPKEY_PRESERVE_DATA_TABLES. and the table that is configured as version table using the property PROPKEY_VERSION_TABLE_NAME.

Author:
Tim Ducheyne, Filip Neven

Field Summary
static String PROPKEY_PRESERVE_DATA_SCHEMAS
          Property key for schemas in which none of the tables should be cleaned
static String PROPKEY_PRESERVE_DATA_TABLES
          Property key for the tables that should not be cleaned
static String PROPKEY_PRESERVE_TABLES
          Property that specifies which tables should not be dropped (should also not be cleaned)
static String PROPKEY_VERSION_TABLE_NAME
          The key of the property that specifies the name of the datase table in which the DB version is stored.
protected  Set<String> schemasToPreserve
          Names of schemas that should left untouched.
protected  Set<String> tablesToPreserve
          The tables that should not be cleaned
 
Fields inherited from class org.unitils.dbmaintainer.util.BaseDatabaseAccessor
configuration, dbSupports, defaultDbSupport, sqlHandler
 
Constructor Summary
DefaultDBCleaner()
           
 
Method Summary
 void cleanSchemas()
          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(String tableName, DbSupport dbSupport)
          Deletes the data in the table with the given name.
protected  void doInit(Properties configuration)
          Configures this object.
protected  Set<String> getItemsToPreserve(String propertyName, boolean prefixDefaultSchema)
          Gets the list of items to preserve.
protected  boolean isItemToPreserve(String item, Set<String> itemsToPreserve)
          Checks whether the given item is one of the items to preserve.
 
Methods inherited from class org.unitils.dbmaintainer.util.BaseDatabaseAccessor
getDbSupport, init
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.unitils.dbmaintainer.util.DatabaseAccessing
init
 

Field Detail

PROPKEY_PRESERVE_DATA_SCHEMAS

public static final String PROPKEY_PRESERVE_DATA_SCHEMAS
Property key for schemas in which none of the tables should be cleaned

See Also:
Constant Field Values

PROPKEY_PRESERVE_DATA_TABLES

public static final String PROPKEY_PRESERVE_DATA_TABLES
Property key for the tables that should not be cleaned

See Also:
Constant Field Values

PROPKEY_PRESERVE_TABLES

public static final String PROPKEY_PRESERVE_TABLES
Property that specifies which tables should not be dropped (should also not be cleaned)

See Also:
Constant Field Values

PROPKEY_VERSION_TABLE_NAME

public static final String PROPKEY_VERSION_TABLE_NAME
The key of the property that specifies the name of the datase table in which the DB version is stored. This table should not be deleted

See Also:
Constant Field Values

schemasToPreserve

protected Set<String> schemasToPreserve
Names of schemas that should left untouched.


tablesToPreserve

protected Set<String> tablesToPreserve
The tables that should not be cleaned

Constructor Detail

DefaultDBCleaner

public DefaultDBCleaner()
Method Detail

doInit

protected void doInit(Properties configuration)
Configures this object.

Overrides:
doInit in class BaseDatabaseAccessor
Parameters:
configuration - The configuration, not null

cleanSchemas

public void cleanSchemas()
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:
cleanSchemas in interface DBCleaner

cleanTable

protected void cleanTable(String tableName,
                          DbSupport dbSupport)
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:
tableName - The name of the table that need to be cleared, not null
dbSupport - The database support, not null

isItemToPreserve

protected boolean isItemToPreserve(String item,
                                   Set<String> itemsToPreserve)
Checks whether the given item is one of the items to preserve. This also handles identifiers that are stored in mixed case.

Parameters:
item - The item, not null
itemsToPreserve - The items to preserve, not null
Returns:
True if item to preserve

getItemsToPreserve

protected Set<String> getItemsToPreserve(String propertyName,
                                         boolean prefixDefaultSchema)
Gets the list of items to preserve. The case is correct if necesary. Quoting an identifier makes it case sensitive. If requested, the identifiers will be quailified with the default schema name if no schema name is used as prefix.

Parameters:
propertyName - The name of the property that defines the items, not null
prefixDefaultSchema - True to prefix item with default schema when needed
Returns:
The set of items, not null


Copyright © 2011. All Rights Reserved.