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 java.lang.Object
implements InitializingBean, DisposableBean

Used to populate a database during initialization.

Since:
3.0
Author:
Dave Syer
See Also:
DatabasePopulator

Field Summary
private  DatabasePopulator databaseCleaner
           
private  DatabasePopulator databasePopulator
           
private  javax.sql.DataSource dataSource
           
private  boolean enabled
           
 
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(javax.sql.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
 

Field Detail

dataSource

private javax.sql.DataSource dataSource

databasePopulator

private DatabasePopulator databasePopulator

databaseCleaner

private DatabasePopulator databaseCleaner

enabled

private boolean enabled
Constructor Detail

DataSourceInitializer

public DataSourceInitializer()
Method Detail

setDataSource

public void setDataSource(javax.sql.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