Upload
gervase-allen
View
214
Download
1
Embed Size (px)
Citation preview
Benefits of Server-Side CodeSpeedy Pizza
MENUNAPOLITAINE
PIZZA
• Reduced network traffic
• Maintainability• Data integrity
TriggersProceduresFunctionsPackages
Older Editions of Designer
• Most constraints only enforced in application
• Server vulnerable to other access methods
• Application code references tables and generates network traffic
Database Trigger
• NOT a form trigger– When-enter-block, When-validate-item…
• Occurs in server• Associated with Lock or DB modification• Before or After DB event• For every affected Row, or• For SQL Statement
What Is a Database Trigger?
ITEMS
DMLDMLactionaction
Database TriggerCode that is implicitly executed when an INSERT, UPDATE, or DELETE statement is issued against its associated table or view
• When
– Before DML
– After DML
• What
– Row
– Statement
TriggerTrigger
Triggers and Packages
• Triggers often call procedures in Packages
• Packages provide Scope for Variables shared by Procedures
• Each process gets own copy of Package Variables
RENTALS
PublicDefinitions
Packages
1+ 1
2
Procedures
Functions
Public andPrivate Elements
BodyBodyActionAction
Value = 2Value = 2
SpecificationSpecification
PL/SQL in the Repository
APPLICATION[1]
Relational Table Definitions
PL/SQL Definitions
PL/SQL Composition
Navigator - Server ModelNavigator - Server Model
Server Model Distribution
Triggers
Functions
Procedures
Triggers
Packages Structure
Implementation
PL/SQL Definitions
PL/SQL DefinitionsFunction DefinitionsPackage DefinitionsProcedure Definitions
Cursor DefinitionsTrigger DefinitionsUndefined PL/SQL
Server Model
ArgumentsSub Program UnitsProgram DataDatastructuresSynonyms
P_SET_PRICE
CREATE . . . ( p_name IN VARCHAR2) IS
v_date DATE; TYPE table_type IS . . .BEGIN IF . . . THEN . . . ; . . . callprocedure(v_date); . . .END;
Navigator - Server ModelNavigator - Server Model
PL/SQL Definitions
PL/SQL Composition
Server Model
Relational Table DefinitionsAPPLICATION[1]
TITLES
TriggersTRIG1
Columns
Trigger LogicTRIG1
TRIG1
PL/SQL DefinitionsTrigger Definitions
Trigger Header Definition
PL/SQL DefinitionCompleteEnabledTrigger . . .When Condition
. . .PL/SQL Block. . .
PL/SQL Logic
Defining Triggers
PL/SQL Definitions
Procedure DefinitionsP_SET_PRICE
Navigator - Server Model
Opening the Logic Editor• Drag the definition to the work
surface
Using the Logic Editor
PROCEDURE
PL/SQL PROCEDURE
Select
INTO
FROM
WHERE
SELECT title
INTO v_title
FROM titles
WHERE product_code = p_product_code;...
SELECT
OutlinerOutliner
Text EditorText Editor
PL/SQL
Root
Constructs
Statements
Static Data
Construct TreeConstruct Tree
Generating PL/SQL ObjectsDDL file:• CREATE OR
REPLACE statements
• Header• Data declarations• PL/SQL logic
Use the utility as you would for Use the utility as you would for other database objectsother database objects
Fortunately ...
• You do not have to write most triggers or packages
• Designer writes them for you• You give specifications• You generate Table API• All this code used to be in
Applications
Table API Keeps Applications Thin Application
Validation code
Application
Tables Tables
Table API
Tables
Table API Packages
• Are called by:– Applications– Triggers
• Perform DML operations• Validate data• Derive column values
ServerPackages
Server PackagesPackage cg$titles
Insert
Update
Delete
Lock
procedures . . .callcg$titles.ins Insert
TITLES
# * PROD_CDE * TITLE . . .
TITLES
# * PROD_CDE * TITLE . . .
In-sert
trigger
Why API?
• Table API provides a Table Handler for each package
• Normal DML causes Triggers to Invoke Handlers
• Applications can call API procedures directly– Disabling recursive call of trigger
Applications and the API
TABLEColumn_1Column_2
Server
Packages
Form BuilderForm Builderapplicationapplication
Triggers
WebServerWebServerapplicationapplication