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
    A CqlScript represents a collection of executable Cassandra Query Language (CQL) statements.

    This functional interface provides methods for constructing CqlScript instances 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 Detail

      • ofClassPath

        static CqlScript ofClassPath​(String name,
                                     Charset charset)
        Creates a CqlScript instance using a classpath resource and the specified Charset.
        Parameters:
        name - the name of the resource (must not be null)
        charset - the character encoding to use when reading the resource (must not be null)
        Returns:
        a new CqlScript instance
        Throws:
        NullPointerException - if name or charset is null
      • ofStatements

        static CqlScript ofStatements​(String... statements)
        Creates a CqlScript instance from an array of CQL statements.
        Parameters:
        statements - an array of CQL statements (must not be null)
        Returns:
        a new CqlScript instance
        Throws:
        NullPointerException - if statements is null
        Since:
        5.0.0
      • ofStatements

        static CqlScript ofStatements​(List<? extends String> statements)
        Creates a CqlScript instance from a List of CQL statements.
        Parameters:
        statements - a list of CQL statements (must not be null)
        Returns:
        a new CqlScript instance
        Throws:
        NullPointerException - if statements is null
        Since:
        5.0.0
      • forEachStatement

        default void forEachStatement​(Consumer<? super String> callback)
        Iterates over all the statements in this CqlScript, applying the provided Consumer.

        This method allows developers to perform an action (e.g., execution, logging) for each individual CQL statement.

        Parameters:
        callback - a Consumer that processes each statement (must not be null)
        Throws:
        NullPointerException - if callback is null
      • getStatements

        List<String> getStatements()
        Retrieves the list of CQL statements encapsulated within this CqlScript.

        The returned List contains all the parsed or explicitly provided statements. This method guarantees that the result is never null, but the list may be empty if no statements are provided or parsed.

        Returns:
        an unmodifiable list of CQL statements (never null)