Introducing Deployment Options of Persistence Models

Objectives
After completing this lesson, you will be able to:

After completing this lesson, you will be able to:

  • Describe deployment options of persistence models

Describe Deployment options of Persistence Models

As seen in the unit for SAP Cloud Application Programming Model, the idea is to allow open tooling for the Application Development.

Following this concept and to allow greater flexibility in Application Development.

From a Development standpoint, SAP Business Application Studio is used as the preferred tooling for Application Development when using SAP Cloud Application Programming Model, at the same time other tools are also allowed. example Visual Studio with CDS Extension, Eclipse,Docker,Jupyter notebooks.

From a Deployment standpoint, SAP Cloud Application Programming Model allows two deployment options.

  • Local:

    The idea with the local development is to provide quick development and test cycles

    For Local developments, SAP Cloud Application Programming Model automatically bootstraps an SQLite in-process and in-memory database by default - that is, unless told otherwise.

    While this isn’t meant for productive use, it drastically speeds up development turn-around times, essentially by mocking your target database, for example, SAP HANA.

  • Persistence:
    • SQLite:

      Instead of using in-memory, we can also use persistent databases. For example, still with SQLite:

      The difference from the automatically provided in-memory database is that we now get a persistent database stored in the local file

    • SAP HANA Cloud:

      Once the development and tests are complete, the developments can be deployed to the SAP HANA Cloud Database or alternatively you can directly start with this option. A set of prerequisites has to be followed when deploying the developments to SAP HANA Cloud and this will be mentioned later.

Describing the Local Deployment option

This chapter mentions the steps required for the Local deployment.

  1. Define Domain Model:

    In this step we create the .cds file under the db folder for the entities that are required for the Persistence. The data definition file here is the Domain Model because this captures the entity relationship. This is the complete application data model

    We will use .csv files to load the data in the tables that will be created. The .csv files are stored in db/data folder.

  2. npm install :

    npm install reads the dependencies from your package.json and download all the specified modules into your project from the internet.

  3. Build:

    The content needed for the models, that is, tables, views, data are placed into a separate /gen folder in your project. This keeps the sources separate from the deployable/executable portions of your project. You can see this addition to the project structure in the main project navigation area. The command cds build is used.

  4. Compile :

    This step is optional but helps to check the definitions that are used during the creation of Persistence layer in SQL and HANA and the objects created during the actual deployment.

    The commands cds compile schema.cds – to HANA or cds compile schema.cds – to sql are used at the db level.

    Note
    HANA deployment shows usage of .hdbcds table but .hdbcds is not supported in SAP HANA Cloud, so we need to perform minor modification to enable HANA Deployment. This will be covered in the next Lesson on SAP HANA Cloud deployment.
  5. Deploy:

    In case of Local deployment,

    using cds deploy The Sqlite in-memory db is used by default.

    In case Local deployment with persistence is required we use the

    cds deploy --to sqlite is used.

Watch this video to learn about the process flow for Local Deployment

Describing the Persistence Deployment Option

This chapter mentions the steps required for the SAP HANA Cloud Deployment.

Watch this video to learn about the process flow for SAP HANA Cloud Deployment.

Local Persistence Deployment option in SAP CAP

HANA Persistence Deployment option in SAP CAP

Explore Service Instance on SAP BTP

Explore Database Artifacts on DB Level

Data and Code File - Describe Deployment options of Persistence Models

We define the Domain model using .cds, we create a file under db folder schema.cds (name can be anything). Copy the below code.

In the code below, we see

  • namespace
  • @sap/cds/common Referring to the Model reuse topic. Here we use Currency from the common types provided. This can be declared using the using {}from@sap/cds/common.
  • Association
  • Composition
  • multiline
  • Annotations (@)
Code snippet
namespace hc450.officesupplies;

using {Currency} from '@sap/cds/common';

entity Products {
 @Common.Label : 'UUID'
 key ID : UUID;
 identifier : String @Common.Label : 'ProductID';
 title : localized String @(Common.Label : 'Name');
 description : localized String;
 availability : Integer;
 storage_capacity : Integer;
 criticality : Integer;
 price : Decimal(9, 2);
 currency : Currency;
 supplier : Association to Suppliers;
 image_url : String;
}

