Top Description Fields Constructors Methods
org.springframework.r2dbc.connection.init

public Class ResourceDatabasePopulator

extends Object
implements DatabasePopulator
Class Inheritance
All Implemented Interfaces
org.springframework.r2dbc.connection.init.DatabasePopulator
Imports
java.nio.charset.Charset, java.util.ArrayList, .Arrays, .List, io.r2dbc.spi.Connection, reactor.core.publisher.Flux, .Mono, org.springframework.core.io.Resource, org.springframework.core.io.buffer.DataBufferFactory, .DefaultDataBufferFactory, org.springframework.core.io.support.EncodedResource, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

Populates, initializes, or cleans up a database using SQL scripts defined in external resources.
Authors
Keith Donald, Dave Syer, Juergen Hoeller, Chris Beams, Oliver Gierke, Sam Brannen, Chris Baldwin, Phillip Webb, Mark Paluch
Since
5.3
See Also
ScriptUtils

Field Summary

Modifier and TypeField and Description
private String
private String
private String[]
private boolean
private DataBufferFactory
private boolean
pack-priv List<Resource>
private String
private Charset

Constructor Summary

AccessConstructor and Description
public
ResourceDatabasePopulator()

Create a new ResourceDatabasePopulator with default settings.

public
ResourceDatabasePopulator(Resource...
the scripts to execute to initialize or clean up the database (never null)
scripts
)

Create a new ResourceDatabasePopulator with default settings for the supplied scripts.

public
ResourceDatabasePopulator(boolean
flag to indicate that all failures in SQL should be logged but not cause a failure
continueOnError
,
boolean
flag to indicate that a failed SQL DROP statement can be ignored
ignoreFailedDrops
,
String
the encoding for the supplied SQL scripts (may be null or empty to indicate platform encoding)
sqlScriptEncoding
,
Resource...
the scripts to execute to initialize or clean up the database (never null)
scripts
)

Construct a new ResourceDatabasePopulator with the supplied values.

Method Summary

Modifier and TypeMethod and Description
public void
addScript(Resource
the path to an SQL script (never null)
script
)

Add a script to execute to initialize or clean up the database.

public void
addScripts(Resource...
the scripts to execute (never null)
scripts
)

Add multiple scripts to execute to initialize or clean up the database.

private void
public Mono<Void>
populate(Connection
the R2DBC connection to use to populate the db; already configured and ready to use, must not be null
connection
)

Implements org.springframework.r2dbc.connection.init.DatabasePopulator.populate.

Populate, initialize, or clean up the database using the provided R2DBC Connection.

public void
setBlockCommentEndDelimiter(String
the end delimiter for block comments (never null or empty)
blockCommentEndDelimiter
)

Set the end delimiter that identifies block comments within the SQL scripts.

public void
setBlockCommentStartDelimiter(String
the start delimiter for block comments (never null or empty)
blockCommentStartDelimiter
)

Set the start delimiter that identifies block comments within the SQL scripts.

public void
setCommentPrefix(String
the prefix for single-line comments
commentPrefix
)

Set the prefix that identifies single-line comments within the SQL scripts.

public void
setCommentPrefixes(String...
the prefixes for single-line comments
commentPrefixes
)

Set the prefixes that identify single-line comments within the SQL scripts.

public void
setContinueOnError(boolean
true if script execution should continue on error
continueOnError
)

Flag to indicate that all failures in SQL should be logged but not cause a failure.

public void
setDataBufferFactory(DataBufferFactory
the DataBufferFactory to use, must not be null
dataBufferFactory
)

Set the DataBufferFactory to use for Resource loading.

public void
setIgnoreFailedDrops(boolean
true if failed drop statements should be ignored
ignoreFailedDrops
)

Flag to indicate that a failed SQL DROP statement can be ignored.

public void
setScripts(Resource...
the scripts to execute (never null)
scripts
)

Set the scripts to execute to initialize or clean up the database, replacing any previously added scripts.

public void
setSeparator(String
the script statement separator
separator
)

Specify the statement separator, if a custom one.

public void
setSqlScriptEncoding(String
the encoding used in scripts (may be null or empty to indicate platform encoding)
sqlScriptEncoding
)

Specify the encoding for the configured SQL scripts, if different from the platform encoding.

public void
setSqlScriptEncoding(Charset
the encoding used in scripts (may be null or empty to indicate platform encoding)
sqlScriptEncoding
)

Specify the encoding for the configured SQL scripts, if different from the platform encoding.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockCommentEndDelimiterback to summary
private String blockCommentEndDelimiter
blockCommentStartDelimiterback to summary
private String blockCommentStartDelimiter
commentPrefixesback to summary
private String[] commentPrefixes
continueOnErrorback to summary
private boolean continueOnError
dataBufferFactoryback to summary
private DataBufferFactory dataBufferFactory
ignoreFailedDropsback to summary
private boolean ignoreFailedDrops
scriptsback to summary
pack-priv List<Resource> scripts
separatorback to summary
private String separator
sqlScriptEncodingback to summary
private Charset sqlScriptEncoding
Annotations
@Nullable

Constructor Detail

