Most Pega applications keep their data in the Pega database. Sometimes, though, you must read or write a table in a different, external relational database, such as a legacy ledger or a reporting database. The RDB methods in an activity are the traditional way to do that.
Important rule first
Use RDB methods and Connect SQL rules only with an external database. Do not use them against the PegaRULES database. Some Pega properties are not stored as their own columns, so a plain SQL statement can lose data. For the Pega database always use Obj-Open and Obj-Save instead.
How they work
Each RDB method works together with a Connect SQL rule. The Connect SQL rule holds the SQL text on one of its tabs, and the method decides which tab to run.
| Method | Connect SQL tab | What it does |
|---|---|---|
| RDB-List | Browse | Runs a SELECT and puts the rows as embedded pages on a step page of class Code-Pega-List |
| RDB-Open | Open | Reads exactly one row and copies its columns to properties on a clipboard page |
| RDB-Save | Save | Writes the properties of a page into a row, using INSERT or UPDATE |
| RDB-Delete | Delete | Removes one or more rows |
A worked example
A bank must show a customer's recent card transactions from a legacy database table card_txn.
- Create a Connect SQL rule pointing at the legacy database, with this on its Browse tab:
SELECT txn_id, txn_date, amount FROM card_txn WHERE customer_id = ? ORDER BY txn_date DESC
- In an activity, add an RDB-List step that names the Connect SQL rule, passes the customer ID as the parameter, and sets a step page of class
Code-Pega-List. - Loop over the embedded pages of the result and copy each one into your case's page list, or show them on a screen.
For a single customer record, an RDB-Open step with a SELECT that returns exactly one row would fill a clipboard page with the customer's columns. To write back, an RDB-Save step runs the INSERT or UPDATE.
Tips
- Write the SQL so RDB-Open returns exactly one row.
- Always filter by an indexed column. A list without a WHERE clause can pull the whole table into memory.
- Handle errors: check the step status and show a friendly message if the database is unreachable.
- In newer designs, consider mapping the external table to a Pega class and reading it through a data page and a Report Definition. It is easier to reuse and maintain.
Interview tip
Give the golden rule (external databases only), then the four methods with their tabs. Related: Obj methods and the Activity label.
No comments:
Post a Comment