Class SqlStatement
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.
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description SqlStatement(String sql)
-
Method Summary
Modifier and Type Method 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 instanceboolean
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 parameters.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 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()
-
Field Details
-
TIMEOUT_NOT_SET
public static final long TIMEOUT_NOT_SETValue for the timeout that is not set.- See Also:
- Constant Field Values
-
TIMEOUT_DISABLED
public static final long TIMEOUT_DISABLEDValue for the timeout that is disabled.- See Also:
- Constant Field Values
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUTDefault timeout.- See Also:
- Constant Field Values
-
DEFAULT_CURSOR_BUFFER_SIZE
public static final int DEFAULT_CURSOR_BUFFER_SIZEDefault cursor buffer size.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
getSql
Gets the SQL string to be executed.- Returns:
- SQL string
-
setSql
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 nullIllegalArgumentException
- if passed SQL string is empty
-
getSchema
Gets the schema name.- Returns:
- the schema name or
null
if there is none - Since:
- 4.2
-
setSchema
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
Gets the statement parameters.- Returns:
- statement parameters
-
setParameters
Sets the statement 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:
parameters
- statement parameters- Returns:
- this instance for chaining
- See Also:
addParameter(Object)
,clearParameters()
-
addParameter
Adds a single parameter to the end of the parameters list.- Parameters:
parameter
- parameter- Returns:
- this instance for chaining
- See Also:
setParameters(List)
,clearParameters()
-
clearParameters
Clears statement parameters.- Returns:
- this instance for chaining
- See Also:
setParameters(List)
,addParameter(Object)
-
getTimeoutMillis
public long getTimeoutMillis()Gets the execution timeout in milliseconds.- Returns:
- execution timeout in milliseconds
-
setTimeoutMillis
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:
SqlConfig.getStatementTimeoutMillis()
-
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
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:
SqlService.execute(SqlStatement)
,SqlResult
-
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
-
copy
Creates a copy of this instance- Returns:
- Copy of this instance
-
equals
-
hashCode
public int hashCode() -
toString
-