entity Suppliers {
 key ID : UUID;
 identifier : String;
 name : String;
 phone : String;
 building : String;
 street : String @multiline;
 postCode : String;
 city : String;
 country : String;
 products : Composition of many Products
 on products.supplier = $self;
}
Expand

Next we create the .csv files for data in the data folder underdb folder. We can create all four files now or leave the currencies file for later as they are needed for the SAP Fiori development.

Below is the data for the four files in sequence.

  • hc450.officesupplies-Products.csv
  • hc450.officesupplies-Suppliers.csv
  • sap.common-Currencies.csv
  • sap.common.Currencies_texts.csv
Note
The file names are case sensitive as they need to be associated with the tables later. Also notice here the usage of namespace before the file name.
Code snippet
ID,IDENTIFIER,TITLE,DESCRIPTION,AVAILABILITY,STORAGE_CAPACITY,CRITICALITY,PRICE,CURRENCY_CODE,SUPPLIER_ID,IMAGE_URL
844ede5c-071e-34ed-907f-f99cb3a4693d,MC-CM-1003,Tea- / Coffee-Mug,Robust high-quality ceramic mug for every-day use in two unobstrusive colours.,153,200,0,2.65,USD,8b001df1-dab2-39a2-8b1a-89b6b445e237,../images/mug.png
64d40922-ea0d-30f9-9b83-eb4448ee4c2e,MC-CH-1000,Coat Hangers,"Set of high-quality hangers with coated surface, trouser bar - anti slip. Super slim design - space saving - The hooks can be rotated through 360 degree rotation, practical for various room situations. Material: ABS (plastic); Colour: turquoise.",10,200,3,2.6,USD,12726eec-165c-3713-a674-3d2fc4f5127f,../images/hanger1.png
a6756d40-792e-34c9-8b2e-df3acb0c54b4,MC-CH-1001,Coat Hangers,"Set of high-quality hangers with coated surface, trouser bar - anti slip. Super slim design - space saving - The hooks can be rotated through 360 degree rotation, practical for various room situations. Material: ABS (plastic); Colour: assorted (2 of each pink, grey, blue green, black).",34,200,2,21.73,USD,12726eec-165c-3713-a674-3d2fc4f5127f,../images/hanger2.png
37f028f0-1dd5-30ae-9cdd-a7f543e4d61d,MC-CH-1002,Wooden Coat Hangers - Pack of 5,"Pack of 5 quality wooden hangers with trouser bar. Slim design for space saving - The hooks can be rotated through 360 degree rotation, practical for various room situations. Material: ABS (plastic); Colour: assorted (2 of each pink, grey, blue green, black).",5,200,2,6.4,USD,8b001df1-dab2-39a2-8b1a-89b6b445e237,../images/hanger3.png
a376e380-00e8-3d90-ba9f-c332c2df0f28,MC-CH-1003,Designer Coat Hooks - Pack of 3,Pack of 3 designer coat hook. Heavy-duty stainless steel hooks in a stylish shape.,6,200,1,6.49,USD,8b001df1-dab2-39a2-8b1a-89b6b445e237,../images/hanger4.png
fc16c43d-bb4e-30db-8b7e-98b3fdc7f0b9,MC-CH-1004,Vacuum Wall Hook - Pack of 6,"Big suction cup with diameter of 70mm, can load more than 10kg; bright contemporary colour; Principle of work: Atmospheric pressure, safely and easy to install and tear off, no need to drill a hole or add glue, without any damage to the surface; can be used on a variety of surfaces, including paint, glasses, wood, ceramic tile, gypsum, and any other smooth surface.",17,200,0,5.76,USD,12726eec-165c-3713-a674-3d2fc4f5127f,../images/hanger4.png
Expand
Code snippet
ID,IDENTIFIER,NAME,COUNTRY,POSTCODE,CITY,STREET,BUILDING,PHONE
12726eec-165c-3713-a674-3d2fc4f5127f,OFFIPOR,OffiPOR,PR,Guaynabo,PR 00968,City View Plaza,301,+1 787-38515864
9655e5b6-bd8c-31ee-b94a-0651449721a0,POLIRADO,POLirado,PL,Warszawa,02-675,Ul. Woloska,5,+48 883 77522087
f1fd8dd5-3156-3469-b4f1-a03ff5041080,REGULCUST,Regular Custom Ltd,GB,Knutsford,WA16 6DW,King Street,25,+44 1565 47759991
bb2fa1e5-5c3a-3d26-b5c1-ed53f3e08622,OFFICEGURU,Office-Guru AG,DE,Siegen,57078,Birlenbacher Str.,19-21,+49 271 7722547
b91f077f-2086-3517-8244-d3b50835651b,MEINRESSORT,Mein Ressort GmbH,CH,Regensdorf,8105,Althardstrasse,80,+41 44 84008483
8b001df1-dab2-39a2-8b1a-89b6b445e237,OFFICELINE,Office Line Prag,CZ,Praha,140 00,Vyskocilova,1481/4,+420 776 9487923
3c7e6cbb-ea0f-35d2-a2ce-c85057a57916,DEPOT4ALL,Depot-4All,DE,Freiberg a. N.,71691,Grundelbachstrasse,10,+49 7141 2463585
41b46958-5ad7-30b6-9884-b547c1e26b7e,ITELOFFICE,ITeL-Office,DE,Dresden,01187,Chemnitzer Strasse,48,+49 351 31915489
7c5a5e3a-6dfa-35d3-8bf4-0cadbddb761a,FAMOUSUS,FamousUS,US,Houston,TX 77098,2601 Westheimer Road,Suite C250,+1 713-12001085
36de419f-0a4c-3a5a-b285-188979ce13ec,CHINACHAIN,ChinaChain,CN,Guangzhou,510613,No. 233 Tien He Road North,6402-6403,+86 20 86454650
41b922ad-35d9-352d-80c7-ee63ba1c007c,FAMOUSUS1,FamousUS (LV),US,Las Vegas,NV 89118,W Sunset Rd,3620,+1 702-486454400
b4b3188c-fa27-3467-a38a-f36ede8acc18,FAMOUSUS2,FamousUS (SF),US,South San Francisco,CA 94080,Forbes Blvd,401,+1 650-486454500
b5f1b294-a102-38e1-88c5-9b4d9ff0dd33,FAMOUSUS3,FamousUS (NY),US,New York,NY 10128,3rd Ave,1588,+1 212-486454600
391da904-9acd-334b-885e-4b4da38f3c6e,FAMOUSUS4,FamousUS (ORL),US,Orlando,FL 32806,W Sturtevant St,47,+1 407-486454700
1f6aed3b-bac0-39e5-ba5b-c091b0d18f40,FAMOUSUS5,FamousUS (NSH),US,Nashville,TN 37211,Space Park S Dr,486-810,+1 615-486454800
Expand
Code snippet
name,descr,code,symbol
Euro,European Euro,EUR,€
US Dollar,United States Dollar,USD,$
Canadian Dollar,Canadian Dollar,CAD,$
Australian Dollar,Canadian Dollar,AUD,$
British Pound,Great Britain Pound,GBP,£
Shekel,Israeli New Shekel,ILS,?
Rupee,Indian Rupee,INR,?
Riyal,Katar Riyal,QAR,?
Riyal,Saudi Riyal,SAR,?
Yen,Japanese Yen,JPY,¥
Yuan,Chinese Yuan Renminbi,CNY,¥
Expand
Code snippet
locale,name,descr,code
de,Euro,European Euro,EUR
de,US-Dollar,United States Dollar,USD
de,Kanadischer Dollar,Kanadischer Dollar,CAD
de,Australischer Dollar,Australischer Dollar,AUD
de,Pfund,Britische Pfund,GBP
de,Schekel,Israelische Schekel,ILS
fr,euro,de la Zone euro,EUR
fr,dollar,dollar des États-Unis,USD
fr,dollar canadien,dollar canadien,CAD
fr,dollar australien,dollar australien,AUD
fr,livre sterling,pound sterling,GBP
fr,Shekel,shekel israelien,ILS
Expand

Log in to track your progress & complete quizzes