Interface BoundStatement

  • All Superinterfaces:
    PreparedStatement, Statement

    public interface BoundStatement
    extends PreparedStatement

    Represents a Statement that has been compiled and an execution plan generated for it. A BoundStatement must be used when the Statement is a DML statement that contains external variables. It provides methods to bind the external variables to specific values.

    To create an instance of a BoundStatement, an instance of a PreparedStatement must be created first, which is done via the KVStore.prepare(String statement) method. Next, one or more BoundStatement instances can be created from the same PreparedStatement via the method. Creating multiple BoundStatements from the same PreparedStatement allows for the potentially concurrent execution of the PreparedStatement multiple times with different bind values each time.

    Like a PreparedStatement, a BoundStatement can be executed multiple times via one of the KVStore.execute methods (for example, KVStore.execute(String statement, ExecuteOptions options) or KVStore.executeSync(Statement statement, ExecuteOptions options)). All the external variables must be bound before execution is initiated.

    Objects implementing the PreparedStatement interface are thread-safe and their methods are re-entrant. On the other hand, BoundStatement instances are not thread-safe.

    FieldValueFactory to create values for complex types.

    Since:
    4.0
    • Method Detail

      • getVariables

        java.util.Map<java.lang.String,​FieldValue> getVariables()
        Returns the map of bound variables.
        Returns:
        a map of variables that have been set.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   FieldValue value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   int value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   boolean value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   double value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   float value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   long value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   java.lang.String value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.
      • setVariable

        BoundStatement setVariable​(java.lang.String variableName,
                                   byte[] value)
        Sets the value of a variable.
        Parameters:
        variableName - the name of the query variable
        value - the value to be set
        Returns:
        the same object
        Throws:
        java.lang.IllegalArgumentException - if the variable does not appear in the query or the type of value doesn't match the type of the variable.