Skip to Content

Generating Core Data Services files with Sybase PowerDesigner

Contents


Generating Core Data Services files with Sybase PowerDesigner. 1

What is Core Data Services?. 1

The basics: Creating a project, a physical data model and the data model 1

Installing the HDBCDS Extension File (HDBCDS.xem). 6

The funny part: Generating the CDS definition file. 8

Using Domains in the Data Model (CDS Basic Types). 11

Working with multiple Contexts. 13

Conclusion. 16


What is Core Data Services?

As described in the SAP HANA CDS Reference guide, Core Data Services (CDS) is an infrastructure that can be used by database developers to create the underlying (persistent) data model which the application services expose to UI clients.

In that sense, CDS looks to be similar to SQL DDL but the key advantage is that CDS definition files are created as design-time objects that means that can be transported together with HANA Models.

Design-time objects for Data Model definition + logic + UI layer is indispensable for Native HANA Apps.

With this SPD Extension you can create CDS (.hdbdd) files from Physical Data Models.

So, let’s take the following example from the SAP HANA CDS Reference Guide

/wp-content/uploads/2015/04/1_770072.png

This code creates two tables after activation in the schema MYSCHEMA.

The CDS Guide explains in details all the elements that composes a CDS file (.hdbdd).


The basics: Creating a project, a physical data model and the data model


Go to File -> New Project and give a name to the project

/wp-content/uploads/2015/04/2_691540.png

1)      Go to File -> New Model and select Physical Model under the Information category.

/wp-content/uploads/2015/04/3_691544.png

2)      Create the Book and Author tables

/wp-content/uploads/2015/04/4_691545.png
/wp-content/uploads/2015/04/5_691546.png

3)      Create the SCHEMA

Go to Model -> User and Roles -> Schemas

/wp-content/uploads/2015/04/6_691547.png

/wp-content/uploads/2015/04/7_691548.png

4)    Set the Table’s owner


Go to Model -> Tables

/wp-content/uploads/2015/04/8_691549.png

And set the Owner column to MYSCHEMA

/wp-content/uploads/2015/04/9_691550.png

5)      Preview the Data Model (press Ctrl+G or Right click on the Model -> Properties )

/wp-content/uploads/2015/04/10_691551.png


Installing the HDBCDS Extension File (HDBCDS.xem)


Before proceeding we must create a folder to store the .XEM extension file.


Go to Model -> Extensions -> Attach an Extension


/wp-content/uploads/2015/04/11_691552.png

Click on Path and select the folder that contains the .XEM file

/wp-content/uploads/2015/04/12_691553.png

/wp-content/uploads/2015/04/13_691554.png

After the Path is added, select the HDBCDS extension

/wp-content/uploads/2015/04/14_691555.png

Once the HDBCDS extension is added, a new object is added to the toolbox for creating contexts

/wp-content/uploads/2015/04/15_691559.png

The funny part: Generating the CDS definition file

Before generating the .hdbdd file from the PDM we must create a Package and a Context.

Using the package tool in the toolbox under SAP HANA Database 1.0 category, create a package named com.acme.myapp1

/wp-content/uploads/2015/04/16_691560.png

Use the context tool to create a context named Books.

/wp-content/uploads/2015/04/17_691561.png

Set the context Books as main context for the data model.


Go to Model Properties (right click on DemoCDS Model -> Properties)
In the CDS Tab set the Books context for the Context property

/wp-content/uploads/2015/04/18_691562.png

Finally, generate the CDS Definition files. Go to Tools -> Extended Generation

/wp-content/uploads/2015/04/19_691563.png

In the Targets tabs select HDBCDS, let the Selection by default selecting all objects and in Generated Files select the .hdbdd and .hdbschema files.
Set an output directory and click Ok to generate the two files

/wp-content/uploads/2015/04/20_691564.png
/wp-content/uploads/2015/04/21_691565.png

Using Domains in the Data Model (CDS Basic Types)

CDS supports the definition of shared types so that your columns definition can reference the types instead of declaring explicit the data type.

f.e.

/wp-content/uploads/2015/04/22_691566.png

To use this feature, go to Model -> Domains and define a Domain, for example “TextoLargo” defined as VARCHAR(100)

/wp-content/uploads/2015/04/23_691567.png

Set the Domain in the columns definition, instead of setting the Data Type.

Go to Model -> Columns

/wp-content/uploads/2015/04/24_691571.png

And set de Domain value to “TextoLargo” for those fields of Varchar(100) type

Tip: If the Domain column is not present in the Columns properties, press Ctrl+U and select “Domain”.

Go to Tools -> Extended Generation and generate the model.hdbddfile once again.

/wp-content/uploads/2015/04/25_691572.png

Working with multiple Contexts

As described in the CDS Guide, we can define multiple contexts for grouping tables that belongs to the same functional group.

For instance, let’s rename the Book context to Main context, and create 2 more contexts named “Datamodel” and “Application”

Go to the Book table’s properties, and select the CDS tab, then set the Context to “Datamodel

/wp-content/uploads/2015/04/26_691573.png

Create a 3rdtable named UILogic and set the “Application” context in the CDS Tab


/wp-content/uploads/2015/04/27_691574.png

Finally, generate the hdbdd file to see the context definition.

/wp-content/uploads/2015/04/28_691575.png


Conclusion


It is possible to use Sybase PowerDesigner to generate SAP HANA CDS files. Using an enterprise modeling tool such as PowerDesigner gives more transparency in the model definition and simplifies the data model maintenance. There is no big effort to generate the CDS file once the PDM is defined.


There are some limitations in this extension, for example structured typed cannot be created.


If you want to enhance this extension, feel free to modify the code.


Go to Extensions -> HDBCDS -> Properties to see all the code behind this extension

/wp-content/uploads/2015/04/29_691576.png

To report this post you need to login first.

8 Comments

You must be Logged on to comment or reply to a post.

  1. Juan Escalante

    Hi Martin! Very useful guide. I don’t know if im the only one who cannot see first picture after “What is Core Data Services”.

    Cheers,

    Juan

    (0) 
  2. G. Cheung

    Thanks Martin! CDS generation from PD was something I was in dire need of and wondering if that was possible. Thanks again for sharing!

    Cheers,

    Glenn

    (0) 
  3. Luis Becker

    Hello Martin

    Excellent post and very useful extension.

    Some nice features can still be added, like including associations generation for foreign keys. As far as I’ve tested, this feature it’s not included yet.

    Maybe if you could share some links on how to work with PowerDesigner extensions, more people interested in the subject could help to enhance this nice extension.

    Regards

    Luis Becker

    (0) 
      1. Luis Becker

        Hi Martin

        I’m sure will be glad to help you in extending the extensions, but up till now I hadn’t time to dig deeper in the subject and work in more complex features like associations.

        One very small change that I’ve done is to add support for NVARCHAR, which wasn’t supported, just adding two lines on  “tipoDato” template:

        .elsif(%.2:ConceptualDataType% == “VM”)

        String(%Length%)

        But sure I’ll let you know and share if I’m able to do further improvements.

        UPDATE: finally I’ve made it to modify the file to allow it to create unmanaged associations. It works with 0..* and 1..* associations and do the backlink also. Let me know how can we share and even improve it more.

        Best regards (o saludos desde el país vecino)

        Luis Becker

        (0) 

Leave a Reply