Database class mapping wizard in Pega

Introduction

In this post we will see how to use database class mapping wizard

Pega 7 introduced a separate database schema for rule and data.

  1. PegaRules – Contains rule tables.
  2. 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,

  1. Create a new concrete class.
  2. Create a new table in DB.
  3. 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’ (http://myknowpega.com/2017/05/13/data-type-cascad…-control-example/) 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.

Prerequisites:

  • 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.

14 thoughts on “Database class mapping wizard in Pega

  1. Hi
    Can u update the details regarding external database I.e how to insert New table in external db by using pega application

    1. Bro. I will get that done. Give me some time. I am switching my work to new laptop shortly. Some DB config issue us there

    1. Hi Pradeep, you can expect an exclusive post on rule availability with examples within a week. Stay tuned 🙂

    2. Thanks u very much prem for posting rule availability it’s very helpful to me. please post how to do exceptions in integration and in activities. it is available in pdn but it is very difficult to understand .

      1. You are most welcome, Pradeep. 🙂
        Yeah, I’ve taken note of those topics. I’ll try my best to post them soon. I’ll help you in all the possible ways. 🙂
        Stay tuned.

    1. You have created a new data table in database with the help of DB administrators.
      You need to map a Pega class to that table. In such scenario, you can make use of that database class mapping wizard.

  2. Hi prem,

    i have a doubt that,if i create a properties in work- class then how can i use this properties in data – class.and how can i save this in data table.please the answer.

    Regards.

    1. Hi Gangadhar, the inheritance path of work class and data class meet by @baseclass only. So unless the property is in @baseclass, it cannot be reused in work- and data- class. I would recommend you to create a separate property in work and data class. Hope you are clear now

Leave a Reply to Premkumar G Cancel reply

Your email address will not be published. Required fields are marked *