Interface BatchStatement

    • Method Detail

      • newInstance

        @NonNull
        static BatchStatement newInstance​(@NonNull
                                          BatchType batchType)
        Creates an instance of the default implementation for the given batch type.

        Note that the returned object is immutable.

      • newInstance

        @NonNull
        static BatchStatement newInstance​(@NonNull
                                          BatchType batchType,
                                          @NonNull
                                          Iterable<BatchableStatement<?>> statements)
        Creates an instance of the default implementation for the given batch type, containing the given statements.

        Note that the returned object is immutable.

      • newInstance

        @NonNull
        static BatchStatement newInstance​(@NonNull
                                          BatchType batchType,
                                          @NonNull
                                          BatchableStatement<?>... statements)
        Creates an instance of the default implementation for the given batch type, containing the given statements.

        Note that the returned object is immutable.

      • builder

        @NonNull
        static BatchStatementBuilder builder​(@NonNull
                                             BatchType batchType)
        Returns a builder to create an instance of the default implementation.

        Note that this builder is mutable and not thread-safe.

      • builder

        @NonNull
        static BatchStatementBuilder builder​(@NonNull
                                             BatchStatement template)
        Returns a builder to create an instance of the default implementation, copying the fields of the given statement.

        Note that this builder is mutable and not thread-safe.

      • getBatchType

        @NonNull
        BatchType getBatchType()
      • setBatchType

        @NonNull
        @CheckReturnValue
        BatchStatement setBatchType​(@NonNull
                                    BatchType newBatchType)
        Sets the batch type.

        The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.

      • setKeyspace

        @NonNull
        @CheckReturnValue
        BatchStatement setKeyspace​(@Nullable
                                   CqlIdentifier newKeyspace)
        Sets the CQL keyspace to associate with this batch.

        If the keyspace is not set explicitly with this method, it will be inferred from the first simple statement in the batch that has a keyspace set (or will be null if no such statement exists).

        This feature is only available with native protocol v5 or higher. Specifying a per-request keyspace with lower protocol versions will cause a runtime error.

        See Also:
        Request.getKeyspace()
      • add

        @NonNull
        @CheckReturnValue
        BatchStatement add​(@NonNull
                           BatchableStatement<?> statement)
        Adds a new statement to the batch.

        Note that, due to protocol limitations, simple statements with named values are currently not supported.

        The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.

      • addAll

        @NonNull
        @CheckReturnValue
        BatchStatement addAll​(@NonNull
                              Iterable<? extends BatchableStatement<?>> statements)
        Adds new statements to the batch.

        Note that, due to protocol limitations, simple statements with named values are currently not supported.

        The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.

      • size

        int size()
        Returns:
        The number of child statements in this batch.
      • clear

        @NonNull
        @CheckReturnValue
        BatchStatement clear()
        Clears the batch, removing all the statements added so far.

        The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.

      • computeSizeInBytes

        default int computeSizeInBytes​(@NonNull
                                       DriverContext context)
        Description copied from interface: Statement
        Calculates the approximate size in bytes that the statement will have when encoded.

        The size might be over-estimated by a few bytes due to global options that may be defined on a Session but not explicitly set on the statement itself.

        The result of this method is not cached, calling it will cause some encoding to be done in order to determine some of the statement's attributes sizes. Therefore, use this method sparingly in order to avoid unnecessary computation.

        Specified by:
        computeSizeInBytes in interface Statement<BatchStatement>
        Returns:
        the approximate number of bytes this statement will take when encoded.