public final class SqlStatement extends Object
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.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CURSOR_BUFFER_SIZE
Default cursor buffer size.
|
static long |
DEFAULT_TIMEOUT
Default timeout.
|
static long |
TIMEOUT_DISABLED
Value for the timeout that is disabled.
|
static long |
TIMEOUT_NOT_SET
Value for the timeout that is not set.
|
Constructor and Description |
---|
SqlStatement(String sql) |
Modifier and Type | Method and Description |
---|---|
SqlStatement |
addParameter(Object parameter)
Adds a single parameter to the end of the parameters list.
|
SqlStatement |
clearParameters()
Clears statement parameters.
|
SqlStatement |
copy()
Creates a copy of this instance
|
boolean |
equals(Object o) |
int |
getCursorBufferSize()
Gets the cursor buffer size (measured in the number of rows).
|
List<Object> |
getParameters()
Gets the statement parameters.
|
String |
getSql()
Gets the SQL string to be executed.
|
long |
getTimeoutMillis()
Gets the execution timeout in milliseconds.
|
int |
hashCode() |
SqlStatement |
setCursorBufferSize(int cursorBufferSize)
Sets the cursor buffer size (measured in the number of rows).
|
SqlStatement |
setParameters(List<Object> parameters)
Sets the statement parameters.
|
SqlStatement |
setSql(String sql)
Sets the SQL string to be executed.
|
SqlStatement |
setTimeoutMillis(long timeout)
Sets the execution timeout in milliseconds.
|
String |
toString() |
public static final long TIMEOUT_NOT_SET
public static final long TIMEOUT_DISABLED
public static final long DEFAULT_TIMEOUT
public static final int DEFAULT_CURSOR_BUFFER_SIZE
@Nonnull public SqlStatement setSql(@Nonnull String sql)
The SQL string cannot be null or empty.
sql
- SQL stringNullPointerException
- if passed SQL string is nullIllegalArgumentException
- if passed SQL string is empty@Nonnull public List<Object> getParameters()
@Nonnull public SqlStatement setParameters(List<Object> parameters)
You may define parameter placeholders in the statement with the "?"
character. For every placeholder, a parameter
value must be provided.
When the method is called, the content of the parameters list is copied. Subsequent changes to the original list don't change the statement parameters.
parameters
- statement parametersaddParameter(Object)
,
clearParameters()
@Nonnull public SqlStatement addParameter(Object parameter)
parameter
- parametersetParameters(List)
,
clearParameters()
@Nonnull public SqlStatement clearParameters()
setParameters(List)
,
addParameter(Object)
public long getTimeoutMillis()
@Nonnull public SqlStatement setTimeoutMillis(long timeout)
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.
timeout
- execution timeout in milliseconds, 0
for no timeout, -1
to user member's default timeoutSqlConfig.getStatementTimeoutMillis()
public int getCursorBufferSize()
@Nonnull public SqlStatement setCursorBufferSize(int cursorBufferSize)
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 the 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.
cursorBufferSize
- cursor buffer size (measured in the number of rows)SqlService.execute(SqlStatement)
,
SqlResult
@Nonnull public SqlStatement copy()
Copyright © 2020 Hazelcast, Inc.. All rights reserved.