using the table api
DESCRIPTION
Using the Table API. Standard Uses of API. Populate Columns via Sequences Insert Default Values instead of nulls Populate Autogen Columns Date Created, Date Modified Who Created, Who Modified Sequence within Parent Force Uppercase Domain Validation Arc validation. Standard Uses of API. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/1.jpg)
Using the Table API
![Page 2: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/2.jpg)
Standard Uses of API• Populate Columns via Sequences• Insert Default Values instead of nulls• Populate Autogen Columns
– Date Created, Date Modified– Who Created, Who Modified– Sequence within Parent
• Force Uppercase• Domain Validation• Arc validation
![Page 3: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/3.jpg)
Standard Uses of API
• Foreign Key Cascades, Nullifies, Defaults, Restricted Delete/Update
• Table Journaling• Derived Columns• Denormalization:
– Copy Parent Value to Child– Aggregate Child Values to Parent
![Page 4: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/4.jpg)
Specification SummarySequence Populated
Denormalized
Uppercase
Domain
Autogen
![Page 5: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/5.jpg)
Force Uppercase
• Set ‘Uppercase’ to Yes• Set ‘Server Derived?’ to Yes• Generate Table API
![Page 6: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/6.jpg)
Uppercase Only
Uppercase
Server Derived?
![Page 7: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/7.jpg)
Autogen Code
• For autogen column– Set Autogen Type
• Date Modified/Created• Created/Modified By• Sequence within Parent
– Set ‘Server Derived’ to Yes.
• Generate API
![Page 8: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/8.jpg)
Autogen Columns
Server Derived?
Autogen Type
![Page 9: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/9.jpg)
Domain Validation
• Via Check Constraint (non-API)• Via Lookup in CG_REF_CODES table• How?
– Define Domain– Define Column using Domain, or– Define Column with ‘Allowable Values’– Generate Table API
![Page 10: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/10.jpg)
Server
Packages
Validating DomainsGAME_CATEGORY
ARC
RV_DOMAIN RV_LOW_VALUE
GAME _CATEGORY ARCGAME _CATEGORY EDUGAME _CATEGORY ROLGAME _CATEGORY SIM
Triggers
CG_REF_CODESCG_REF_CODES
DML
TITLESTITLES
![Page 11: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/11.jpg)
Advantages of REF_CODES
• DBA must alter Check constraint• May have to bring down system • CG_REF_CODES table can be
accessed thru Application
![Page 12: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/12.jpg)
Schema of CG_REF_CODES• RV_DOMAIN
– Domain name, or– Table.column
• RV_LOW_VALUE– One legal value, e.g., UT– Low value of a range
• RV_HIGH_VALUE• RV_ABBREVIATION, e.g., UNIT• RV_MEANING, e.g., Unit Test
![Page 13: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/13.jpg)
Domain Validation
![Page 14: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/14.jpg)
Domain Validation
Server Derived?
Domain
![Page 15: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/15.jpg)
How to Populate with Sequence
• Make sure sequence is defined• For Populated Column:
– Set ‘Sequence’ to desired sequence
• Generate API
![Page 16: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/16.jpg)
Populate with Sequence
Server Derived?
SequenceSequence Defined
![Page 17: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/17.jpg)
Validating Arcs
GAMES
# * PRODUCT_CODE. . .
TITLES
# * PRODUCT_CODE * TITLE
. . . o MO_PRODUCT_CODE o GA_PRODUCT_CODE . . .
MOVIES
# * PRODUCT_CODE. . .DML
TriggersServer
Packages
![Page 18: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/18.jpg)
Arc Validation
• Explicit style only: one column for each FK in Arc
• For each FK in Table with Arc,– Set ‘Arc Number’ same for same arc– Set ‘Arc Mandatory’ to Yes or No
• Generate Table API for Table
![Page 19: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/19.jpg)
Performing Cascade Update
Triggers
PRODUCT_CODE
25
TI_PRODUCT_CODE
2525
TITLESTITLES COPIESCOPIES
Update 30
Server
Packages
3030
![Page 20: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/20.jpg)
Cascading Updates/Deletes
• For foreign key,– Set ‘Update Rule’– Set ‘Delete Rule’– Set ‘Validate In’ to Server or Both
• Generate Table API for Parent and Child at Same Time
• Usually best to generate whole API at one time
![Page 21: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/21.jpg)
Foreign Key Cascade
FK properties (NOT FK Column)
Delete Rule
Validate in Server
![Page 22: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/22.jpg)
Journal Tables
• Have all fields of Base Table• Plus: operation, date, user,
application• Contains only needed table data
– Key for deletes– Key plus updated columns for
updates
![Page 23: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/23.jpg)
Server
Packages
Journaling Tables
PRODUCT_CODE . . .
TITLESTITLES
PRODUCT_CODE . . .
TITLES_JNTITLES_JNTriggers
DML 30
30
![Page 24: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/24.jpg)
To Set Up Journaling
• Table Property: ‘Journal’• Set to
– ‘Server’– or ‘Client Calls Server Procedure’
• Generate API
![Page 25: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/25.jpg)
Denormalization
• Most Common: Bring Parent Value (e.g., Department Name) into Child Column (e.g., Employee Table)
• Aggregate Children (Count, Sum, Average of Child Column)
![Page 26: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/26.jpg)
Copying Denormalized Values
PRODUCT_CODE TITLE
30 TITANIC
TITLESTITLES
TI_PRODUCT_CODE TITLE
COPIESCOPIES
By foreign keyBy foreign key
DML
30
Server
Packages
TITANIC
Triggers
![Page 27: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/27.jpg)
How To Denormalize into Child
• In Child table, for target column– Set ‘From Column’ to column in
Parent.– Set ‘Via Foreign Key’ as appropriate.– Set ‘Server Derived’ to Yes
• Generate API for both parent and child.
![Page 28: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/28.jpg)
Denormalization
. . .
![Page 29: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/29.jpg)
How to Aggregate into Parent
• For target column in parent– Set ‘From Column’– Set ‘Via Foreign Key’– Set ‘Using Operator’ (Count, Sum,
etc.)– Set ‘Server Derived’ to Yes
• Generate API for Parent and Child
![Page 30: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/30.jpg)
Column Derivations• Calculate value based on columns
in the same record– Area := Height * Width– Name := Lname || ‘, ‘ || Fname
• For target column– set ‘Derivation Expression Type’ to
SQL Expression– Enter ‘Derivation Expression’– Set Server Derived to Yes
• Generate API
![Page 31: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/31.jpg)
Specification SummarySequence Populated
Denormalized
Uppercase
Domain
Autogen
![Page 32: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/32.jpg)
Generate DB from Server Model
![Page 33: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/33.jpg)
REF_CODES Table CreatedPROMPT Creating Table 'CG_REF_CODES'CREATE TABLE CG_REF_CODES (RV_DOMAIN VARCHAR2(100) NOT NULL ,RV_LOW_VALUE VARCHAR2(240) NOT NULL ,RV_HIGH_VALUE VARCHAR2(240) ,RV_ABBREVIATION VARCHAR2(240) ,RV_MEANING VARCHAR2(240) )/
![Page 34: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/34.jpg)
REF_CODES Table Populated
DELETE FROM CG_REF_CODESWHERE RV_DOMAIN = 'PCH_TYPE_TYPE'/INSERT INTO CG_REF_CODES (RV_DOMAIN, …)VALUES ('PCH_TYPE_TYPE', 'OT', NULL, 'OTHER', 'Other')/INSERT INTO CG_REF_CODES (RV_DOMAIN, …)VALUES ('PCH_TYPE_TYPE', 'EQ', NULL, 'EQUIP', 'Equipment over $500')/. . .
![Page 35: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/35.jpg)
Generate Table API
![Page 36: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/36.jpg)
Some Messages for Purchases
Creating Table API Error Package CG$ERRORS ...Creating Table API Package Specification for Table 'PURCHASES' ......Creating Table API Package Body for Table 'PURCHASES' ......Creating Trigger Logic for Table 'PURCHASES' ...Creating Before Delete Statement Trigger on 'PURCHASES' ...Creating Before Delete Row Trigger on 'PURCHASES' ...Creating After Delete Row Trigger on 'PURCHASES' ...Creating After Delete Statement Trigger on 'PURCHASES' ...
![Page 37: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/37.jpg)
Package Spec
• Trigger flag to avoid recursive call• Useful Constants• Row variable for Table• Table variable for Table• Procedures ins, upd, del, lck, slct• Procedures for validating arc,
domains, cascading, denormalization
![Page 38: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/38.jpg)
Up_autogen_columns-- Code highlights IF (operation = 'INS') THEN BEGIN IF (cg$rec.PURCHASES_ID is NULL) THEN -- SEQUENCE SELECT PCH_SEQ.nextval INTO cg$rec.PURCHASES_ID FROM DUAL; END IF; EXCEPTION WHEN OTHERS THEN cg$errors.push(SQLERRM, ….) cg$errors.raise_failure; END;
cg$rec.CREATOR := user; -- AUTOGEN cg$rec.CREATEDATE := trunc(sysdate); END IF; cg$rec.ITEM := upper(cg$rec.ITEM); -- UPPERCASE IF(cg$rec.PCH_DNUMBER IS NULL) THEN cg$rec.DNAME := NULL; ELSE SELECT DNAME INTO cg$rec.DNAME -- DENORMALIZATION FROM DEPARTMENTS WHERE DNUMBER = cg$rec.PCH_DNUMBER; END IF;
![Page 39: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/39.jpg)
Test With SQLPLUSSQL> insert into purchases( 2 PURCHASES_ID,PCH_DNUMBER,DNAME,ITEM,PCH_TYPE,QUANTITY,COST, 3 CREATOR,CREATEDATE) 4 values( 5 null, 10, null, 'soap', 'SU', 1, 10, 6 null,null);
ID DNO DNAME ITEM PC QTY COST CREATOR CREATEDAT---- ---- --------------- ----- -- ---- ---- ---------- --------- 5 10 ADMINISTRATION SOAP SU 1 10 IBL 16-APR-00
![Page 40: Using the Table API](https://reader035.vdocument.in/reader035/viewer/2022081418/56813ba6550346895da4d8b5/html5/thumbnails/40.jpg)
Test with Form