Class ResourceKeyspacePopulator
- All Implemented Interfaces:
KeyspacePopulator
- Call
addScript(org.springframework.core.io.Resource)to add a single CQL script location. - Call
addScripts(org.springframework.core.io.Resource...)to add multiple CQL script locations. - Consult the setter methods in this class for further configuration options.
- Call
populate(com.datastax.oss.driver.api.core.CqlSession)orexecute(org.springframework.data.cassandra.SessionFactory)to initialize or clean up the database using the configured scripts.
- Since:
- 3.0
- Author:
- Mark Paluch
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstruct a newResourceKeyspacePopulatorwith default settings.ResourceKeyspacePopulator(boolean continueOnError, boolean ignoreFailedDrops, String cqlScriptEncoding, Resource... scripts) Construct a newResourceKeyspacePopulatorwith the supplied values.ResourceKeyspacePopulator(Resource... scripts) Construct a newResourceKeyspacePopulatorwith default settings for the supplied scripts. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a script to execute to initialize or clean up the database.voidaddScripts(Resource... scripts) Add multiple scripts to execute to initialize or clean up the database.voidexecute(SessionFactory sessionFactory) Execute thisResourceKeyspacePopulatoragainst the givenSessionFactory.voidpopulate(com.datastax.oss.driver.api.core.CqlSession session) Populate, initialize, or clean up the database using the provided CqlSession connection.voidsetBlockCommentEndDelimiter(String blockCommentEndDelimiter) Set the end delimiter that identifies block comments within the CQL scripts.voidsetBlockCommentStartDelimiter(String blockCommentStartDelimiter) Set the start delimiter that identifies block comments within the CQL scripts.voidsetCommentPrefix(String commentPrefix) Set the prefix that identifies single-line comments within the CQL scripts.voidsetCommentPrefixes(String... commentPrefixes) Set the prefixes that identify single-line comments within the CQL scripts.voidsetContinueOnError(boolean continueOnError) Flag to indicate that all failures in CQL should be logged but not cause a failure.voidsetCqlScriptEncoding(String cqlScriptEncoding) Specify the encoding for the configured CQL scripts, if different from the platform encoding.voidsetIgnoreFailedDrops(boolean ignoreFailedDrops) Flag to indicate that a failed CQLDROPstatement can be ignored.voidsetScripts(Resource... scripts) Set the scripts to execute to initialize or clean up the database, replacing any previously added scripts.voidsetSeparator(String separator) Specify the statement separator, if a custom one.
-
Constructor Details
-
ResourceKeyspacePopulator
public ResourceKeyspacePopulator()Construct a newResourceKeyspacePopulatorwith default settings. -
ResourceKeyspacePopulator
Construct a newResourceKeyspacePopulatorwith default settings for the supplied scripts.- Parameters:
scripts- the scripts to execute to initialize or clean up the database (never null)
-
ResourceKeyspacePopulator
public ResourceKeyspacePopulator(boolean continueOnError, boolean ignoreFailedDrops, @Nullable String cqlScriptEncoding, Resource... scripts) Construct a newResourceKeyspacePopulatorwith the supplied values.- Parameters:
continueOnError- flag to indicate that all failures in CQL should be logged but not cause a failureignoreFailedDrops- flag to indicate that a failed CQLDROPstatement can be ignoredcqlScriptEncoding- the encoding for the supplied CQL scripts (may be null or empty to indicate platform encoding)scripts- the scripts to execute to initialize or clean up the database (never null)
-
-
Method Details
-
addScript
Add a script to execute to initialize or clean up the database.- Parameters:
script- the path to an CQL script (never null).
-
addScripts
Add multiple scripts to execute to initialize or clean up the database.- Parameters:
scripts- the scripts to execute (never null).
-
setScripts
Set the scripts to execute to initialize or clean up the database, replacing any previously added scripts.- Parameters:
scripts- the scripts to execute (never null).
-
setCqlScriptEncoding
Specify the encoding for the configured CQL scripts, if different from the platform encoding.- Parameters:
cqlScriptEncoding- the encoding used in scripts (may be null or empty to indicate platform encoding).- See Also:
-
setSeparator
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 toScriptUtils.EOF_STATEMENT_SEPARATORto signal that each script contains a single statement without a separator.- Parameters:
separator- the script statement separator.
-
setCommentPrefix
Set the prefix that identifies single-line comments within the CQL scripts.Defaults to
"--".- Parameters:
commentPrefix- the prefix for single-line comments.- See Also:
-
setCommentPrefixes
Set the prefixes that identify single-line comments within the CQL scripts.Defaults to
["--"].- Parameters:
commentPrefixes- the prefixes for single-line comments.
-
setBlockCommentStartDelimiter
Set the start delimiter that identifies block comments within the CQL scripts.Defaults to
"/*".- Parameters:
blockCommentStartDelimiter- the start delimiter for block comments (never null or empty).- See Also:
-
setBlockCommentEndDelimiter
Set the end delimiter that identifies block comments within the CQL scripts.Defaults to
"*/".- Parameters:
blockCommentEndDelimiter- the end delimiter for block comments (never null or empty).- See Also:
-
setContinueOnError
public void setContinueOnError(boolean continueOnError) Flag to indicate that all failures in CQL should be logged but not cause a failure.Defaults to false.
- Parameters:
continueOnError- true if script execution should continue on error
-
setIgnoreFailedDrops
public void setIgnoreFailedDrops(boolean ignoreFailedDrops) Flag to indicate that a failed CQLDROPstatement can be ignored.This is useful for a non-embedded database whose CQL dialect does not support an
IF EXISTSclause in aDROPstatement.The default is false so that if the populator runs accidentally, it will fail fast if a script starts with a
DROPstatement.- Parameters:
ignoreFailedDrops- true if failed drop statements should be ignored.
-
populate
Description copied from interface:KeyspacePopulatorPopulate, initialize, or clean up the database using the provided CqlSession connection.Concrete implementations may throw a
RuntimeExceptionif an error is encountered but are strongly encouraged to throw a specificScriptExceptioninstead. For example, Spring'sResourceKeyspacePopulatorwrap all exceptions inScriptExceptions.- Specified by:
populatein interfaceKeyspacePopulator- Parameters:
session- the CQLCqlSessionto use to populate the keyspace; already configured and ready to use; never null- Throws:
ScriptException- in all other error cases
-
execute
Execute thisResourceKeyspacePopulatoragainst the givenSessionFactory.- Parameters:
sessionFactory- theSessionFactoryto execute against (never null)- Throws:
ScriptException- if an error occurs- See Also:
-