Class RegularStatement

  • Direct Known Subclasses:
    BuiltStatement, SchemaStatement, SimpleStatement

    public abstract class RegularStatement
    extends Statement
    A regular (non-prepared and non batched) CQL statement.

    This class represents a query string along with query options (and optionally binary values, see getValues). It can be extended but SimpleStatement is provided as a simple implementation to build a RegularStatement directly from its query string.

    • Constructor Detail

      • RegularStatement

        protected RegularStatement()
        Creates a new RegularStatement.
    • Method Detail

      • getQueryString

        public abstract String getQueryString​(CodecRegistry codecRegistry)
        Returns the query string for this statement.

        It is important to note that the query string is merely a CQL representation of this statement, but it does not convey all the information stored in Statement objects.

        For example, Statement objects carry numerous protocol-level settings, such as the consistency level to use, or the idempotence flag, among others. None of these settings will be included in the resulting query string.

        Similarly, if values have been set on this statement because it has bind markers, these values will not appear in the resulting query string.

        Note: the consistency level was conveyed at CQL level in older versions of the CQL grammar, but since CASSANDRA-4734 it is now a protocol-level setting and consequently does not appear in the query string.

        Parameters:
        codecRegistry - the codec registry that will be used if the actual implementation needs to serialize Java objects in the process of generating the query. Note that it might be possible to use the no-arg getQueryString() depending on the type of statement this is called on.
        Returns:
        a valid CQL query string.
        See Also:
        getQueryString()
      • getQueryString

        public String getQueryString()
        Returns the query string for this statement.

        This method calls getQueryString(CodecRegistry) with CodecRegistry.DEFAULT_INSTANCE. Whether you should use this or the other variant depends on the type of statement this is called on:

        • for a SimpleStatement or SchemaStatement, the codec registry isn't actually needed, so it's always safe to use this method;
        • for a BuiltStatement you can use this method if you use no custom codecs, or if your custom codecs are registered with the default registry. Otherwise, use the other method and provide the registry that contains your codecs (see BuiltStatement for more explanations on why this is so);
        • for a BatchStatement, use the first rule if it contains no built statements, or the second rule otherwise.
        Returns:
        a valid CQL query string.
      • hasValues

        public abstract boolean hasValues​(CodecRegistry codecRegistry)
        Whether or not this statement has values, that is if getValues will return null or not.
        Parameters:
        codecRegistry - the codec registry that will be used if the actual implementation needs to serialize Java objects in the process of determining if the query has values. Note that it might be possible to use the no-arg hasValues() depending on the type of statement this is called on.
        Returns:
        false if both getValues(ProtocolVersion, CodecRegistry) and getNamedValues(ProtocolVersion, CodecRegistry) return null, true otherwise.
        See Also:
        hasValues()
      • requestSizeInBytes

        public int requestSizeInBytes​(ProtocolVersion protocolVersion,
                                      CodecRegistry codecRegistry)
        Description copied from class: Statement
        Returns the number of bytes required to encode this statement.

        The calculated size may be overestimated by a few bytes, but is never underestimated. If the size cannot be calculated, this method returns -1.

        Note that the returned value is not cached, but instead recomputed at every method call.

        Overrides:
        requestSizeInBytes in class Statement
        Returns:
        the number of bytes required to encode this statement.
      • toString

        public String toString()
        Returns this statement as a CQL query string.

        It is important to note that the query string is merely a CQL representation of this statement, but it does not convey all the information stored in Statement objects.

        See the javadocs of getQueryString() for more information.

        Overrides:
        toString in class Object
        Returns:
        this statement as a CQL query string.
        See Also:
        getQueryString()