[Home] [Help]
PACKAGE BODY: APPS.WF_ENTITY_MGR
Source
1 package body WF_ENTITY_MGR as
2 /* $Header: WFEMGRB.pls 120.3 2006/04/04 03:24:06 anachatt ship $ */
3 ------------------------------------------------------------------------------
4 /*
5 ** InitCache - <private> Creates the 'CACHE_CHANGED' attribute for a specific
6 ** entity_type/entity_key
7 */
8 procedure InitCache(p_entity_type in varchar2,
9 p_entity_key_value in varchar2) is
10 pragma autonomous_transaction;
11 begin
12 insert into wf_attribute_cache (
13 entity_type,
14 entity_key_value,
15 attribute_name,
16 attribute_value,
17 last_update_date,
18 change_number)
19 values
20 (p_entity_type,
21 upper(p_entity_key_value),
22 'CACHE_CHANGED',
23 'PENDING',
24 sysdate,
25 NULL);
26
27 --We commit the transaction so all sessions can see the attribute.
28 commit;
29 exception
30 when DUP_VAL_ON_INDEX then
31 --This can occur from race condition (two sessions tried to update at
32 --same time).
33 null;
34 end;
35
36 /*
37 ** put - <private> construct cache rows
38 */
39 PROCEDURE put(p_entity_type in varchar2,
40 p_entity_key_value in varchar2,
41 p_att in varchar2,
42 p_value in varchar2,
43 p_change_number in number ) is
44
45 l_cacheLocked boolean;
46
47 begin
48
49
50 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
51
52 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
53 'wf.plsql.WF_ENTITY_MGR.put',
54 'Begin put('||p_entity_type||', '||
55 p_entity_key_value||', '||p_att||', '||
56 p_value||', '||p_change_number||')');
57 end if;
58
59 if (p_value = '*UNKNOWN*') then
60 return;
61 elsif (p_att <> 'CACHE_CHANGED') then
62 --First lock the cache or call InitCache() if the attribute
63 --does not exist..
64 l_cacheLocked := FALSE;
65 while not (l_cacheLocked) loop
66 update wf_attribute_cache
67 set attribute_value = 'YES'
68 where entity_type = p_entity_type
69 and entity_key_value = upper(p_entity_key_value)
70 and attribute_name = 'CACHE_CHANGED';
71
72 if sql%notfound then
73 WF_ENTITY_MGR.InitCache(put.p_entity_type,
74 put.p_entity_key_value);
75 else
76 --We locked the cache so we can exit the loop.
77 l_cacheLocked := TRUE;
78 end if;
79 end loop;
80 end if;
81
82 --We acquired a lock on the entity_type/entity_key so we can update/create
83 --Attributes.
84 update wf_attribute_cache
85 set attribute_value = nvl(p_value, '*NULL*'),
86 last_update_date = sysdate,
87 change_number = nvl(p_change_number, change_number)
88 where entity_type = p_entity_type
89 and entity_key_value = upper(p_entity_key_value)
90 and attribute_name = upper(p_att);
91
92 --No need to worry about race condition here because we have a lock on the
93 --entity_type/entity_key.
94 if SQL%notfound then
95 insert into wf_attribute_cache (
96 entity_type,
97 entity_key_value,
98 attribute_name,
99 attribute_value,
100 last_update_date,
101 change_number)
102 values
103 (p_entity_type,
104 upper(p_entity_key_value),
105 upper(p_att),
106 nvl(p_value, '*NULL*'),
107 sysdate,
108 p_change_number);
109 end if;
110
111 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
112
113 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
114 'wf.plsql.WF_ENTITY_MGR.put',
115 'End put('||p_entity_type||', '||
116 p_entity_key_value||', '||p_att||', '||
117 p_value||', '||p_change_number||')');
118 end if;
119
120 end;
121 ------------------------------------------------------------------------------
122 /*
123 ** process_changes - <described in WFEMGRS.pls>
124 */
125 PROCEDURE process_changes(p_entity_type in varchar2,
126 p_entity_key_value in varchar2,
127 p_change_source in varchar2,
128 p_change_type in varchar2 ,
129 p_event_name in varchar2 )
130 is
131 my_user_base varchar2(256);
132 my_ent_type varchar2(50) := upper(p_entity_type);
133 my_parms wf_parameter_list_t;
134 my_key_value varchar2(256);
135 begin
136
137 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
138
139 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
140 'wf.plsql.WF_ENTITY_MGR.process_changes',
141 'Begin process_changes('||p_entity_type||', '||
142 p_entity_key_value||', '||p_change_source||', '||
143 p_change_type||', '||p_event_name||')');
144 end if;
145
146 if (wf_entity_mgr.get_attribute_value(my_ent_type, p_entity_key_value,
147 'CACHE_CHANGED') = 'YES') then
148 --
149 -- Tell everybody about the change by raising the appropriate event
150 --
151 -- First, mark this entity in the cache as unchanged so we can pick up
152 -- any actual subsequent changes
153 --
154 wf_entity_mgr.put_attribute_value(my_ent_type, p_entity_key_value,
155 'CACHE_CHANGED', 'NO');
156 wf_event.AddParameterToList('CHANGE_SOURCE', p_change_source, my_parms);
157 wf_event.AddParameterToList('CHANGE_TYPE', p_change_type, my_parms);
158
159 if (p_event_name is null) then
160 wf_event.raise('oracle.apps.global.'||lower(my_ent_type)||'.change',
161 upper(p_entity_key_value), null, my_parms);
162 else
163 wf_event.raise(p_event_name, upper(p_entity_key_value), null, my_parms);
164 end if;
165 end if;
166
167 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
168
169 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
170 'wf.plsql.WF_ENTITY_MGR.process_changes',
171 'End process_changes('||p_entity_type||', '||
172 p_entity_key_value||', '||p_change_source||', '||
173 p_change_type||', '||p_event_name||')');
174 end if;
175
176 end;
177 ------------------------------------------------------------------------------
178 /*
179 ** get_attribute_value - <described in WFEMGRS.pls>
180 */
181 FUNCTION get_attribute_value(p_entity_type in varchar2,
182 p_entity_key_value in varchar2,
183 p_attribute in varchar2) return varchar2
184 is
185 my_att_val varchar2(4000);
186 begin
187
188 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
189
190 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
191 'wf.plsql.WF_ENTITY_MGR. get_attribute_value',
192 'Begin get_attribute_value('||p_entity_type||', '||
193 p_entity_key_value||', '||
194 p_attribute||')');
195 end if;
196
197 select attribute_value into my_att_val
198 from wf_attribute_cache
199 where entity_type = upper(p_entity_type)
200 and entity_key_value = upper(p_entity_key_value)
201 and attribute_name = upper(p_attribute);
202
203 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
204
205 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
206 'wf.plsql.WF_ENTITY_MGR. get_attribute_value',
207 'End get_attribute_value('||p_entity_type||', '||
208 p_entity_key_value||', '||
209 p_attribute||')');
210 end if;
211
212 return my_att_val;
213 exception when no_data_found then
214 if (wf_log_pkg.level_unexpected >= fnd_log.g_current_runtime_level) then
215 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_UNEXPECTED,
216 'wf.plsql.WF_ENTITY_MGR. get_attribute_value',
217 'Exception: '||sqlerrm);
218 end if;
219
220 return '*UNKNOWN*';
221 end;
222 ------------------------------------------------------------------------------
223 /*
224 ** put_attribute_value - <described in WFEMGRS.pls>
225 */
226 PROCEDURE put_attribute_value(p_entity_type in varchar2,
227 p_entity_key_value in varchar2,
228 p_attribute in varchar2,
229 p_attribute_value in varchar2)
230 is
231 old_att_val varchar2(4000);
232 my_ent_type varchar2(50) := upper(p_entity_type);
233 begin
234
235 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
236
237 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
238 'wf.plsql.WF_ENTITY_MGR. put_attribute_value',
239 'Begin put_attribute_value('||p_entity_type||', '||
240 p_entity_key_value||', '||
241 p_attribute||', '||p_attribute_value||')');
242 end if;
243
244 if (p_attribute = 'CACHE_CHANGED') then
245 wf_entity_mgr.put(my_ent_type,
246 p_entity_key_value,
247 'CACHE_CHANGED',
248 p_attribute_value,
249 NULL);
250
251 elsif (p_attribute_value = '*UNKNOWN*') then
252 null;
253
254 elsif (p_attribute_value is null) then
255 null; -- means "do not update" like for fndload --
256 -- if you want to null out a value, use *NULL* --
257 else
258 old_att_val := wf_entity_mgr.get_attribute_value(my_ent_type,
259 p_entity_key_value,
260 p_attribute);
261 if (p_attribute_value <> old_att_val) then
262 wf_entity_mgr.put(my_ent_type,
263 p_entity_key_value,
264 p_attribute,
265 p_attribute_value,
266 NULL);
267 end if;
268 end if;
269 if (wf_log_pkg.level_procedure >= fnd_log.g_current_runtime_level) then
270
271 WF_LOG_PKG.String(WF_LOG_PKG.LEVEL_PROCEDURE,
272 'wf.plsql.WF_ENTITY_MGR. put_attribute_value',
273 'End put_attribute_value('||p_entity_type||', '||
274 p_entity_key_value||', '||
275 p_attribute||', '||p_attribute_value||')');
276
277 end if;
278
279 end;
280 ------------------------------------------------------------------------------
281 /*
282 ** flush_cache - <described in WFEMGRS.pls>
283 */
284 PROCEDURE flush_cache(p_entity_type in varchar2 ,
285 p_entity_key_value in varchar2 )
286 is pragma autonomous_transaction;
287 begin
288 if (p_entity_type = '*ALL*') then
289 execute immediate 'truncate table wf_attribute_cache';
290 elsif ((p_entity_type is NOT NULL) and (p_entity_key_value is NOT NULL)) then
291 delete from wf_attribute_cache
292 where entity_type = upper(p_entity_type)
293 and entity_key_value = upper(p_entity_key_value);
294 else
295 delete from wf_attribute_cache
296 where ((entity_type is NULL) or (entity_type = upper(p_entity_type)))
297 and ((entity_key_value is NULL) or
298 (entity_key_value = upper(p_entity_key_value)));
299 end if;
300
301 commit;
302 exception
303 when others then null;
304 end;
305 ------------------------------------------------------------------------------
306 /*
307 ** get_entity_type - <described in WFEMGRS.pls>
308 */
309 FUNCTION get_entity_type(p_event_name in varchar2) return varchar2 is
310 a number := instr(p_event_name,'.',-1,2)+1;
311 b number := instr(p_event_name,'.',-1) - a;
312 begin
313 return upper( substr(p_event_name, a, b) );
314 end;
315 ------------------------------------------------------------------------------
316 /*
317 ** gen_xml_payload - <described in WFEMGRS.pls>
318 */
319 FUNCTION gen_xml_payload(p_event_name in varchar2,
320 p_event_key in varchar2) return clob
321 is
322 my_clob clob;
323 my_ent_type varchar2(50) := wf_entity_mgr.get_entity_type(p_event_name);
324 found boolean := FALSE;
325
326 l_doc xmldom.DOMDocument;
327 l_root xmldom.DOMNode;
328 l_node xmldom.DOMNode;
329
330 cursor attribute_data is
331 select attribute_name aname,
332 attribute_value avalue
333 from wf_attribute_cache
334 where entity_type = my_ent_type
335 and entity_key_value = upper(p_event_key)
336 and attribute_name <> 'CACHE_CHANGED';
337
338 begin
339 l_doc := xmldom.newDOMDocument;
340 l_root := xmldom.makeNode(l_doc);
341 l_root := wf_event_xml.newtag(l_doc, l_root, my_ent_type);
342
343 for atts in attribute_data loop
344 l_node := wf_event_xml.newtag(l_doc, l_root, atts.aname, atts.avalue);
345 found := TRUE;
346 end loop;
347
348 if (found) then
349 dbms_lob.createtemporary(my_clob, FALSE);
350 xmldom.writeToClob(l_root, my_clob);
351 return my_clob;
352 else
353 return null;
354 end if;
355 end;
356 ---------------------------------------------------------------------------
357 /*
358 ** isChanged - <Described in WFEMGRS.pls>
359 */
360 FUNCTION isChanged(p_new_val in varchar2,
361 p_old_val in varchar2) return boolean is
362 retval boolean := FALSE;
363 begin
364 if (p_new_val = '*UNKNOWN*') then
365 retval := FALSE;
366 elsif (p_new_val <> p_old_val) then
367 retval := TRUE;
368 end if;
369
370 return retval;
371 end;
372
373 ------------------------------------------------------------------------------
374 end WF_ENTITY_MGR;