public class ResourceDatabasePopulator extends Object implements DatabasePopulator
addScript(org.springframework.core.io.Resource) to add a single SQL script location.
addScripts(org.springframework.core.io.Resource...) to add multiple SQL script locations.
populate(io.r2dbc.spi.Connection) or execute(io.r2dbc.spi.ConnectionFactory) to initialize or clean up the database using the configured scripts.
DatabasePopulatorUtils,
ScriptUtils| Constructor and Description |
|---|
ResourceDatabasePopulator()
Creates a new
ResourceDatabasePopulator with default settings. |
ResourceDatabasePopulator(boolean continueOnError,
boolean ignoreFailedDrops,
String sqlScriptEncoding,
Resource... scripts)
Creates a new
ResourceDatabasePopulator with the supplied values. |
ResourceDatabasePopulator(Resource... scripts)
Creates a new
ResourceDatabasePopulator with default settings for the supplied scripts. |
| Modifier and Type | Method and Description |
|---|---|
void |
addScript(Resource script)
Add a script to execute to initialize or clean up the database.
|
void |
addScripts(Resource... scripts)
Add multiple scripts to execute to initialize or clean up the database.
|
reactor.core.publisher.Mono<Void> |
execute(ConnectionFactory connectionFactory)
Execute this
ResourceDatabasePopulator against the given ConnectionFactory. |
reactor.core.publisher.Mono<Void> |
populate(Connection connection)
Populate, initialize, or clean up the database using the provided R2DBC
Connection. |
void |
setBlockCommentEndDelimiter(String blockCommentEndDelimiter)
Set the end delimiter that identifies block comments within the SQL scripts.
|
void |
setBlockCommentStartDelimiter(String blockCommentStartDelimiter)
Set the start delimiter that identifies block comments within the SQL scripts.
|
void |
setCommentPrefix(String commentPrefix)
Set the prefix that identifies single-line comments within the SQL scripts.
|
void |
setContinueOnError(boolean continueOnError)
Flag to indicate that all failures in SQL should be logged but not cause a failure.
|
void |
setDataBufferFactory(DataBufferFactory dataBufferFactory)
Set the
DataBufferFactory to use for Resource loading. |
void |
setIgnoreFailedDrops(boolean ignoreFailedDrops)
Flag to indicate that a failed SQL
DROP statement can be ignored. |
void |
setScripts(Resource... scripts)
Set the scripts to execute to initialize or clean up the database, replacing any previously added scripts.
|
void |
setSeparator(String separator)
Specify the statement separator, if a custom one.
|
void |
setSqlScriptEncoding(Charset sqlScriptEncoding)
Specify the encoding for the configured SQL scripts, if different from the platform encoding.
|
void |
setSqlScriptEncoding(String sqlScriptEncoding)
Specify the encoding for the configured SQL scripts, if different from the platform encoding.
|
public ResourceDatabasePopulator()
ResourceDatabasePopulator with default settings.public ResourceDatabasePopulator(Resource... scripts)
ResourceDatabasePopulator with default settings for the supplied scripts.scripts - the scripts to execute to initialize or clean up the database (never null)public ResourceDatabasePopulator(boolean continueOnError,
boolean ignoreFailedDrops,
@Nullable
String sqlScriptEncoding,
Resource... scripts)
ResourceDatabasePopulator with the supplied values.continueOnError - flag to indicate that all failures in SQL should be logged but not cause a failureignoreFailedDrops - flag to indicate that a failed SQL DROP statement can be ignoredsqlScriptEncoding - the encoding for the supplied SQL scripts (may be null or empty to
indicate platform encoding)scripts - the scripts to execute to initialize or clean up the database, must not be null.public void addScript(Resource script)
script - the path to an SQL script, must not be null.public void addScripts(Resource... scripts)
scripts - the scripts to execute, must not be null.public void setScripts(Resource... scripts)
scripts - the scripts to execute, must not be null.public void setSqlScriptEncoding(@Nullable String sqlScriptEncoding)
sqlScriptEncoding - the encoding used in scripts (may be null or empty to indicate platform
encoding).addScript(Resource)public void setSqlScriptEncoding(@Nullable Charset sqlScriptEncoding)
sqlScriptEncoding - the encoding used in scripts (may be null to indicate platform encoding).addScript(Resource)public void setSeparator(String separator)
";" if not specified and falls back to "\n" as a last resort; may be set to
ScriptUtils.EOF_STATEMENT_SEPARATOR to signal that each script contains a single statement without a
separator.separator - the script statement separator.public void setCommentPrefix(String commentPrefix)
"--".commentPrefix - the prefix for single-line commentspublic void setBlockCommentStartDelimiter(String blockCommentStartDelimiter)
"/*".blockCommentStartDelimiter - the start delimiter for block comments (never null or empty).setBlockCommentEndDelimiter(java.lang.String)public void setBlockCommentEndDelimiter(String blockCommentEndDelimiter)
"*/".blockCommentEndDelimiter - the end delimiter for block comments (never null or empty)setBlockCommentStartDelimiter(java.lang.String)public void setContinueOnError(boolean continueOnError)
continueOnError - true if script execution should continue on error.public void setIgnoreFailedDrops(boolean ignoreFailedDrops)
DROP statement can be ignored.
This is useful for a non-embedded database whose SQL dialect does not support an IF EXISTS clause in a
DROP statement.
The default is false so that if the populator runs accidentally, it will fail fast if a script starts
with a DROP statement.ignoreFailedDrops - true if failed drop statements should be ignored.public void setDataBufferFactory(DataBufferFactory dataBufferFactory)
dataBufferFactory - the DataBufferFactory to use, must not be null.public reactor.core.publisher.Mono<Void> populate(Connection connection) throws ScriptException
DatabasePopulatorConnection.populate in interface DatabasePopulatorconnection - the R2DBC connection to use to populate the db; already configured and ready to use, must not be
null.Mono that initiates script execution and is notified upon completion.ScriptException - in all other error casesDatabasePopulatorUtils.execute(org.springframework.data.r2dbc.connectionfactory.init.DatabasePopulator, io.r2dbc.spi.ConnectionFactory)public reactor.core.publisher.Mono<Void> execute(ConnectionFactory connectionFactory) throws ScriptException
ResourceDatabasePopulator against the given ConnectionFactory.
Delegates to DatabasePopulatorUtils.execute(org.springframework.data.r2dbc.connectionfactory.init.DatabasePopulator, io.r2dbc.spi.ConnectionFactory).connectionFactory - the ConnectionFactory to execute against, must not be null..Mono tthat initiates script execution and is notified upon completion.ScriptException - if an error occurs.populate(Connection)Copyright © 2018–2020 Pivotal Software, Inc.. All rights reserved.