dbStatement
Processor that executes a statement against a database.
Any legal statement for the target database is supported. Dynamic values can be injected into the statement using named parameters with the syntax :<name>
. For example: SELECT * FROM members WHERE age = :age
.
Named parameters are looked up from the payload. If the parameter value can not be found on the payload, it will be looked up from the exchange properties. Thus, exchange properties can be used as defaults for values missing from the payload. For example:
-
Payload:
{"age": 43, "position": "Admin"}
-
Exchange property:
score=5
-
Configured statement:
SELECT * FROM members WHERE age = :age AND role = :position AND score = :score
-
Resolved statement:
SELECT * FROM members WHERE age = 43 AND role = 'Admin' AND score = 5
If the named parameter resolves to a list, you can use it in an IN
clause. For example:
-
Payload:
{"ages": [43, 57, 89]}
-
Configured statement:
SELECT * FROM members WHERE age IN (:ages)
-
Resolved statement:
SELECT * FROM members WHERE age IN (43, 57, 89)
Parameters can also be looked up via expression with the syntax :##<expression>##
. For example:
-
Payload:
{"age": 43, "position": "Admin"}
-
Configured statement:
INSERT INTO members (age, role) VALUES ( :## envelope.payload['age'] - 10 ##, :## envelope.payload['position'].toUpperCase() ## )
-
Resolved statement:
INSERT INTO members (age, role) VALUES (33, 'ADMIN')
It’s possible to build dynamic queries at runtime by inserting expression values verbatim into the statement text with the syntax :@@<expression>@@
. For example:
-
Payload:
{"age": 43, "position": "Admin"}
-
Exchange property:
targetDatabase=admins
-
Configured statement:
INSERT INTO :@@ exchangePropertiesMap['targetDatabase'] @@ (age, role) VALUES (:age, :position)
-
Resolved statement:
INSERT INTO admins (age, role) VALUES (43, 'Admin')
The processor supports batched processing. If the payload is a list of objects, and the batching
processor property is true
, a statement will be built for each of the objects in the list. The statements will be executed as one batched transaction. For example:
-
Payload:
[{"age": 43, "position": "Admin"}, {"age": 25, "position": "User"}]
-
Configured statement:
INSERT INTO members (age, role) VALUES (:age, :position)
-
Resolved statements:
INSERT INTO members (age, role) VALUES (43, 'Admin'); INSERT INTO members (age, role) VALUES (25, 'User');
Result Payload
The format of the returned results is determined by the statementType
property. The following options apply:
-
SelectOne
: Returns a JSON compliant map of the selected data with column names as keys. For example:{"age": 43, "position": "Admin"}
. -
SelectList
: Returns a JSON compliant list of maps of the selected data with column names as keys. For example:[{"age": 43, "position": "Admin"}, {"age": 25, "position": "User"}]
. -
Update
: Returns a JSON compliant map with a singlenoOfUpdates
entry indicating how many rows were affected by the insert or update. For example:{"noOfUpdates": 2}
.
Inbound Payload Conversion
The processor takes an optional inboundTransformationStrategy
that can be used to transform the inbound payload to a format that is suitable for pulling values into your statement. If your input payload is a JSON string, and you set the objectConversionFormat
property to MarshallingFormat.JSON
, it will be transformed to the standard JSON compliant object format that named parameters are fetched from.
Automatic Outbound Payload Conversion
The processor automatically converts the outbound payload to a JSON compliant format based on the following rules, from JDBC types to JSON compliant types:
-
NULL
: null -
BIT(1)
,BOOLEAN
: Boolean -
TINYINT
,SMALLINT
,INTEGER
: Int -
BIGINT
: Long -
REAL
: Float -
FLOAT
,DOUBLE
: Double -
BINARY
,VARBINARY
,LONGVARBINARY
,BLOB
: Base64 encoded String -
ARRAY
: List of JSON compliant member objects -
STRUCT
: List of JSON compliant attribute value objects -
REF
: REF type is not supported -
BIT(n) where n > 1
,other types
: String
Parallelism
Each instance of the processor owns a single database connection and will process messages sequentially. This default behaviour is only suitable for low-traffic scenarios. You will most likely want to add some parallelism via the processingStrategy sub-builder. For example: processingStrategy { concurrencyMaxNo = 15 }
.
Properties
Name | Summary |
---|---|
|
String containing all the information, except credentials (see |
|
A secret key that the server uses to look up the credentials needed to authenticate the client with the database. Optional, but typically required for most connections. |
|
Required statement to execute on the database. The statement is typically a SQL string with optional named parameters (e.g., |
|
Required execution type of the statement. Legal values include the following:
|
|
The maximum number of seconds the statement is allowed to execute without completing. If the threshold is passed, the execution is interrupted, and a transient (retryable) error is raised. However, when executing within a transaction that is set up with an explicit timeout, that timeout will be used instead of the configured execution timeout. The transaction timeout setting is database specific. executionTimeoutSeconds is optional and defaults to |
|
The maximum number of rows to return for a query. Additional rows will be dropped quietly. Optional and defaults to |
|
Whether to do batched processing when the payload is a list of objects. Optional and defaults to |
|
Optional, descriptive name for the processor. |
|
Required identifier of the processor, unique across all processors within the flow. Must be between 3 and 30 characters long; contain only lower and uppercase alphabetical characters (a-z and A-Z), numbers, dashes ("-"), and underscores ("_"); and start with an alphabetical character. In other words, it adheres to the regex pattern |
|
Optional set of custom properties in a simple jdk-format, that are added to the message exchange properties before processing the incoming payload. Any existing properties with the same name will be replaced by properties defined here. |
|
Whether the incoming payload is available for error processing on failure. Defaults to |
Sub-builders
Name | Summary |
---|---|
Strategy for describing the external system integration. Optional. |
|
Strategy for providing message processing hints to the server. Optional. |
|
Strategy for configuring the processor’s circuit breaker. Optional. |
|
Strategy for describing how a processor’s message is logged on the server. |
|
Strategy for archiving payloads. |
|
Strategy that customizes the conversion of an incoming payload by a processor (e.g., string to object). Should be used when the processor’s default conversion logic cannot be used. |
Details
Authentication
The authenticationConfigKey
property supports secrets of type UserNameAndPassword.
See the Secret Types documentation for formatting details.