Use the DatabaseRetrieve node to ensure that information in a message is up to date.
This topic contains the following sections:
Use the DatabaseRetrieve node to modify a message using information from a database. For example, you can add information to a message using a key that is contained in a message; the key can be an account number.
The DatabaseRetrieve node is contained in the Database drawer of the message flow node palette, and is represented in the IBM® Integration Toolkit by the following icon:
You can view information about samples only when you use the product documentation that is integrated with the IBM Integration Toolkit or the online product documentation. You can run samples only when you use the product documentation that is integrated with the IBM Integration Toolkit.
Java | JDBC |
---|---|
Integer | INTEGER |
Long | BIGINT |
Double | DOUBLE |
BigDecimal | NUMERIC |
Boolean | BIT |
byte[] | VARBINARY or LONGVARBINARY |
BitSet | VARBINARY or LONGVARBINARY |
String | VARCHAR or LONGVARCHAR |
MbTime | java.sql.Time |
MbTimestamp | java.sql.Timestamp |
MbDate | java.sql.Date |
JDBC | Java | ESQL Type |
---|---|---|
SMALLINT | Integer | INTEGER |
INTEGER | Integer | INTEGER |
BIGINT | Long | DECIMAL |
DOUBLE | Double | FLOAT |
REAL | Double | FLOAT |
FLOAT | Double | FLOAT |
NUMERIC | BigDecimal | DECIMAL |
DECIMAL | BigDecimal | DECIMAL |
BIT | Boolean | BOOLEAN |
BOOLEAN | Boolean | BOOLEAN |
BINARY | byte[] | BLOB |
VARBINARY | byte[] | BLOB |
LONGVARBINARY | byte[] | BLOB |
CHAR | String | CHARACTER |
VARCHAR | String | CHARACTER |
LONGVARCHAR | String | CHARACTER |
TINYINT | byte[1] | BLOB |
TIME | java.util.Date | TIME |
TIMESTAMP | java.util.Date | TIMESTAMP |
DATE | java.util.Date | DATE |
If an error is found in the XPath expression of a pattern, it is reported during validation in the IBM Integration Toolkit. The reported error message might include the incorrect expression string and its associated unique dynamic or static terminal name, or the string might be marked as broker in the table.
The DatabaseRetrieve node looks up values from a database and stores them as elements in the outgoing message assembly trees. The type of information that is obtained from the database in the form of output column values, which is acquired and passed back in the result set from SQL queries, is converted first into a matching Java type, then into an internal message element value type when it is finally stored in a location in am outgoing message assembly tree. If a message element already exists in the outgoing message tree, the new value overwrites the old value. If the target element does not exist, it is created, and the value is stored.
The node needs query information that is used to form an SQL select query, which can access multiple tables in a database using multiple test conditions. Sometimes, not all the information that you want to retrieve in a result set is in a single database table. To get the column values that you want, you might need to retrieve them from two or more tables. This node supports the use of SELECT statements that facilitate getting columns from one or more tables in a single result set. The normal join syntax that is supported is also referred to as inner join.
Inner join information that is collected to form a query includes a list of table qualified column values to retrieve and a list of test conditions, which form the WHERE clause of the SELECT statement. Table qualified column values can form the left hand operand in a test condition. Choose a comparison operator to apply to this operand and, optionally, specify an operand on the right to complete the test condition. The operator could be a null comparison test, in which case an operand on the right is not needed. The value of the operand on the right can be a database type (such as Integer, Boolean, or Long), another table qualified column, or a value that is acquired from an element in the incoming message, as expressed through an XPath 1.0 general expression.
The application of the expression must result in a single element, double, Boolean, or string being returned, otherwise an exception occurs. If the query returns multiple rows, the first row is chosen and the rest are ignored, unless the Multiple rows option is selected. In this case, all rows are processed, and values in those rows are used to update the outgoing message assembly trees.
It can be useful to combine a DatabaseRetrieve node with other message flow nodes. For example, you can use an XSLTransform node to manipulate data before or after the DatabaseRetrieve node is invoked.
The DatabaseRetrieve node has one input terminal (In) and three output terminals (Out, KeyNotFound, and Failure). If the message is modified successfully, it is routed to the Out terminal. If the message is not modified successfully or a failure is detected during processing, the message is routed to the Failure terminal. If no rows are returned in the result set following execution of a specified SQL select query, the original message is routed to the KeyNotFound terminal.
The DatabaseRetrieve node constructs its JDBC connections using connection details that are stored in the broker's registry as a configurable service. JDBCProvider configurable services are supplied for all supported databases.
Use the IBM Integration Explorer to modify or create the supplied service; see Using the IBM Integration Explorer to work with configurable services for more information.
You can also use the mqsichangeproperties command to modify the settings of the supplied service for your chosen database, or create a new service using the mqsicreateconfigurableservice command. See Setting up a JDBC provider for type 4 connections for further information and assistance on working with JDBCProvider services. You must set up a different JDBCProvider service for each database to which you want to connect.
Note: The maxConnectionPoolSize property does not apply to the JDBC connections used by the DatabaseRetrieve or DatabaseRoute nodes.
When you have defined the service, set the Data source name property of this node to the name of the JDBCProvider service; the attributes of the service are used to establish connections for the DatabaseRetrieve node.
You must stop and restart the broker for your changes to take effect, unless you intend to create a new integration server on the broker to which you will deploy the message flow that contains this node.
When you have put an instance of the DatabaseRetrieve node into a message flow, you can configure it. For more information, see Configuring a message flow node. The properties of the node are displayed in the Properties view.
All mandatory properties for which you must enter a value (those that do not have a default value defined) are marked with an asterisk.
EmployeeNumber | FamilyName | FirstName | Salary |
---|---|---|---|
00001 | Smith | John | 20000 |
00002 | Jones | Harry | 26000 |
00003 | Doe | Jane | 31000 |
<EmployeeRecord>
<EmployeeNumber>00001</EmployeeNumber>
</EmployeeRecord>
Table name | Column name | Operator | Value Type | Value |
---|---|---|---|---|
Employee | FamilyName | |||
Employee | Salary | |||
Employee | EmployeeNumber | = | Element | $InputRoot/XMLNSC/EmployeeRecord/EmployeeNumber |
Column name | Message element |
---|---|
Employee.FamilyName | $OutputRoot/XMLNSC/EmployeeRecord/FamilyName |
Employee.Salary | $OutputRoot/XMLNSC/EmployeeRecord/Wage |
SELECT Employee.FamilyName, Employee.Salary
FROM Employee
WHERE EmployeeNumber=?
ORDER BY Employee.FamilyName ASC, Employee.Salary ASC
where ? is
the value that is retrieved from the incoming message, which is located
through the Value property
in the third row of the Query elements table, which has a Value Type of Element.<EmployeeRecord>
<EmployeeNumber>00001</EmployeeNumber>
<FamilyName>Smith</FamilyName>
<Wage>20000</Wage>
</EmployeeRecord>
<EmployeeRecord>
<EmployeeNumber>00002</EmployeeNumber>
<FamilyName>Jones</FamilyName>
<Wage>26000</Wage>
</EmployeeRecord>
<EmployeeRecord>
<EmployeeNumber>00001</EmployeeNumber>
<FamilyName>Smith</FamilyName>
<Wage>20000</Wage>
<EmployeeNumber>00002</EmployeeNumber>
<FamilyName>Jones</FamilyName>
<Wage>26000</Wage>
</EmployeeRecord>
Set the Validation properties to define how the message that is produced by the DatabaseRetrieve node is to be validated. These properties do not cause the input message to be validated. It is expected that, if such validation is required, the validation has already been performed by the input node or a preceding validation node.
For more details, see Validating messages and Validation properties.
The DatabaseRetrieve node terminals are described in the following table.
Terminal | Description |
---|---|
In | The input terminal that accepts a message for processing by the node. |
Out | The output terminal to which the outgoing message is routed when it has been modified successfully. |
KeyNotFound | The output terminal to which the original message is routed, unchanged, when the result set is empty. |
Failure | The output terminal to which the message is routed if a failure is detected during processing. |
The following tables describe the node properties. The column headed M indicates whether the property is mandatory (marked with an asterisk if you must enter a value when no default is defined); the column headed C indicates whether the property is configurable (you can change the value when you add the message flow to the BAR file to deploy it).
Property | M | C | Default | Description |
---|---|---|---|---|
Node name | No | No | DatabaseRetrieve | The name of the node. |
Short description | No | No | A brief description of the node. | |
Long description | No | No | Text that describes the purpose of the node in the message flow. |
Property | M | C | Default | Description | mqsiapplybaroverride command property |
---|---|---|---|---|---|
Data source name | Yes | Yes | DB2 | The alias that is used to locate JDBCProvider
service definition that is stored in the broker registry. The alias
is used to locate and build the JDBC connection URL that is used to
connect to a DBMS. The connection URL is driver specific, but it includes
the database name to which to connect. If connection to the database is by a login account and password, the node also uses this property as a lookup key, through which these values can be acquired from an expected matching broker registry DSN entry. If the DBMS is password protected, define the -n parameter on the mqsisetdbparms command for the JDBC unique security key before you deploy the message flow that contains this DatabaseRetrieve node. |
dataSource |
Copy message | No | Yes | Cleared | This property indicates if a copy of the original incoming message is required because the message tree is to be updated, possibly in addition to logical trees in the message assembly. By default, this check box is cleared. For performance reasons, select this property only if the input message will be augmented. | |
Multiple rows | No | Yes | Cleared | This property indicates if all rows are processed when a query returns multiple rows. If you select Multiple rows, all rows are processed, and values in those rows are used to update the outgoing message assembly trees. If you do not select this property, the first row is chosen and the rest are ignored. | |
Query elements | Yes | No | A table of query elements that are used to compose a single SQL select statement. The table consists of five columns and one or more rows. The columns are Table name, Column name, Operator, Value Type, and Value. These five properties describe a query element, indicating a table qualified column value to be retrieved from a database. In this case, the element forms part of the SELECT and ORDER BY clauses in the generated query. Otherwise, the query element acts as a test condition that forms a predicate in the WHERE clause in the generated query. | ||
Table name | Yes | No | The name of a database table that forms part of the SQL select statement, including the schema name; for example, myschema.mytable. | ||
Column name | Yes | No | The name of the column in the database table to be retrieved in the results set, as qualified by the value of the Table name property. This SELECT clause can refer to this name as a column value to return from a query or to be referenced in a test condition in the WHERE clause. | ||
Operator | Yes | No | A comparison operator to apply to an operand on the left (the table column that is specified in the row's first two columns) and optionally a value to apply to an operand on the right. If you specify an Ascending 'ASC' or Descending 'DESC' operator value for this property, this row signifies the declaration of a table qualified column that forms part of the SELECT and ORDER BY clauses in the generated query and optionally can be referenced in future rows as a value to an operand on the right. If you specify the operator LIKE or NOT LIKE, the operand on the right must be a string literal with a value type of String. | ||
Value Type | Yes | No | A value that is either set to None, or that indicates the type of value that is expressed in the last column of this row. If this property is not set to None, it refers to a row that describes a test condition in the WHERE clause of the SQL select statement. Use a value type of Element if the operand on the right is to be evaluated from the node's incoming message at runtime using an XPATH expression. | ||
Value | Yes | No | A value that is either set to None, or that specifies one of a specified set of property types as expressed by the Value Type property. For example, if the Value Type property is set to Element, the Value property collects an XPath 1.0 general expression. The value that is returned from the expression when it is applied to the node's incoming message is used as value of the operand on the right to be compared through this predicate. The compared value of the operand on the right must match the type that is retrieved for the table column that is compared against as the operand on the left. Complex expressions are possible, where zero or more values can be acquired from the incoming message, and manipulated to formed a single value for comparison. For example, the sum of multiple field values in the incoming message can be calculated by a general expression that is presented for a value type of Element. |
Property | M | C | Default | Description |
---|---|---|---|---|
Data elements | Yes | No | A list of data elements. A data element is described by the Column name and Message element properties. | |
Column name | Yes | No | The name of the database column from which to obtain the element value. The list of names is updated dynamically based on the column entries that are entered in the Query elements table. | |
Message element | Yes | No | An XPath 1.0 read-write path expression that describes the path location of a message element. The message element is where the database value is stored. The XPath expression must evaluate to a single element in the message. |
The DatabaseRetrieve node Validation properties are described in the following table.
For a full description of these properties, see Validation properties.Property | M | C | Default | Description |
---|---|---|---|---|
Validate | No | Yes | None | This property controls whether validation takes place. Valid values are None, Content and Value, Content, and Inherit. |
Failure action | No | No | Exception | This property controls what happens if a validation failure occurs. You can set this property only if Validate is set to Content or Content and Value. Valid values are User Trace, Local Error Log, Exception, and Exception List. |
Property | M | C | Default | Description |
---|---|---|---|---|
Events | No | No | None | Events that you have defined for the node are
displayed on this tab. By default, no monitoring events are defined
on any node in a message flow. Use Add, Edit,
and Delete to create, change or delete monitoring
events for the node; see Configuring monitoring event sources using monitoring properties for details. You can enable and disable events that are shown here by selecting or clearing the Enabled check box. |