Interface CqlDataSet

  • All Superinterfaces:
    CqlScript
    All Known Implementing Classes:
    DefaultCqlDataSet
    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 CqlDataSet
    extends CqlScript
    A CqlDataSet represents a collection of CqlScript instances, providing functionality to group and manage multiple CQL scripts that can be executed sequentially.

    This interface provides several factory methods for creating CqlDataSet instances, as well as a CqlDataSet.Builder class for more customizable configurations.

    Example Usage:

    
     // Creating a CqlDataSet from classpath resources
     CqlDataSet dataSet = CqlDataSet.ofClassPaths("schema.cql", "data.cql");
    
     // Using a builder to combine multiple resources and scripts
     CqlDataSet dataSet = CqlDataSet.builder()
             .addResource(new ClassPathResource("schema.cql"))
             .addScript("CREATE KEYSPACE test WITH replication = {...};")
             .build();
    
     // Iterating over CQL statements
     dataSet.getStatements().forEach(System.out::println);
     
    Since:
    4.0.1
    Author:
    Dmytro Nosan
    See Also:
    CqlScript, DefaultCqlDataSet
    • Method Detail

      • ofClassPaths

        static CqlDataSet ofClassPaths​(String... names)
        Creates a CqlDataSet from the specified classpath resource names, using the default charset.
        Parameters:
        names - the resource names (must not be null)
        Returns:
        a new CqlDataSet instance
        Throws:
        NullPointerException - if names is null
      • ofClassPaths

        static CqlDataSet ofClassPaths​(Charset charset,
                                       String... names)
        Creates a CqlDataSet from the specified classpath resource names, using the provided Charset.
        Parameters:
        names - the resource names (must not be null)
        charset - the character encoding to use when reading the resources (must not be null)
        Returns:
        a new CqlDataSet instance
        Throws:
        NullPointerException - if names or charset is null
      • ofResources

        static CqlDataSet ofResources​(Charset charset,
                                      Resource... resources)
        Creates a CqlDataSet from the specified Resource instances, using the provided Charset.
        Parameters:
        resources - the resources to use (must not be null)
        charset - the character encoding to use when reading the resources (must not be null)
        Returns:
        a new CqlDataSet instance
        Throws:
        NullPointerException - if resources or charset is null
      • ofScripts

        static CqlDataSet ofScripts​(CqlScript... scripts)
        Creates a CqlDataSet from the specified CqlScript instances.

        If one or more CqlScript instances are themselves instances of CqlDataSet, their individual scripts are flattened into the resulting dataset.

        Parameters:
        scripts - the scripts to include (must not be null)
        Returns:
        a new CqlDataSet instance
        Throws:
        NullPointerException - if scripts is null
      • forEachScript

        default void forEachScript​(Consumer<? super CqlScript> callback)
        Executes the provided callback for each CqlScript in the CqlDataSet.
        Parameters:
        callback - the action to perform on each script (must not be null)
        Throws:
        NullPointerException - if callback is null
      • getStatements

        default List<String> getStatements()
        Retrieves all the CQL statements from every script in the CqlDataSet.
        Specified by:
        getStatements in interface CqlScript
        Returns:
        an unmodifiable list of all CQL statements (never null)