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, meaning there's no time limit to
run a query.
|
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 value)
Adds a single parameter value to the end of the parameter values list.
|
SqlStatement |
clearParameters()
Clears statement parameter values.
|
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).
|
SqlExpectedResultType |
getExpectedResultType()
Gets the expected result type.
|
List<Object> |
getParameters()
Gets the statement parameter values.
|
String |
getSchema()
Gets the schema name.
|
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 |
setExpectedResultType(SqlExpectedResultType expectedResultType)
Sets the expected result type.
|
SqlStatement |
setParameters(List<Object> parameters)
Sets the values for statement parameters.
|
SqlStatement |
setSchema(String schema)
Sets the schema name.
|
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
SqlConfig.setStatementTimeoutMillis(long)
will be used.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@Nullable public String getSchema()
null
if there is none@Nonnull public SqlStatement setSchema(@Nullable String schema)
"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.
schema
- the current schema name@Nonnull public SqlStatement setParameters(List<Object> 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
- statement parametersaddParameter(Object)
,
clearParameters()
@Nonnull public SqlStatement addParameter(Object value)
value
- parameter valuesetParameters(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 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 SqlExpectedResultType getExpectedResultType()
@Nonnull public SqlStatement setExpectedResultType(@Nonnull SqlExpectedResultType expectedResultType)
expectedResultType
- expected result type@Nonnull public SqlStatement copy()
Copyright © 2024 Hazelcast, Inc.. All rights reserved.