In this post we will see how to use database class mapping wizard
Pega 7 introduced a separate database schema for rule and data.
- PegaRules – Contains rule tables.
- PegaData – Contains data instances like work item.
All the work and data tables resides in PegaData, whereas the rule tables reside in PegaRules.
Data can be organised in a data table as rows and columns.
We will see more of database in separate lesson.
Let’s jump into the topic.
All you need to do is to create a table and map a class to that table.
Why do we need to map class to datatable?
- We know Pega that stores the user session data in memory using clipboard pages, but we may need to persist the data for future reference.
- Pega supports mapping class to the table, so that when we save a page of defined class, the particular instance gets saved to the mapped database table.
- Remember only concrete classes can be mapped to dedicated database table.
Database commits are handled by Pega platform.
As a developer all we need to do is,
- Create a new concrete class.
- Create a new table in DB.
- Map the class with the DB table.
First, let’s get to the basics.
What are the ways you can create a table in Pega?
We can see there are few ways by which Pega creates a new DB table without the help of DBA administrator.
1. While creating an application, you will see a work class and a class group (work pool) gets created and mapped to work table. A new work table is created in DB.
Step 1: Create a new application. Select PegaRules as built on application. Select two casetypes.
Step 2: After creating application Designer studio -> Data Model -> Classes & Properties -> database class mappings
You can see the Class mapped to database table.
XYZ-NewHire-Work mapped to pc_XYZ_NewHire_Work
2. Creating a new data type creates a new data table in DB.
Please go through the ‘Data type’ () post to know how to create a new data type.
I created a Candidates data type. As soon as you configure, a local data storage a table gets created.
You can see Data type class – XYZ-Data-Candidates gets mapped to pr_XYZ_Data_Candidates.
3. Optimizing an aggregate property using optimization tool.
A new index table gets created. We will see more about this in separate lesson.
All the above three ways are implemented internally by Pega Platform.
How Pega handles?
There is an OOTB final rule in ‘Rule-Obj-Class’ – pzCreateTableForClass.
This is responsible for creating dedicated database table for particular classes.
What is Database class mapping wizard?
- It is a mapping wizard, which creates a concrete class and maps to a particular DB table.
In simple words, you have a database table. Think, “How can we use that table in Pega?”.
Yes, you are going to map that table to a class. Map the columns to properties.
So saving a class instance implies making an entry to the table.
- You need a separate DB table created in Database.
- Required columns are available in the database table.
How do we use Database class mapping wizard?
Step 1: Move to Designer studio -> Data Model -> Classes & Properties -> database class mappings.
Step 2: Click on the ‘New External Database class mapping’.
You will see a modal dialog.Step 3: Specify the configurations.
Specify database table – Provide the DB name, schema, DB table name.
Specify ruleset class – Specify the ruleset details and a new Class name.
Map database columns to properties –
- Key – You can check the column to make it as key to the table.
- Property Name – You can select the properties in Key column and provide a Property Name in property column.
- Map All/None – Creates new properties, if checked. Pega creates new properties in XYZ-PREM–Data-Countries class.
Here I have selected Country code and country name column, and mapped to different properties CountryCd, CountryDesc respectively.Step 4: Click submit.
You can see that the class gets mapped to new table.
What are the rules that get created by the wizard?
1. A new concrete class – Wizard creates a new concrete class that we provide.
2. New properties – You can check the external mappings tab.New properties are created for CountrCd, CountryDesc, sno
3. Database table instanceNow the connection is ready. When you save any page with class XYZ-PREM-Data-Countries it will make an entry to pr_xyz_data_countries.
What do we need to remember when using the wizard?
- You can substitute the same wizard process by manually creating the following rules.
Step 1: Create a concrete class with class which does not belong to a class group.
Step 2: Create database table instance by specifying the database name and table name. Save the instance.
Step 3: Save the class again and use test connectivity to check if the class is mapped to the database table.
Step 4: Create new properties corresponding to DB table column.
But creating via wizard is highly recommended.
- You can also replicate the same process using Integration – Connector & metadata accelerator.
Connector & metadata accelerator are mainly used for integration with external database. We will discuss that in detail in separate lesson.