ResourceDatabasePopulatorback to summary
public ResourceDatabasePopulator()

Create a new ResourceDatabasePopulator with default settings.

ResourceDatabasePopulatorback to summary
public ResourceDatabasePopulator(Resource... scripts)

Create a new ResourceDatabasePopulator with default settings for the supplied scripts.

Parameters
scripts:Resource[]

the scripts to execute to initialize or clean up the database (never null)

ResourceDatabasePopulatorback to summary
public ResourceDatabasePopulator(boolean continueOnError, boolean ignoreFailedDrops, String sqlScriptEncoding, Resource... scripts)

Construct a new ResourceDatabasePopulator with the supplied values.

Parameters
continueOnError:boolean

flag to indicate that all failures in SQL should be logged but not cause a failure

ignoreFailedDrops:boolean

flag to indicate that a failed SQL DROP statement can be ignored

sqlScriptEncoding:String

the encoding for the supplied SQL scripts (may be null or empty to indicate platform encoding)

scripts:Resource[]

the scripts to execute to initialize or clean up the database (never null)

Method Detail

addScriptback to summary
public void addScript(Resource script)

Add a script to execute to initialize or clean up the database.

Parameters
script:Resource

the path to an SQL script (never null)

addScriptsback to summary
public void addScripts(Resource... scripts)

Add multiple scripts to execute to initialize or clean up the database.

Parameters
scripts:Resource[]

the scripts to execute (never null)

assertContentsOfScriptArrayback to summary
private void assertContentsOfScriptArray(Resource... scripts)
populateback to summary
public Mono<Void> populate(Connection connection)

Implements org.springframework.r2dbc.connection.init.DatabasePopulator.populate.

Doc from org.springframework.r2dbc.connection.init.DatabasePopulator.populate.

Populate, initialize, or clean up the database using the provided R2DBC Connection.

Parameters
connection:Connection

the R2DBC connection to use to populate the db; already configured and ready to use, must not be null

Returns:Mono<Void>

Mono that initiates script execution and is notified upon completion

Annotations
@Override
setBlockCommentEndDelimiterback to summary
public void setBlockCommentEndDelimiter(String blockCommentEndDelimiter)

Set the end delimiter that identifies block comments within the SQL scripts.

Defaults to "*/".

Parameters
blockCommentEndDelimiter:String

the end delimiter for block comments (never null or empty)

See Also
setBlockCommentStartDelimiter
setBlockCommentStartDelimiterback to summary
public void setBlockCommentStartDelimiter(String blockCommentStartDelimiter)

Set the start delimiter that identifies block comments within the SQL scripts.

Defaults to "/*".

Parameters
blockCommentStartDelimiter:String

the start delimiter for block comments (never null or empty)

See Also
setBlockCommentEndDelimiter
setCommentPrefixback to summary
public void setCommentPrefix(String commentPrefix)

Set the prefix that identifies single-line comments within the SQL scripts.

Defaults to "--".

Parameters
commentPrefix:String

the prefix for single-line comments

See Also
setCommentPrefixes(String...)
setCommentPrefixesback to summary
public void setCommentPrefixes(String... commentPrefixes)

Set the prefixes that identify single-line comments within the SQL scripts.

Defaults to ["--"].

Parameters
commentPrefixes:String[]

the prefixes for single-line comments

setContinueOnErrorback to summary
public void setContinueOnError(boolean continueOnError)

Flag to indicate that all failures in SQL should be logged but not cause a failure.

Defaults to false.

Parameters
continueOnError:boolean

true if script execution should continue on error

setDataBufferFactoryback to summary
public void setDataBufferFactory(DataBufferFactory dataBufferFactory)

Set the DataBufferFactory to use for Resource loading.

Defaults to DefaultDataBufferFactory.

Parameters
dataBufferFactory:DataBufferFactory

the DataBufferFactory to use, must not be null

setIgnoreFailedDropsback to summary
public void setIgnoreFailedDrops(boolean ignoreFailedDrops)

Flag to indicate that a failed SQL 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.

Parameters
ignoreFailedDrops:boolean

true if failed drop statements should be ignored

setScriptsback to summary
public void setScripts(Resource... scripts)

Set the scripts to execute to initialize or clean up the database, replacing any previously added scripts.

Parameters
scripts:Resource[]

the scripts to execute (never null)

setSeparatorback to summary
public void setSeparator(String separator)

Specify the statement separator, if a custom one.

Defaults to ";" 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.

Parameters
separator:String

the script statement separator

setSqlScriptEncodingback to summary
public void setSqlScriptEncoding(String sqlScriptEncoding)

Specify the encoding for the configured SQL scripts, if different from the platform encoding.

Parameters
sqlScriptEncoding:String

the encoding used in scripts (may be null or empty to indicate platform encoding)

See Also
addScript(Resource)
setSqlScriptEncodingback to summary
public void setSqlScriptEncoding(Charset sqlScriptEncoding)

Specify the encoding for the configured SQL scripts, if different from the platform encoding.

Parameters
sqlScriptEncoding:Charset

the encoding used in scripts (may be null or empty to indicate platform encoding)

See Also
addScript(Resource)