public class DslJdbcSampler extends BaseSampler<DslJdbcSampler>
This sampler currently does not require to specify the type of query to send to the database (as JMeter element does), and calculates the proper type from query string and defined parameters.
DslJdbcConnectionPool| Modifier and Type | Class and Description |
|---|---|
static class |
DslJdbcSampler.JdbcParamMode
Specifies the mode to apply to a given query parameter.
|
static class |
DslJdbcSampler.QueryType
Specifies the type of query to use the JDBC driver with.
|
BaseSampler.SamplerChildchildrenguiClass, name| Constructor and Description |
|---|
DslJdbcSampler(String name,
String poolName,
String query) |
| Modifier and Type | Method and Description |
|---|---|
DslJdbcSampler |
autoCommit(boolean enabled)
Allows enabling or disabling auto-commits on the connection pool.
|
protected org.apache.jmeter.testelement.TestElement |
buildTestElement() |
DslJdbcSampler |
commit()
Allows committing changes applied by previous queries when auto-commit is disabled on the
connection pool.
|
DslJdbcSampler |
param(Object value,
int jdbcParamType)
Allows specifying a parameter value to pass to the query and used in provided query
placeholders ("?" symbol).
|
DslJdbcSampler |
param(Object value,
int jdbcParamType,
DslJdbcSampler.JdbcParamMode mode)
Same as
param(Object, int) but allowing also to specify parameter mode. |
DslJdbcSampler |
queryType(DslJdbcSampler.QueryType queryType)
Allows to explicitly specify the query type when auto-detection is not enough.
|
DslJdbcSampler |
resultsVar(String resultsVar)
Allows specifying the name of a variable where to store a list of query retrieved row maps.
|
DslJdbcSampler |
rollback()
Allows undoing changes done by previous queries when auto-commit is disabled on the connection
pool.
|
DslJdbcSampler |
timeout(Duration timeout)
Allows specifying a maximum amount of time a query can take before it fails.
|
DslJdbcSampler |
vars(String... vars)
Allows specifying the name prefixes of variables where to store query retrieved row columns.
|
childrenaddChildren, buildTreeUnderbuildConfiguredTestElement, buildTestElementGui, configureTestElement, durationToSeconds, getGuiClass, getName, loadBeanProperties, showAndWaitFrameWith, showFrameWith, showInGui, showTestElementGuiclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuildTreeUnder, showInGuipublic DslJdbcSampler param(Object value, int jdbcParamType)
In general, prefer using this instead of using JMeter variable references or expressions inside query, since is more performance and safer.
In the end, this just specifies parameters to pass to a prepared statement generated from the given query string.
There is no need to replace nulls with special values or have any special consideration for strings containing commas and quotes since the DSL abstracts such details.
value - specifies the actual value to set on the parameter.jdbcParamType - sets the type of the parameter, being the value one of Types defined ones, or a specific one for the database that is
not included in Types class.Typespublic DslJdbcSampler param(Object value, int jdbcParamType, DslJdbcSampler.JdbcParamMode mode)
param(Object, int) but allowing also to specify parameter mode.
When mode is not specified, then DslJdbcSampler.JdbcParamMode.IN is used.
Remember specifying a parameter for each of query placeholders ('?'), even if is an OUT parameter.
value - specifies the actual value to set on the parameter.jdbcParamType - sets the type of the parameter, being the value one of Types defined ones, or a specific one for the database that is
not included in Types class.mode - specifies the DslJdbcSampler.JdbcParamMode for the parameter.param(Object, int),
DslJdbcSampler.JdbcParamModepublic DslJdbcSampler vars(String... vars)
JMeter adds a suffix to each variable with the row number, starting with 1 (eg: if the name of the variable is MY_FIELD, then the first row column value will be MY_FIELD_1). Additionally, JMeter creates a variable with "_#" suffix which includes the number of returned values/rows (eg: MY_FIELD_#).
Alternatively you may use resultsVar for getting a list of row maps.
vars - specifies variables names prefixes to use for each returned query column or
function/procedure output parameter.public DslJdbcSampler resultsVar(String resultsVar)
Each element in the list will contain a map where the key is the column name or alias, or parameter output name, and the value is the associated value.
resultsVar - specifies the name of the variable where to store the list of row maps.public DslJdbcSampler timeout(Duration timeout)
You should set the timeout with a big enough value that covers all expected scenarios, but also low enough to quickly detect any potential abnormal behavior.
timeout - specifies the timeout duration.
By default, no timeout will be set, which might use the default timeout for the driver, connection, database. This also avoid issues with drivers that don't support a query timeout. When set to 0, then an infinity timeout will be considered (not recommended).
Since JDBC only supports specifying times in seconds, if you specify a smaller granularity (like milliseconds) it will be rounded up to seconds.
public DslJdbcSampler commit()
When this method is used, query string is ignored (so you can set it to null).
public DslJdbcSampler rollback()
When this method is used, query string is ignored (so you can set it to null).
public DslJdbcSampler autoCommit(boolean enabled)
When this method is used, query string is ignored (so you can set it to null).
enabled - specifies to enable auto-commits when set to true, or disable them otherwise.public DslJdbcSampler queryType(DslJdbcSampler.QueryType queryType)
In general this method should not be needed to invoke, but in some cases auto-detection may fail, and this method allows you to explicitly specify it.
queryType - the type of query to assign to use with the JDBC Driver.DslJdbcSampler.QueryTypeprotected org.apache.jmeter.testelement.TestElement buildTestElement()
buildTestElement in class BaseTestElementCopyright © 2022. All rights reserved.