The Database Bulk functions enable you to bundle multiple queries into one SQL statement. This significantly improves the throughput due to reduced need of context switching and network traversals. The functions are intended for batch usage only.
All functions without the parameter disableCommit
will be auto commit after the function has executed.
Making an SQL Query
When making an SQL query it must follow a certain format and the order of the columns in the query must remain the same in the statement as in the where_clause
.
...
Code Block |
---|
any sqlBulkPrepareStatement
(string dbProfile ,
string statement ,
string static_where_clause , //set to null if not present
string where_clause ,
int bulkSize ,
int significantColumns ,
int totalColumns ,
int timeout , //Optional
@Deprecated boolean disableCommit , //Optional) |
Parameter | Description | ||
---|---|---|---|
| Name of the database where the table resides | ||
| Statement to send to the database | ||
| The static_where_clause of the SQL statement stays the same throughout the batch mode execution | ||
| The where_clause of the SQL statement principal. The where_clause columns that are to be considered significant must correspond with the columns in the select statement. For example, when statement reads "select A, B and C from X", where A and B is significant, the where_clause must begin with "A=? and B=?". | ||
| The size of the bundled lookup SQL query, that is the number of UDRs with a unique UDR key to be bundled. The ideal | ||
| This parameter indicates which columns in the select statement are significant to tie a result row to its context (UDR). All columns to be used as significant columns must be included in SQL search condition, and they must be used in the same order as in the search condition. For example, when using an incoming UDR as context and a search condition matching its IMSI field, using significant columns = 1 ties all matching rows to this UDR, namely, all rows with the same IMSI as that carried by the UDR. | ||
| The total number of columns in the statement | ||
| The least time interval, in milliseconds, the workflow will allow before a database bulk lookup will be done | ||
disableCommit (Deprecated from MZ 9.2.2.0) | An optional parameter to disable the commit statement from being performed at the end of every SQL transaction for this particular function. Setting this parameter to false will result in the commit statement to be performed at the end of every SQL transaction for this particular function. By default, the system has the disableCommit set to true unless otherwise changed via this parameter.
| ||
Returns: | The returned object is a “Prepared Statement” object containing the added parameters, a prepared result list and a maintained contexts list. This object is a mandatory parameter to the |
Info | ||||||
---|---|---|---|---|---|---|
Example - Lookup queryLookup query with one of the To prepare a query:
The call to the function and the values for the above example:
The call to the APL function:
|
sqlBulkExecuteQuery
When a UDR enters sqlBulkExecuteQuery
the first met criteria of bulkSize
or timeout
triggers the database bulk lookup.
...
Code Block |
---|
list <any> sqlBulkExecuteQuery(any ps, any context , any value1, any value2, ...) |
Parameter | Description |
---|---|
| The object returned from a call to the |
| A context string, usually the UDR routed to the node |
| A number of values to populate the query |
Returns: | A list containing objects that in their turn contains a context object and a result list. This object is a mandatory parameter to the |
Info | ||||
---|---|---|---|---|
Example - Using sqlBulkExecuteQueryThe call to the function and the values for the example above, Example - Lookup Query:
Call to the APL function:
|
The function executes the SQL query before the bulkSize
is reached.
Code Block |
---|
list <any> sqlBulkDrain(any ps) |
Parameter | Description |
---|---|
| A |
Returns: | A list containing objects that in their turn contain a context object and a list with results. |
sqlBulkResultGetContext
The function finds the context object from one result object in the list returned either by the sqlBulkExecuteQuery()
or the sqlBulkDrain()
functions.
Code Block |
---|
any sqlBulkResultGetContext(any presult) |
Parameter | Description |
---|---|
| A result object from the list returned by the |
Returns: | The context object associated with the |
sqlBulkResultGetSize
The function states the size of a result object in the list returned from the sqlBulkExecuteQuery()
or the sqlBulkDrain()
functions.
Code Block |
---|
int sqlBulkResultGetSize(any presult) |
Parameter | Description |
---|---|
| A result object from the list returned by the |
Returns: | An integer representing the size of the result |
sqlBulkResultGetValue
The function gets a result value from a result object in the list returned by either the sqlBulkExecuteQuery()
or the sqlBulkDrain()
functions.
Code Block |
---|
any sqlBulkResultGetValue(any presult, int index, int column) |
Parameter | Description |
---|---|
| A result object from the list returned by the |
| The index of the result table |
| The column number |
Returns: | The value of the result object |
sqlBulkElapsedNanoTime
This function accumulates the time of the execution of the database queries that is end time of execution minus start time of execution.
Code Block |
---|
long sqlBulkElapsedNanoTime() |
Parameter | Description |
---|---|
Returns: | A long integer representing the accumulated nanoseconds. |
sqlBulkClose
The function closes down the database connection as well as the SQL statement. If the sqlBulkClose
is not called the connection will be closed when the workflow stops.
Code Block |
---|
void sqlBulkClose(any ps ) |
Parameter | Description |
---|---|
| A preparedStatement object returned by the |
Returns: | Nothing |
Example Workflow
The example shows a basic workflow where a Database Bulk lookup with a range condition is performed.
Example workflow
Prerequisites
...
Katerine,Stenberg,46123456,,10,10
Kalle,Andersson,46789123,,10
Mia,Karlsson,46999111,,10
Karina,Hansson,46222333,,10
PerErik,Larsson,46111999,,11,11
Mikael,Grenkvist,46333444,,10
Jonas,Bergsten,46555666,,10
Petra,Sjoberg,46777888,,10
Karl,Kvistgren,46444555,,10
FiaLotta,Bergman,46666222,,10
...