Interface CqlScript
-
- All Known Subinterfaces:
CqlDataSet
- All Known Implementing Classes:
AbstractCqlScript,DefaultCqlDataSet,ResourceCqlScript,StatementsCqlScript,StringCqlScript
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface CqlScript
ACqlScriptrepresents a collection of executable Cassandra Query Language (CQL) statements.This functional interface provides methods for constructing
CqlScriptinstances from various sources, such as resources, classpath files, or raw strings. Implementations of this interface encapsulate CQL statements and provide convenient functionality for working with them.Example Usage:
// Load CQL from a classpath resource CqlScript script = CqlScript.ofClassPath("example.cql"); script.forEachStatement(System.out::println); // Create CQL script from explicit statements CqlScript script = CqlScript.ofStatements("CREATE TABLE test (...)", "INSERT INTO test VALUES (...)"); script.getStatements().forEach(System.out::println);- Since:
- 4.0.0
- Author:
- Dmytro Nosan
- See Also:
CqlDataSet,AbstractCqlScript,ResourceCqlScript,StringCqlScript
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidforEachStatement(Consumer<? super String> callback)List<String>getStatements()Retrieves the list of CQL statements encapsulated within thisCqlScript.static CqlScriptofClassPath(String name)static CqlScriptofClassPath(String name, Charset charset)static CqlScriptofResource(Resource resource)static CqlScriptofResource(Resource resource, Charset charset)static CqlScriptofStatements(String... statements)Creates aCqlScriptinstance from an array of CQL statements.static CqlScriptofStatements(List<? extends String> statements)
-
-
-
Method Detail
-
ofClassPath
static CqlScript ofClassPath(String name)
- Parameters:
name- the name of the resource (must not benull)- Returns:
- a new
CqlScriptinstance - Throws:
NullPointerException- ifnameisnull
-
ofClassPath
static CqlScript ofClassPath(String name, Charset charset)
- Parameters:
name- the name of the resource (must not benull)charset- the character encoding to use when reading the resource (must not benull)- Returns:
- a new
CqlScriptinstance - Throws:
NullPointerException- ifnameorcharsetisnull
-
ofResource
static CqlScript ofResource(Resource resource)
- Parameters:
resource- theResourceto use (must not benull)- Returns:
- a new
CqlScriptinstance - Throws:
NullPointerException- ifresourceisnull- Since:
- 4.0.1
-
ofResource
static CqlScript ofResource(Resource resource, Charset charset)
- Parameters:
resource- theResourceto use (must not benull)charset- the character encoding to use when reading the resource (must not benull)- Returns:
- a new
CqlScriptinstance - Throws:
NullPointerException- ifresourceorcharsetisnull- Since:
- 4.0.1
-
ofStatements
static CqlScript ofStatements(String... statements)
Creates aCqlScriptinstance from an array of CQL statements.- Parameters:
statements- an array of CQL statements (must not benull)- Returns:
- a new
CqlScriptinstance - Throws:
NullPointerException- ifstatementsisnull- Since:
- 5.0.0
-
ofStatements
static CqlScript ofStatements(List<? extends String> statements)
- Parameters:
statements- a list of CQL statements (must not benull)- Returns:
- a new
CqlScriptinstance - Throws:
NullPointerException- ifstatementsisnull- Since:
- 5.0.0
-
forEachStatement
default void forEachStatement(Consumer<? super String> callback)
Iterates over all the statements in thisCqlScript, applying the providedConsumer.This method allows developers to perform an action (e.g., execution, logging) for each individual CQL statement.
- Parameters:
callback- aConsumerthat processes each statement (must not benull)- Throws:
NullPointerException- ifcallbackisnull
-
getStatements
List<String> getStatements()
Retrieves the list of CQL statements encapsulated within thisCqlScript.The returned
Listcontains all the parsed or explicitly provided statements. This method guarantees that the result is nevernull, but the list may be empty if no statements are provided or parsed.- Returns:
- an unmodifiable list of CQL statements (never
null)
-
-