org.springframework.jdbc.datasource.init
Class DataSourceInitializer

java.lang.Object
  extended by org.springframework.jdbc.datasource.init.DataSourceInitializer
All Implemented Interfaces:
DisposableBean, InitializingBean

public class DataSourceInitializer
extends Object
implements InitializingBean, DisposableBean

Used to populate a database during initialization.

Since:
3.0
Author:
Dave Syer
See Also:
DatabasePopulator

Constructor Summary
DataSourceInitializer()
           
 
Method Summary
 void afterPropertiesSet()
          Use the populator to set up data in the data source.
 void destroy()
          Use the populator to clean up data in the data source.
 void setDatabaseCleaner(DatabasePopulator databaseCleaner)
          Set a script execution to be run in the bean destruction callback, cleaning up the database and leaving it in a known state for others.
 void setDatabasePopulator(DatabasePopulator databasePopulator)
          The DatabasePopulator to use to populate the data source.
 void setDataSource(DataSource dataSource)
          The DataSource to populate when this component is initialized.
 void setEnabled(boolean enabled)
          Flag to explicitly enable or disable the database populator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataSourceInitializer

public DataSourceInitializer()
Method Detail

setDataSource

public void setDataSource(DataSource dataSource)
The DataSource to populate when this component is initialized. Mandatory with no default.

Parameters:
dataSource - the DataSource

setDatabasePopulator

public void setDatabasePopulator(DatabasePopulator databasePopulator)
The DatabasePopulator to use to populate the data source. Mandatory with no default.

Parameters:
databasePopulator - the database populator to use.

setDatabaseCleaner

public void setDatabaseCleaner(DatabasePopulator databaseCleaner)
Set a script execution to be run in the bean destruction callback, cleaning up the database and leaving it in a known state for others.

Parameters:
databaseCleaner - the database script executor to run on destroy

setEnabled

public void setEnabled(boolean enabled)
Flag to explicitly enable or disable the database populator.

Parameters:
enabled - true if the database populator will be called on startup

afterPropertiesSet

public void afterPropertiesSet()
Use the populator to set up data in the data source.

Specified by:
afterPropertiesSet in interface InitializingBean

destroy

public void destroy()
Use the populator to clean up data in the data source.

Specified by:
destroy in interface DisposableBean