Package org.springframework.jdbc.datasource.init

# Class CompositeDatabasePopulator

java.lang.Object
org.springframework.jdbc.datasource.init.CompositeDatabasePopulator

All Implemented Interfaces:
  `DatabasePopulator`

public class CompositeDatabasePopulator extends Object implements DatabasePopulator
Composite `DatabasePopulator` that delegates to a list of given `DatabasePopulator` implementations, executing all scripts.

Since:
  3.1
Author:
  Dave Syer, Juergen Hoeller, Sam Brannen, Kazuki Shimizu

## Constructor Summary

Constructors
Constructor
Description
`CompositeDatabasePopulator()`
Create an empty `CompositeDatabasePopulator`.
`CompositeDatabasePopulator(Collection<DatabasePopulator> populators)`
Create a `CompositeDatabasePopulator` with the given populators.
`CompositeDatabasePopulator(DatabasePopulator... populators)`
Create a `CompositeDatabasePopulator` with the given populators.

## Method Summary

Modifier and Type
Method
Description
`void`
`addPopulators(DatabasePopulator... populators)`
Add one or more populators to the list of delegates.
`void`
`populate(Connection connection)`
Populate, initialize, or clean up the database using the provided JDBC connection.
`void`
`setPopulators(DatabasePopulator... populators)`
Specify one or more populators to delegate to.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### CompositeDatabasePopulator

public CompositeDatabasePopulator()
Create an empty `CompositeDatabasePopulator`.

See Also:
  - `setPopulators(org.springframework.jdbc.datasource.init.DatabasePopulator...)`
  - `addPopulators(org.springframework.jdbc.datasource.init.DatabasePopulator...)`

### CompositeDatabasePopulator

public CompositeDatabasePopulator(Collection<DatabasePopulator> populators)
Create a `CompositeDatabasePopulator` with the given populators.

Parameters:
  `populators` - one or more populators to delegate to
Since:
  4.3

### CompositeDatabasePopulator

public CompositeDatabasePopulator(DatabasePopulator... populators)
Create a `CompositeDatabasePopulator` with the given populators.

Parameters:
  `populators` - one or more populators to delegate to
Since:
  4.3

## Method Details

### setPopulators

public void setPopulators(DatabasePopulator... populators)
Specify one or more populators to delegate to.

### addPopulators

public void addPopulators(DatabasePopulator... populators)
Add one or more populators to the list of delegates.

### populate

public void populate(Connection connection) throws SQLException, ScriptException
Description copied from interface: `DatabasePopulator`
Populate, initialize, or clean up the database using the provided JDBC connection.

Warning: Concrete implementations should not close the provided `Connection`.

Concrete implementations may throw an `SQLException` if an error is encountered but are strongly encouraged to throw a specific `ScriptException` instead. For example, Spring's `ResourceDatabasePopulator` and `DatabasePopulatorUtils` wrap all `SQLExceptions` in `ScriptExceptions`.

Specified by:
  `populate` in interface `DatabasePopulator`
Parameters:
  `connection` - the JDBC connection to use; already configured and ready to use; never `null`
Throws:
  `SQLException` - if an unrecoverable data access exception occurs while interacting with the database
  `ScriptException` - in all other error cases
See Also:
  - `DatabasePopulatorUtils.execute(org.springframework.jdbc.datasource.init.DatabasePopulator, javax.sql.DataSource)`