public class ResourceKeyspacePopulator extends Object implements KeyspacePopulator
addScript(org.springframework.core.io.Resource) to add a single CQL script location.
addScripts(org.springframework.core.io.Resource...) to add multiple CQL script locations.
populate(com.datastax.oss.driver.api.core.CqlSession) or execute(org.springframework.data.cassandra.SessionFactory) to initialize or clean up the database using the configured scripts.
ScriptUtils| Constructor and Description |
|---|
ResourceKeyspacePopulator()
Construct a new
ResourceKeyspacePopulator with default settings. |
ResourceKeyspacePopulator(boolean continueOnError,
boolean ignoreFailedDrops,
String cqlScriptEncoding,
Resource... scripts)
Construct a new
ResourceKeyspacePopulator with the supplied values. |
ResourceKeyspacePopulator(Resource... scripts)
Construct a new
ResourceKeyspacePopulator 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.
|
void |
execute(SessionFactory sessionFactory)
Execute this
ResourceKeyspacePopulator against the given SessionFactory. |
void |
populate(com.datastax.oss.driver.api.core.CqlSession session)
Populate, initialize, or clean up the database using the provided CqlSession connection.
|
void |
setBlockCommentEndDelimiter(String blockCommentEndDelimiter)
Set the end delimiter that identifies block comments within the CQL scripts.
|
void |
setBlockCommentStartDelimiter(String blockCommentStartDelimiter)
Set the start delimiter that identifies block comments within the CQL scripts.
|
void |
setCommentPrefix(String commentPrefix)
Set the prefix that identifies single-line comments within the CQL scripts.
|
void |
setCommentPrefixes(String... commentPrefixes)
Set the prefixes that identify single-line comments within the CQL scripts.
|
void |
setContinueOnError(boolean continueOnError)
Flag to indicate that all failures in CQL should be logged but not cause a failure.
|
void |
setCqlScriptEncoding(String cqlScriptEncoding)
Specify the encoding for the configured CQL scripts, if different from the platform encoding.
|
void |
setIgnoreFailedDrops(boolean ignoreFailedDrops)
Flag to indicate that a failed CQL
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.
|
public ResourceKeyspacePopulator()
ResourceKeyspacePopulator with default settings.public ResourceKeyspacePopulator(Resource... scripts)
ResourceKeyspacePopulator with default settings for the supplied scripts.scripts - the scripts to execute to initialize or clean up the database (never null)public ResourceKeyspacePopulator(boolean continueOnError,
boolean ignoreFailedDrops,
@Nullable
String cqlScriptEncoding,
Resource... scripts)
ResourceKeyspacePopulator with the supplied values.continueOnError - flag to indicate that all failures in CQL should be logged but not cause a failureignoreFailedDrops - flag to indicate that a failed CQL DROP statement 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)public void addScript(Resource script)
script - the path to an CQL script (never null).public void addScripts(Resource... scripts)
scripts - the scripts to execute (never null).public void setScripts(Resource... scripts)
scripts - the scripts to execute (never null).public void setCqlScriptEncoding(@Nullable String cqlScriptEncoding)
cqlScriptEncoding - the encoding used in scripts (may be null or empty to indicate platform
encoding).addScript(Resource)public void setSeparator(String separator)
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.
separator - the script statement separator.public void setCommentPrefix(String commentPrefix)
Defaults to "--".
commentPrefix - the prefix for single-line comments.setCommentPrefixes(String...)public void setCommentPrefixes(String... commentPrefixes)
Defaults to ["--"].
commentPrefixes - the prefixes for single-line comments.public void setBlockCommentStartDelimiter(String blockCommentStartDelimiter)
Defaults to "/*".
blockCommentStartDelimiter - the start delimiter for block comments (never null or empty).setBlockCommentEndDelimiter(java.lang.String)public void setBlockCommentEndDelimiter(String blockCommentEndDelimiter)
Defaults to "*/".
blockCommentEndDelimiter - the end delimiter for block comments (never null or empty).setBlockCommentStartDelimiter(java.lang.String)public void setContinueOnError(boolean continueOnError)
Defaults to false.
continueOnError - true if script execution should continue on errorpublic void setIgnoreFailedDrops(boolean ignoreFailedDrops)
DROP statement can be ignored.
This is useful for a non-embedded database whose CQL 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 populate(com.datastax.oss.driver.api.core.CqlSession session)
throws ScriptException
KeyspacePopulator
Concrete implementations may throw a RuntimeException if an error is encountered but are
strongly encouraged to throw a specific ScriptException instead. For example, Spring's
ResourceKeyspacePopulator wrap all exceptions in ScriptExceptions.
populate in interface KeyspacePopulatorsession - the CQL CqlSession to use to populate the keyspace; already configured and ready to use;
never nullScriptException - in all other error casespublic void execute(SessionFactory sessionFactory) throws ScriptException
ResourceKeyspacePopulator against the given SessionFactory.sessionFactory - the SessionFactory to execute against (never null)ScriptException - if an error occurs#populate(Session)Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.