Broadway has a category of db Actors that are useful for performing DB commands and actions like creating a new table, loading data or fetching it and executing other DB commands. These Actors are:
Each Actor in the db category requires an interface input argument that can be defined either as a reference to the Fabric DB Interface or as a JDBC URL.
The schema, table, fields and sql input arguments of db Actors are case-insensitive.
If the DB command executed by the db Actor fails, the actual SQL statement is sent to the log file. For example:
Caused by: java.sql.SQLException: [SQLITE_CONSTRAINT] Abort due to constraint violation
(UNIQUE constraint failed: CONTRACT_COPY.CONTRACT_ID)
INSERT INTO "main"."CONTRACT_COPY" ("CUSTOMER_ID","CONTRACT_ID","CONTRACT_REF_ID") VALUES (?,?,?)
Using DbLoad Actor
To load the data using the DbLoad Actor, populate the Actor's input arguments as follows:
Using DbCommand Actor
Another way to load the data in a Broadway flow is by using the DbCommand Actor and writing the SQL INSERT statement in the sql input argument. The values to be populated in the table can be taken from the input arguments using the parameters. For example:
INSERT INTO DATA (TEXT) VALUES (${text} )
Where ${text} is replaced with the value of the text input argument in the prepared statement.
The DbCommand Actor’s sql input argument includes an SQL statement which is executed by the Actor. The SQL statement can be created dynamically using prepared and non-prepared statement parameters.
The syntax is:
? - for ordered parameters.
${param_value} - for named parameters.
${@param} - for non-prepared statement parameters.
The values of named parameters are taken from the Actor's input arguments or from the params input argument and only if it is a map. For ordered parameters, the params input argument should be an array or a single value (not a map).
For example, the SQL statement:
Select * From CASES where STATUS = 'Open'
Can be written in the following way:
Select * From ${@table} where ${@column} = ${case_sts}
The values for the table, column and case_sts input arguments are passed to the Actor where they are translated into an SQL statement. When the Actor is called several times, if the resulting SQL is the same as in the previous run, the prepared statement is not recalculated.
The db-commands.flow example shows how the DbCommand Actor can be used to perform various DB actions, including:
Click Actions > Examples in the Main menu to open the db-commands.flow example.
The following example shows how to execute a SELECT statement which includes a WHERE clause using ordered params:
The parameters for the WHERE clause are transferred using the Const Actor's [values] object that is connected to the params input argument of the DbCommand Actor.
[
"Denver",
"CO"
]
The following example shows how a SELECT statement is executed using named params:
When the above query is written in the sql input parameter, a new city_name input argument is added to the DbCommand Actor and the parameter is transferred to it.
The following example shows the SQL statement which includes parameters to populate the table and column name:
The new input arguments table, clm_name and clm_value are added to the SourceDbQuery Actor and are populated by 'cases', 'status' and 'Open' values respectively.
In this example, table and clm_name are non-prepared statement parameters while clm_value is a prepared statement named parameter.
Broadway has a category of db Actors that are useful for performing DB commands and actions like creating a new table, loading data or fetching it and executing other DB commands. These Actors are:
Each Actor in the db category requires an interface input argument that can be defined either as a reference to the Fabric DB Interface or as a JDBC URL.
The schema, table, fields and sql input arguments of db Actors are case-insensitive.
If the DB command executed by the db Actor fails, the actual SQL statement is sent to the log file. For example:
Caused by: java.sql.SQLException: [SQLITE_CONSTRAINT] Abort due to constraint violation
(UNIQUE constraint failed: CONTRACT_COPY.CONTRACT_ID)
INSERT INTO "main"."CONTRACT_COPY" ("CUSTOMER_ID","CONTRACT_ID","CONTRACT_REF_ID") VALUES (?,?,?)
Using DbLoad Actor
To load the data using the DbLoad Actor, populate the Actor's input arguments as follows:
Using DbCommand Actor
Another way to load the data in a Broadway flow is by using the DbCommand Actor and writing the SQL INSERT statement in the sql input argument. The values to be populated in the table can be taken from the input arguments using the parameters. For example:
INSERT INTO DATA (TEXT) VALUES (${text} )
Where ${text} is replaced with the value of the text input argument in the prepared statement.
The DbCommand Actor’s sql input argument includes an SQL statement which is executed by the Actor. The SQL statement can be created dynamically using prepared and non-prepared statement parameters.
The syntax is:
? - for ordered parameters.
${param_value} - for named parameters.
${@param} - for non-prepared statement parameters.
The values of named parameters are taken from the Actor's input arguments or from the params input argument and only if it is a map. For ordered parameters, the params input argument should be an array or a single value (not a map).
For example, the SQL statement:
Select * From CASES where STATUS = 'Open'
Can be written in the following way:
Select * From ${@table} where ${@column} = ${case_sts}
The values for the table, column and case_sts input arguments are passed to the Actor where they are translated into an SQL statement. When the Actor is called several times, if the resulting SQL is the same as in the previous run, the prepared statement is not recalculated.
The db-commands.flow example shows how the DbCommand Actor can be used to perform various DB actions, including:
Click Actions > Examples in the Main menu to open the db-commands.flow example.
The following example shows how to execute a SELECT statement which includes a WHERE clause using ordered params:
The parameters for the WHERE clause are transferred using the Const Actor's [values] object that is connected to the params input argument of the DbCommand Actor.
[
"Denver",
"CO"
]
The following example shows how a SELECT statement is executed using named params:
When the above query is written in the sql input parameter, a new city_name input argument is added to the DbCommand Actor and the parameter is transferred to it.
The following example shows the SQL statement which includes parameters to populate the table and column name:
The new input arguments table, clm_name and clm_value are added to the SourceDbQuery Actor and are populated by 'cases', 'status' and 'Open' values respectively.
In this example, table and clm_name are non-prepared statement parameters while clm_value is a prepared statement named parameter.