1: package body WF_BES_CACHE as
2: /* $Header: WFBECACB.pls 120.6.12010000.2 2008/08/09 13:32:40 sstomar ship $ */
3:
4: /*---------+
5: | Globals |
76: attribute => 'WFBES_METADATA_UPLOADED',
77: value => to_char(sysdate, g_date_mask));
78: exception
79: when others then
80: wf_core.context('WF_BES_CACHE', 'MetaDataUploaded');
81: raise;
82: end SetMetaDataUploaded;
83:
84: -- GetMetaDataUploaded (PRIVATE)
92: l_value := sys_context('WFBES_CACHE_CTX', 'WFBES_METADATA_UPLOADED');
93: return to_date(l_value, g_date_mask);
94: exception
95: when others then
96: wf_core.context('WF_BES_CACHE', 'GetMetaDataUploaded');
97: raise;
98: end GetMetaDataUploaded;
99:
100: -- SetMetaDataCached (PRIVATE)
126: l_lastMetaUpload := GetMetaDataUploaded();
127:
128: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
129: wf_log_pkg.string(wf_log_pkg.level_statement,
130: 'wf.plsql.WF_BES_CACHE.CacheValid.Check',
131: 'Last upload time {'||to_char(l_lastMetaUpload, g_date_mask)||
132: '} Last cache time {'||to_char(g_LastCacheUpdate, g_date_mask)||'}');
133: end if;
134:
158: -- if cache is invalid, clear it so that it can be rebuilt from database
159: if (not CacheValid()) then
160: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
161: wf_log_pkg.string(wf_log_pkg.level_statement,
162: 'wf.plsql.WF_BES_CACHE.ValidateCache.Cache_Invalid',
163: 'Cache is invalid. Clearing the cache');
164: end if;
165: ClearCache();
166: end if;
226: p_event_obj.java_generate_func, p_event_obj.licensed_flag;
227: if (c_get_event%NOTFOUND) then
228: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
229: wf_log_pkg.string(wf_log_pkg.level_statement,
230: 'wf.plsql.WF_BES_CACHE.Load_Event.Not_Found',
231: 'Event {'||p_event_name||'} not found in the database');
232: end if;
233: -- If event not found in the set wf_event_obj to null
234: p_event_obj := null;
278: and subscription_source_type = cp_source_type
279: and ((subscription_source_agent_guid is NOT NULL AND
280: subscription_source_agent_guid = nvl(cp_source_agent_guid, subscription_source_agent_guid))
281: OR subscription_source_agent_guid is NULL)
282: and system_guid = wf_bes_cache.g_local_system_guid
283: order by 5;
284:
285: cursor active_event_subs(cp_event_name varchar2,
286: cp_source_type varchar2,
332: -- Check if subscriptions are already loaded for this source type
333: if (upper(p_event_obj.GetSubsLoaded(p_source_type)) = g_status_yes) then
334: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
335: wf_log_pkg.string(wf_log_pkg.level_statement,
336: 'wf.plsql.WF_BES_CACHE.Load_Subscriptions.Check',
337: p_source_type||' subscriptions for event {'||
338: p_event_name||'} are already loaded.');
339: end if;
340: return;
347: if (lower(p_event_name) in (g_event_unexpected, g_event_any)) then
348: open active_event_subs(p_event_name, p_source_type, p_source_agent);
349: if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
350: wf_log_pkg.string(wf_log_pkg.level_procedure,
351: 'wf.plsql.WF_BES_CACHE.Load_Subscriptions.active_event_subs',
352: 'Using cursor active_event_subs for event {'||p_event_name||'}');
353: end if;
354:
355: loop
390: else
391: open active_subs(p_event_name, p_source_type, p_source_agent);
392: if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
393: wf_log_pkg.string(wf_log_pkg.level_procedure,
394: 'wf.plsql.WF_BES_CACHE.Load_Subscriptions.active_subs',
395: 'Using cursor active_subs for event {'||p_event_name||'}');
396: end if;
397:
398: loop
433: end if;
434:
435: if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
436: wf_log_pkg.string(wf_log_pkg.level_procedure,
437: 'wf.plsql.WF_BES_CACHE.Load_Subscriptions.End',
438: 'Loaded {'||l_count||'} '||p_source_type||' subscriptions '||
439: 'for event {'||p_event_name||'}');
440: end if;
441:
458: l_dummy pls_integer;
459: begin
460: if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
461: wf_log_pkg.string(wf_log_pkg.level_procedure,
462: 'wf.plsql.WF_BES_CACHE.GetEventByName.Begin',
463: 'Getting event details for {'||p_event_name||'}');
464: end if;
465:
466: l_event_obj := null;
475: -- the session
476: if (not wf_object_cache.IsCacheCreated(g_Event_Idx)) then
477: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
478: wf_log_pkg.string(wf_log_pkg.level_statement,
479: 'wf.plsql.WF_BES_CACHE.GetEventByName.Create_Cache',
480: 'Cache is not created for EVENTS index {'||g_Event_Idx||'}');
481: end if;
482: wf_object_cache.CreateCache(g_Event_Idx);
483: SetMetaDataCached(sysdate);
483: SetMetaDataCached(sysdate);
484: else
485: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
486: wf_log_pkg.string(wf_log_pkg.level_statement,
487: 'wf.plsql.WF_BES_CACHE.GetEventByName.Cache_Get',
488: 'Getting the event from Cache');
489: end if;
490: Get_Event_Object(p_event_name, l_event_obj);
491: end if;
494: -- retrieve the details from the database
495: if (l_event_obj is null) then
496: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
497: wf_log_pkg.string(wf_log_pkg.level_statement,
498: 'wf.plsql.WF_BES_CACHE.GetEventByName.Load_Event',
499: 'Event not found in cache. Loading from Database');
500: end if;
501: -- Load event from the database to the object
502: Load_Event(p_event_name, l_event_obj);
503:
504: if (l_event_obj is not null) then
505: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
506: wf_log_pkg.string(wf_log_pkg.level_statement,
507: 'wf.plsql.WF_BES_CACHE.GetEventByName.Set_Cache',
508: 'Setting event {'||p_event_name||'} to cache');
509: end if;
510: Set_Event_Object(p_event_name, l_event_obj);
511: end if;
521: end if;
522:
523: exception
524: when others then
525: wf_core.context('WF_BES_CACHE', 'GetEventByName', p_event_name);
526: raise;
527: end GetEventByName;
528:
529: -- GetSubscriptions
540: l_subs_count number;
541: begin
542: if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
543: wf_log_pkg.string(wf_log_pkg.level_procedure,
544: 'wf.plsql.WF_BES_CACHE.GetSubscriptions.Begin',
545: 'Getting subscriptions for event {'||p_event_name||'}'||
546: ' Source Type {'||p_source_type||'} Source Agt {'||p_source_agent||'}');
547: end if;
548:
558: if (upper(l_event_obj.GetSubsLoaded(p_source_type)) = g_status_no) then
559:
560: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
561: wf_log_pkg.string(wf_log_pkg.level_statement,
562: 'wf.plsql.WF_BES_CACHE.GetSubscriptions.Load_Subs',
563: 'Subscriptions for {'||p_event_name||'} is not already loaded.'||
564: ' Loading from DB for Source Type {'||p_source_type||
565: '} Source Agt {'||p_source_agent||'}');
566: end if;
575: Set_Event_Object(p_event_name, l_event_obj);
576: else
577: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
578: wf_log_pkg.string(wf_log_pkg.level_statement,
579: 'wf.plsql.WF_BES_CACHE.GetSubscriptions.Subs_Loaded',
580: 'Subscriptions for {'||p_event_name||'} is already loaded to cache');
581: end if;
582: end if;
583:
591: return l_event_obj.GetSubscriptionList(p_source_type);
592: end if;
593: exception
594: when others then
595: wf_core.context('WF_BES_CACHE', 'GetSubscriptions', p_event_name, p_source_type);
596: raise;
597: end GetSubscriptions;
598:
599: -- GetSubscriptionByGUID
611: if (p_event_name is null or p_sub_guid is null) then
612: return null;
613: end if;
614:
615: l_event_obj := wf_bes_cache.GetEventByName(p_event_name);
616:
617: if (l_event_obj is null) then
618: return null;
619: end if;
640:
641: return l_event_obj.GetSubscriptionByGUID(p_sub_guid);
642: exception
643: when others then
644: wf_core.context('WF_BES_CACHE', 'GetSubscriptionByGUID', p_event_name, p_sub_guid);
645: raise;
646: end GetSubscriptionByGUID;
647:
648: --
718:
719: if (p_agent_name is not null and p_system_name is not null) then
720: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
721: wf_log_pkg.string(wf_log_pkg.level_statement,
722: 'wf.plsql.WF_BES_CACHE.Load_Agent.Cursor',
723: 'Loading agent by name '||p_agent_name||'+'||p_system_name);
724: end if;
725: open c_get_agent_n(p_agent_name, p_system_name);
726: fetch c_get_agent_n into p_agent_obj.GUID,
739:
740: if (c_get_agent_n%NOTFOUND) then
741: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
742: wf_log_pkg.string(wf_log_pkg.level_statement,
743: 'wf.plsql.WF_BES_CACHE.Load_Agent.Not_Found',
744: 'Agent not found in the database.');
745: end if;
746: -- If agent not found in the set wf_agent_obj to null
747: p_agent_obj := null;
749: close c_get_agent_n;
750: elsif (p_agent_guid is not null) then
751: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
752: wf_log_pkg.string(wf_log_pkg.level_statement,
753: 'wf.plsql.WF_BES_CACHE.Load_Agent.Not_Found',
754: 'Loading agent by GUID '||p_agent_guid);
755: end if;
756: open c_get_agent_g(p_agent_guid);
757: fetch c_get_agent_g into p_agent_obj.GUID,
770:
771: if (c_get_agent_g%NOTFOUND) then
772: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
773: wf_log_pkg.string(wf_log_pkg.level_statement,
774: 'wf.plsql.WF_BES_CACHE.Load_Agent.Not_Found',
775: 'Agent not found in the database');
776: end if;
777: -- If agent not found in the set wf_agent_obj to null
778: p_agent_obj := null;
813: end if;
814:
815: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
816: wf_log_pkg.string(wf_log_pkg.level_statement,
817: 'wf.plsql.WF_BES_CACHE.Load_Agent_QH.Cursor',
818: 'Loading from DB for Queue Handler '||p_agent_qh);
819: end if;
820:
821: open c_get_agent(p_agent_qh, p_direction);
835:
836: if (c_get_agent%NOTFOUND) then
837: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
838: wf_log_pkg.string(wf_log_pkg.level_statement,
839: 'wf.plsql.WF_BES_CACHE.Load_Agent.Not_Found',
840: 'No Agent exists for the given queue handler');
841: end if;
842: -- If agent not found in the set wf_agent_obj to null
843: p_agent_obj := null;
861: l_system_name varchar2(30);
862: begin
863: if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
864: wf_log_pkg.string(wf_log_pkg.level_procedure,
865: 'wf.plsql.WF_BES_CACHE.GetAgentByName.Begin',
866: 'Getting agent details for {'||p_agent_name||
867: '+'||p_system_name||'}');
868: end if;
869:
892: -- the session
893: if (not wf_object_cache.IsCacheCreated(g_Agent_Idx)) then
894: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
895: wf_log_pkg.string(wf_log_pkg.level_statement,
896: 'wf.plsql.WF_BES_CACHE.GetAgentByName.Create_Cache',
897: 'Cache is not created for AGENTS index {'||g_Agent_Idx||'}');
898: end if;
899: wf_object_cache.CreateCache(g_Agent_Idx);
900: SetMetaDataCached(sysdate);
900: SetMetaDataCached(sysdate);
901: else
902: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
903: wf_log_pkg.string(wf_log_pkg.level_statement,
904: 'wf.plsql.WF_BES_CACHE.GetAgentByName.Cache_Get',
905: 'Getting the Agent from Cache');
906: end if;
907: Get_Agent_Object(l_agent_key, l_agent_obj);
908: end if;
911: -- retrieve the details from the database
912: if (l_agent_obj is null) then
913: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
914: wf_log_pkg.string(wf_log_pkg.level_statement,
915: 'wf.plsql.WF_BES_CACHE.GetAgentByName.Load_Agent',
916: 'Agent not found in cache. Loading from Database');
917: end if;
918: -- Load agent from the database to the object
919:
921:
922: if (l_agent_obj is not null) then
923: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
924: wf_log_pkg.string(wf_log_pkg.level_statement,
925: 'wf.plsql.WF_BES_CACHE.GetAgentByName.Set_Cache',
926: 'Setting Agent {'||l_agent_key||'} to cache');
927: end if;
928: Set_Agent_Object(l_agent_key, l_agent_obj);
929: end if;
965: -- check if the Agent cache is created. if created get all agent objects
966: if (not wf_object_cache.IsCacheCreated(g_Agent_Idx)) then
967: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
968: wf_log_pkg.string(wf_log_pkg.level_statement,
969: 'wf.plsql.WF_BES_CACHE.GetAgentByGUID.Create_Cache',
970: 'Cache is not created for AGENTS index {'||g_Agent_Idx||'}');
971: end if;
972: wf_object_cache.CreateCache(g_Agent_Idx);
973: SetMetaDataCached(sysdate);
973: SetMetaDataCached(sysdate);
974: else
975: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
976: wf_log_pkg.string(wf_log_pkg.level_statement,
977: 'wf.plsql.WF_BES_CACHE.GetAgentByGUID.Get_All',
978: 'Getting all cached agent objects');
979: end if;
980: l_all_agents := wf_object_cache.GetAllObjects(g_Agent_Idx);
981: end if;
997:
998: if (l_found) then
999: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
1000: wf_log_pkg.string(wf_log_pkg.level_statement,
1001: 'wf.plsql.WF_BES_CACHE.GetAgentByGUID.Cache_Hit',
1002: 'Agent found in cache for GUID '||p_agent_guid);
1003: end if;
1004: return l_agent_obj;
1005: end if;
1014: l_system_name := l_agent_obj.SYSTEM_NAME;
1015: l_agent_key := l_agent_name||l_system_name;
1016: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
1017: wf_log_pkg.string(wf_log_pkg.level_statement,
1018: 'wf.plsql.WF_BES_CACHE.GetAgentByGUID.Set_Object',
1019: 'Agent loaded from Database for GUID '||p_agent_guid||
1020: '. Setting to cache for '||l_agent_key);
1021: end if;
1022: Set_Agent_Object(l_agent_key, l_agent_obj);
1024: return l_agent_obj;
1025:
1026: exception
1027: when others then
1028: wf_core.context('WF_BES_CACHE', 'GetAgentByGUID', p_agent_guid);
1029: raise;
1030: end GetAgentByGUID;
1031:
1032: -- GetAgentByQH
1062: -- check if the Agent cache is created. if created get all agent objects
1063: if (not wf_object_cache.IsCacheCreated(g_Agent_Idx)) then
1064: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
1065: wf_log_pkg.string(wf_log_pkg.level_statement,
1066: 'wf.plsql.WF_BES_CACHE.GetAgentByQH.Create_Cache',
1067: 'Cache is not created for AGENTS index {'||g_Agent_Idx||'}');
1068: end if;
1069: wf_object_cache.CreateCache(g_Agent_Idx);
1070: SetMetaDataCached(sysdate);
1070: SetMetaDataCached(sysdate);
1071: else
1072: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
1073: wf_log_pkg.string(wf_log_pkg.level_statement,
1074: 'wf.plsql.WF_BES_CACHE.GetAgentByQH.Get_All',
1075: 'Getting all cached agent objects');
1076: end if;
1077: l_all_agents := wf_object_cache.GetAllObjects(g_Agent_Idx);
1078: end if;
1095:
1096: if (l_found) then
1097: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
1098: wf_log_pkg.string(wf_log_pkg.level_statement,
1099: 'wf.plsql.WF_BES_CACHE.GetAgentByQH.Cache_Hit',
1100: 'Agent found in cache for Queue Handler '||p_agent_qh);
1101: end if;
1102: return l_agent_obj;
1103: end if;
1112: l_system_name := l_agent_obj.SYSTEM_NAME;
1113: l_agent_key := l_agent_name||l_system_name;
1114: if (wf_log_pkg.level_statement >= fnd_log.g_current_runtime_level) then
1115: wf_log_pkg.string(wf_log_pkg.level_statement,
1116: 'wf.plsql.WF_BES_CACHE.GetAgentByQH.Set_Object',
1117: 'Agent loaded from Database for Queue Hander '||p_agent_qh||
1118: '. Setting to cache for '||l_agent_key);
1119: end if;
1120: Set_Agent_Object(l_agent_key, l_agent_obj);
1122: return l_agent_obj;
1123:
1124: exception
1125: when others then
1126: wf_core.context('WF_BES_CACHE', 'GetAgentByQH', p_agent_qh, p_direction);
1127: raise;
1128: end GetAgentByQH;
1129:
1130: --
1140: begin
1141: return null;
1142: end GetSystemByName;
1143:
1144: end WF_BES_CACHE;