Class SqlStatement

java.lang.Object
com.hazelcast.sql.SqlStatement

public final class SqlStatement extends Object
Definition of an SQL statement.

This object is mutable. Properties are read once before the execution is started. Changes to properties do not affect the behavior of already running statements.

  • Field Details

    • TIMEOUT_NOT_SET

      public static final long TIMEOUT_NOT_SET
      Value for the timeout that is not set. The value of SqlConfig.setStatementTimeoutMillis(long) will be used.
      See Also:
    • TIMEOUT_DISABLED

      public static final long TIMEOUT_DISABLED
      Value for the timeout that is disabled, meaning there's no time limit to run a query.
      See Also:
    • DEFAULT_TIMEOUT

      public static final long DEFAULT_TIMEOUT
      Default timeout.
      See Also:
    • DEFAULT_CURSOR_BUFFER_SIZE

      public static final int DEFAULT_CURSOR_BUFFER_SIZE
      Default cursor buffer size.
      See Also:
  • Constructor Details

    • SqlStatement

      public SqlStatement(@Nonnull String sql)
  • Method Details

    • getSql

      @Nonnull public String getSql()
      Gets the SQL string to be executed.
      Returns:
      SQL string
    • setSql

      @Nonnull public SqlStatement setSql(@Nonnull String sql)
      Sets the SQL string to be executed.

      The SQL string cannot be null or empty.

      Parameters:
      sql - SQL string
      Returns:
      this instance for chaining
      Throws:
      NullPointerException - if passed SQL string is null
      IllegalArgumentException - if passed SQL string is empty
    • getSchema

      @Nullable public String getSchema()
      Gets the schema name.
      Returns:
      the schema name or null if there is none
      Since:
      4.2
    • setSchema

      @Nonnull public SqlStatement setSchema(@Nullable String schema)
      Sets the schema name. The engine will try to resolve the non-qualified object identifiers from the statement in the given schema. If not found, the default search path will be used, which looks for objects in the predefined schemas "partitioned" and "public".

      The schema name is case-sensitive. For example, "foo" and "Foo" are different schemas.

      The default value is null meaning only the default search path is used.

      Parameters:
      schema - the current schema name
      Returns:
      this instance for chaining
      Since:
      4.2
    • getParameters

      @Nonnull public List<Object> getParameters()
      Gets the statement parameter values.
    • setParameters

      @Nonnull public SqlStatement setParameters(List<Object> parameters)
      Sets the values for statement parameters.

      You may define parameter placeholders in the statement with the "?" character. For every placeholder, a value must be provided.

      When the method is called, the contents of the list are copied. Subsequent changes to the original list don't change the statement parameters.

      Parameters:
      parameters - statement parameters
      Returns:
      this instance for chaining
      See Also:
    • addParameter

      @Nonnull public SqlStatement addParameter(Object value)
      Adds a single parameter value to the end of the parameter values list.
      Parameters:
      value - parameter value
      Returns:
      this instance for chaining
      See Also:
    • clearParameters

      @Nonnull public SqlStatement clearParameters()
      Clears statement parameter values.
      Returns:
      this instance for chaining
      See Also:
    • getTimeoutMillis

      public long getTimeoutMillis()
      Gets the execution timeout in milliseconds.
      Returns:
      execution timeout in milliseconds
    • setTimeoutMillis

      @Nonnull public SqlStatement setTimeoutMillis(long timeout)
      Sets the execution timeout in milliseconds.

      If the timeout is reached for a running statement, it will be cancelled forcefully.

      Zero value means no timeout. -1L means that the value from SqlConfig.getStatementTimeoutMillis() will be used. Other negative values are prohibited.

      Defaults to -1L.

      Parameters:
      timeout - execution timeout in milliseconds, 0 for no timeout, -1 to user member's default timeout
      Returns:
      this instance for chaining
      See Also:
    • getCursorBufferSize

      public int getCursorBufferSize()
      Gets the cursor buffer size (measured in the number of rows).
      Returns:
      cursor buffer size (measured in the number of rows)
    • setCursorBufferSize

      @Nonnull public SqlStatement setCursorBufferSize(int cursorBufferSize)
      Sets the cursor buffer size (measured in the number of rows).

      When a statement is submitted for execution, a SqlResult is returned as a result. When rows are ready to be consumed, they are put into an internal buffer of the cursor. This parameter defines the maximum number of rows in that buffer. When the threshold is reached, the backpressure mechanism will slow down the execution, possibly to a complete halt, to prevent out-of-memory.

      Only positive values are allowed.

      The default value is expected to work well for most workloads. A bigger buffer size may give you a slight performance boost for queries with large result sets at the cost of increased memory consumption.

      Defaults to 4096.

      Parameters:
      cursorBufferSize - cursor buffer size (measured in the number of rows)
      Returns:
      this instance for chaining
      See Also:
    • getExpectedResultType

      @Nonnull public SqlExpectedResultType getExpectedResultType()
      Gets the expected result type.
      Returns:
      expected result type
      Since:
      4.2
    • setExpectedResultType

      @Nonnull public SqlStatement setExpectedResultType(@Nonnull SqlExpectedResultType expectedResultType)
      Sets the expected result type.
      Parameters:
      expectedResultType - expected result type
      Returns:
      this instance for chaining
      Since:
      4.2
    • getPartitionArgumentIndex

      @PrivateApi public int getPartitionArgumentIndex()
      Get the partition argument index value
      Returns:
      partitionArgumentIndex, -1 if not set.
    • setPartitionArgumentIndex

      @PrivateApi public void setPartitionArgumentIndex(int partitionArgumentIndex)
      Set the partition argument index. If there's no such argument, use -1.

      Setting a wrong argument index will not cause incorrect query results, but might cause performance degradation due to more network communication. Setting a value higher than the actual number of arguments will have no effect.

      Parameters:
      partitionArgumentIndex - index of the partition-determining argument of the statement
    • copy

      @Nonnull public SqlStatement copy()
      Creates a copy of this instance
      Returns:
      Copy of this instance
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object