Вы находитесь на странице: 1из 3

7/10/2016

UserHook

UserHook
Overview
1.APIUserHooksallowuserstoextendthebusinesslogicofthestandardbusinessrulesthatare
executedbyAPIs.Thisisdonebyallowingcustomprocedurestobecalledatspecificpointsinthestandard
APIs.Forinstance,weareimplementUserHooksforextendingthevalidationofdatabeyondwhatthe
standardsystemhasprovided.

StepsforImplementingUserHooks
1.ChoosetheAPIyouwishtohooksomeextralogicto.
2.WritethePL/SQLprocedurethatyouwishtobecalledbythehook.
3.Registerorassociatetheprocedureyouhavewrittenwithoneormorespecificuserhooks.
4.RunthepreprocessorprogramwhichbuildsthelogictoexecuteyourPL/SQLprocedurefromthe
hookspecifiedin3.
Example
1.IfvalidationsneedtobedoneonPersonExtraInformationwhentheinformationiscreatedthenwe
needtochecktheavailabilityofmodule_namecalledasCREATE%PERSON%EXTRA%INFO%
ORweneedtoguessrelatedAPIinall_objects
SELECT*
FROMhr_api_modules
WHEREapi_module_type='BP'
ANDmodule_nameLIKE'CREATE%PERSON%EXTRA%INFO%'
OR
select*fromall_objectswhereobject_namelike'%PERSON%EXTRA%API'
2.Ifmoduleexistweneedtofindoutitsmodule_idandrelatedhook_ids
SELECTahk.api_hook_id,ahm.api_module_id,ahk.hook_package,ahk.hook_procedure,
ahk.api_hook_type,ahm.api_module_type
FROMhr_api_hooksahk,hr_api_modulesahm
WHEREahm.module_name='CREATE_PERSON_EXTRA_INFO'
ANDahm.api_module_typein('BP')
ANDahk.api_hook_typein('AP','BP')
ANDahk.api_module_id=ahm.api_module_id
QueryResult:
API_HOOK_ID

API_MODULE_ID

HOOK_PACKAGE

HOOK_PROCEDURE

2759

1226

HR_PERSON_EXTRA_INFO_BK1

CREATE_PERSON_EXTRA_INFO_A

2758

1226

HR_PERSON_EXTRA_INFO_BK1

CREATE_PERSON_EXTRA_INFO_B

HereBPBeforeProcessandAPAfterProcess
The2BusinessProcesshookand3RowHandlerHooksavailable:
BeforeProcessThesehooksexecutelogicbeforethemainAPIlogic.Themajorityofvalidationwillnot
http://dipsoracleeasytechnics.blogspot.in/2012/06/userhook.html

1/3

7/10/2016

UserHook

havetakenplace.Nodatabasechangeswillhavebeenmade.
AfterProcessThesehookswillexecuteafterthemainAPIvalidationhascompletedanddatabase
changesmade.Ifthemainvalidationfailedthentheuserhookwillnotbecalled.
The3typesofRowHandler(RH)hookavailableare:
AfterInsert
AfterUpdate
AfterDelete
3.UsuallyweuseAfterProcess.(say:CREATE_PERSON_EXTRA_INFO_A)
4.CreateCustomPackageandprocedurecode
CREATEORREPLACEPACKAGEak_user_hook_leave_return_pkg
IS
PROCEDUREAir_ticket_request(p_person_idINNUMBER,
p_information_typeINVARCHAR2,
p_pei_information1INVARCHAR2)
ENDak_user_hook_leave_return_pkg
Note:WhilecreatingCustomprocedurepasstheparameterswhicharepresentinstandardprocedure
ParametersinprocedureAir_ticket_requestshouldmatchwithparametersin
CREATE_PERSON_EXTRA_INFO_A.
DuetothisstandardprocedureCREATE_PERSON_EXTRA_INFO_Apassesvalueslikep_person_id,
p_information_type,p_pei_information1dynamicallytoourcustomprocedureAir_ticket_request.
5.RegisteringtheUserHook
DECLARE
l_api_hook_call_idNUMBER
l_object_version_numberNUMBER
BEGIN
hr_api_hook_call_api.create_api_hook_call(
p_validate=>FALSE,
p_effective_date=>TO_DATE(sysdate),
p_api_hook_id=>2759,frompoint2
p_api_hook_call_type=>'PP',
p_sequence=>3000,
p_enabled_flag=>'Y',
p_call_package=>'XX_USER_HOOK_PKG',ourcustompackage
p_call_procedure=>XXAIR_TICKET_REQ',ourcustomprocedure
p_api_hook_call_id=>l_api_hook_call_id,
p_object_version_number=>l_object_version_number)
END
DeleteUserHookcreated(Usewhenrequired)
DECLARE
l_api_hook_call_idNUMBER:=1210passappropriatevalue
l_object_version_numberNUMBER:=27passappropriatevalue
BEGIN
hr_api_hook_call_api.delete_api_hook_call(
p_validate=>FALSE,
p_api_hook_call_id=>l_api_hook_call_id,
http://dipsoracleeasytechnics.blogspot.in/2012/06/userhook.html

2/3

7/10/2016

UserHook

p_object_version_number=>l_object_version_number)
END
6.ChecktheTable:hr_api_hook_calls
Ifcustomcodeisproperlyhookedwithstandardcodethenonerecordwillbecreated
SELECT*FROMhr_api_hook_callsWHERETRUNC(SYSDATE)=TRUNC(creation_date)
7.RunningthePreProcessor(MostlydonebyDBA)
RunfollowingisthecommandinPutty
(Weneedtofindlocationoffile:hrahkone.sql)
>cd$PER_TOP/admin/sqlor>cd$PER_TOP/patch/115/sqloranyothersuggestedbyDBA
(Opensqlplus)
>sqlplususername/password
(Runthefilehrahkone.sql)
>@hrahkone.sql
Itwillaskforapi_module_idwhichwefoundatpoint2
>Entervalueforapi_module_id:1226
Ifallworksfineitwillshowmessageas:

PL/SQLproceduresuccessfullycompleted.
CREATE_PERSON_EXTRA_INFO(BusinessProcessAPI)successful.
8.ChecktheTableagain:hr_api_hook_calls
IfPreProcessorissuccessfulSTATUSwillbeVelseitwillbeIorN

http://dipsoracleeasytechnics.blogspot.in/2012/06/userhook.html

3/3

Вам также может понравиться