DBA Data[Home] [Help]

PACKAGE BODY: APPS.FND_OAM_UMS_LOADER

Source


1 package body fnd_oam_ums_loader as
2 /* $Header: AFOAMUMSLDB.pls 120.1.12020000.2 2012/07/17 21:50:47 tshort ship $ */
3 
4 -- ==================================================
5 -- Constants and Types.
6 -- ==================================================
7 
8 G_STD_DATE_MASK constant varchar2(100) := 'YYYY/MM/DD HH24:MI:SS';
9 
10 DEBUG_OFF       constant varchar2(10) := 'N';
11 DEBUG_ON        constant varchar2(10) := 'Y';
12 DEBUG_STATS     constant varchar2(10) := 'S';
13 DEBUG_ABORT     constant varchar2(10) := 'A';
14 
15 g_debug_flag    varchar2(10);
16 g_newline       varchar2(10);
17 g_default_date  date;
18 
19 --
20 -- lock life and wait times in terms of seconds
21 --
22 g_lock_lifetime integer := 1*24*60*60; -- one day
23 g_lock_waittime integer := 5*60;       -- five minutes
24 
25 g_bugfix_guid fnd_ums_bugfixes.bugfix_guid%type;
26 
27 -- Prereqs/Includes/Links data level
28 
29 PIL_LEVEL_NONE             constant integer := 0;
30 PIL_LEVEL_PREREQS_INCLUDES constant integer := 1;
31 PIL_LEVEL_LINKS            constant integer := 2;
32 
33 -- Unknown data
34 
35 NOT_AVAILABLE constant varchar2(10) := 'N/A';
36 
37 -- UMS tables will be analyzed if
38 --  - analyze hasn't been run for more than TABLE_ANALYZE_PERIOD days or
39 --  - percentage of row count change is more than TABLE_ANALYZE_PERCENTAGE
40 
41 TABLE_ANALYZE_PERIOD     constant number := 28; -- 28 days (4 weeks)
42 TABLE_ANALYZE_PERCENTAGE constant number := 5;  -- 5%
43 
44 -- Error codes
45 
46 ERROR_UNKNOWN_DOWNLOAD_MODE  constant number := -20001;
47 ERROR_UNKNOWN_UPLOAD_PHASE   constant number := -20002;
48 ERROR_UNABLE_TO_LOCK         constant number := -20003;
49 ERROR_ABORT                  constant number := -20100;
50 
51 -- Error Messages
52 
53 MSG_ABORT_OLDER constant varchar2(100) := 'Since file data is older, aborted upload of bug ';
54 MSG_ABORT_LEVEL constant varchar2(100) := 'Since database data is at least as complete as file data, aborted upload of bug ';
55 
56 type forced_bugfix_lookup is table of varchar2(1) index by binary_integer;
57 
58 type data_contents is record
59    (download_mode          varchar2(30),
60     last_definition_date   date,
61     last_update_date       date,
62     has_bugfix_replacement boolean,
63     pil_level              integer,
64     has_files              boolean,
65     download_code          varchar2(30));
66 
67 type upload_controller is record
68    (upload_bugfix_replacement     boolean,
69     upload_prereqs_includes_links boolean,
70     upload_files                  boolean);
71 
72 type row_counts is record
73    (bugfixes              number,
74     bugfix_relationships  number,
75     files                 number,
76     file_versions         number,
77     bugfix_file_versions  number);
78 
79 type ums_table is record
80    (owner_name     varchar2(30),
81     table_name     varchar2(30),
82     last_analyzed  date,
83     num_rows       number,
84     delta_num_rows number);
85 
86 type ums_tables is table of ums_table index by binary_integer;
87 
88 g_uc upload_controller;
89 g_rc row_counts;
90 g_forced_bugfixes forced_bugfix_lookup;
91 
92 --------------------------------------------------------------------------------
93 procedure debug(p_debug in varchar2)
94 is
95 begin
96    if (g_debug_flag <> DEBUG_OFF) then
97       fnd_file.put_line(fnd_file.Log, p_debug);
98    end if;
99 exception
100    when others then
101       null;
102 end debug;
103 
104 --------------------------------------------------------------------------------
105 procedure debug(p_func_name in varchar2,
106                 p_debug     in varchar2)
107 is
108 begin
109    if (g_debug_flag <> DEBUG_OFF) then
110       fnd_file.put_line
111          (fnd_file.Log,
112          'FUNCTION:' || p_func_name        || g_newline ||
113          'DEBUG   :' || p_debug            || g_newline ||
114          'SYSDATE :' || To_char(Sysdate, G_STD_DATE_MASK));
115    end if;
116 exception
117    when others then
118       null;
119 end debug;
120 
121 --------------------------------------------------------------------------------
122 procedure set_debugging(p_debug_flag in varchar2)
123 is
124    l_old_debug_flag varchar2(10);
125 begin
126    l_old_debug_flag := g_debug_flag;
127    g_debug_flag := Nvl(Upper(Substr(p_debug_flag, 1, 1)), DEBUG_OFF);
128    if ((l_old_debug_flag = DEBUG_OFF) and (g_debug_flag = DEBUG_ON)) then
129       debug(' ');
130       debug('Update Management System Loader Debugger');
131       debug(rpad('-', 77, '-'));
132       debug('Sysdate = ' || to_char(sysdate, G_STD_DATE_MASK));
133       debug('Legend: DM: Download Mode. LDD: Last definition Date. LUD: Last Update Date.');
134       debug(' ');
135    end if;
136 exception
137    when others then
138       null;
139 end set_debugging;
140 
141 --------------------------------------------------------------------------------
142 -- Locks the entity before insert.
143 -- p_entity_name - name of the entity
144 -- p_key1..3 - primary keys of the entity
145 --------------------------------------------------------------------------------
146 PROCEDURE lock_entity(p_entity_name in varchar2,
147                       p_key1        in varchar2 default null,
148                       p_key2        in varchar2 default null,
149                       p_key3        in varchar2 default null)
150 is
151    l_entity      varchar2(32000);
152    l_hash_value  number;
153    l_lock_name   varchar2(128);
154    l_lock_handle varchar2(128);
155    l_lock_status integer;
156 begin
157    -- Get a unique lock name
158 
159    l_entity := 'FND.UMS.' || p_entity_name || '.' ||
160                p_key1 || '.' || p_key2 || '.' || p_key3;
161 
162    if (lengthb(l_entity) > 128) then
163       -- lockname cannot be longer than 128 bytes.
164       -- Get a hash value between 1 and 65536.
165       l_hash_value := dbms_utility.get_hash_value(l_entity, 1, 65536);
166       l_lock_name := 'FND.UMS.HASH.' || p_entity_name || '.' || l_hash_value;
167       l_lock_name := substrb(l_lock_name, 1, 128);
168    else
169       l_lock_name := l_entity;
170    end if;
171 
172    dbms_lock.allocate_unique(lockname        => l_lock_name,
173                              lockhandle      => l_lock_handle,
174                              expiration_secs => g_lock_lifetime);
175 
176    l_lock_status := dbms_lock.request(lockhandle        => l_lock_handle,
177                                       lockmode          => dbms_lock.x_mode,
178                                       timeout           => g_lock_waittime,
179                                       release_on_commit => TRUE);
180 
181    if (l_lock_status <> 0) then
182       raise_application_error(ERROR_UNABLE_TO_LOCK,
183                               'Unable to lock entity : ' || l_entity ||
184                               '. dbms_lock.request(' || l_lock_name ||
185                               ') returned : ' || l_lock_status);
186    end if;
187 end lock_entity;
188 
189 --------------------------------------------------------------------------------
190 -- Analyzes table stats iff
191 --  - analyze hasn't been run for more than TABLE_ANALYZE_PERIOD of time
192 --  - percentage of row count change is more than TABLE_ANALYZE_PERCENTAGE
193 --
194 -- p_ums_table - ums table details
195 --------------------------------------------------------------------------------
196 procedure analyze_table(p_ums_table in ums_table)
197 is
198    l_analyze_needed boolean;
199 begin
200    if (g_debug_flag = DEBUG_STATS) then
201       debug('Owner.Table Name        : ' || p_ums_table.owner_name || '.' || p_ums_table.table_name);
202       debug('Number of Data Changes  : ' || p_ums_table.delta_num_rows);
203       debug('Last Analyzed Row Count : ' || p_ums_table.num_rows);
204       debug('Last Analyzed Date      : ' || to_char(p_ums_table.last_analyzed, G_STD_DATE_MASK));
205    end if;
206 
207    l_analyze_needed := false;
208 
209    if ((p_ums_table.last_analyzed is null) or
210        (sysdate - p_ums_table.last_analyzed > TABLE_ANALYZE_PERIOD)) then
211 
212       if (g_debug_flag = DEBUG_STATS) then
213          debug('Table has not been analyzed for more than TABLE_ANALYZE_PERIOD of ' ||
214             TABLE_ANALYZE_PERIOD || ' days');
215       end if;
216 
217       l_analyze_needed := true;
218 
219    elsif ((p_ums_table.num_rows is null) or
220           (p_ums_table.delta_num_rows > p_ums_table.num_rows * TABLE_ANALYZE_PERCENTAGE / 100)) then
221 
222       if (g_debug_flag = DEBUG_STATS) then
223          debug(p_ums_table.delta_num_rows || ' data changes exceeds the TABLE_ANALYZE_PERCENTAGE of ' ||
224             TABLE_ANALYZE_PERCENTAGE || '%');
225       end if;
226 
227       l_analyze_needed := true;
228 
229    end if;
230 
231    if (l_analyze_needed) then
232 
233       fnd_stats.gather_table_stats(p_ums_table.owner_name, p_ums_table.table_name);
234 
235       if (g_debug_flag = DEBUG_STATS) then
236          debug('Statistics were successfully gathered.');
237          debug(' ');
238       end if;
239 
240    else
241       if (g_debug_flag = DEBUG_STATS) then
242          debug('There is no need to gather statistics.');
243          debug(' ');
244       end if;
245    end if;
246 
247 exception
248    when others then
249       if (g_debug_flag = DEBUG_STATS) then
250          debug('analyze_table(''' ||
251             p_ums_table.owner_name || ''', ''' || p_ums_table.table_name || ''') failed.');
252          debug('SQLERRM : ' || sqlerrm);
253       end if;
254 end analyze_table;
255 
256 --------------------------------------------------------------------------------
257 -- Gets UMS table details from dba_tables.
258 --------------------------------------------------------------------------------
259 procedure add_table_details(px_ums_tables      in out nocopy ums_tables,
260                             px_ums_table_count in out nocopy binary_integer,
261                             p_table_name       in varchar2,
262                             p_delta_num_rows   in number)
263 is
264    cursor l_applsys_schemas is
265       select fou.oracle_username
266         from fnd_oracle_userid fou,
267              fnd_product_installations fpi
268        where fou.oracle_id = fpi.oracle_id
269          and fpi.application_id = 0;
270 
271    cursor l_ums_tables(p_owner in varchar2, p_table_name in varchar2) is
272       select owner, table_name, last_analyzed, num_rows
273         from dba_tables
274        where owner = p_owner
275          and table_name = p_table_name;
276 begin
277    for l_applsys_schema in l_applsys_schemas loop
278       for l_ums_table in l_ums_tables(l_applsys_schema.oracle_username, p_table_name) loop
279 
280          px_ums_tables(px_ums_table_count).owner_name     := l_ums_table.owner;
281          px_ums_tables(px_ums_table_count).table_name     := l_ums_table.table_name;
282          px_ums_tables(px_ums_table_count).last_analyzed  := l_ums_table.last_analyzed;
283          px_ums_tables(px_ums_table_count).num_rows       := l_ums_table.num_rows;
284          px_ums_tables(px_ums_table_count).delta_num_rows := p_delta_num_rows;
285 
286          px_ums_table_count := px_ums_table_count + 1;
287 
288       end loop;
289    end loop;
290 exception
291    when others then
292       if (g_debug_flag = DEBUG_STATS) then
293          debug('Unable to get table details for ' || p_table_name || '.');
294          debug('SQLERRM : ' || sqlerrm);
295       end if;
296 end add_table_details;
297 
298 --------------------------------------------------------------------------------
299 -- Analyzes UMS table stats
300 --------------------------------------------------------------------------------
301 procedure analyze_ums_tables
302 is
303    l_ums_tables      ums_tables;
304    l_ums_table_count binary_integer;
305    l_debug_flag      varchar2(10);
306 begin
307    l_debug_flag := g_debug_flag;
308    g_debug_flag := DEBUG_STATS;
309 
310    l_ums_table_count := 0;
311 
312    add_table_details(l_ums_tables, l_ums_table_count, 'FND_UMS_BUGFIXES',             g_rc.bugfixes);
313    add_table_details(l_ums_tables, l_ums_table_count, 'FND_UMS_BUGFIX_RELATIONSHIPS', g_rc.bugfix_relationships);
314    add_table_details(l_ums_tables, l_ums_table_count, 'FND_UMS_FILES',                g_rc.files);
315    add_table_details(l_ums_tables, l_ums_table_count, 'FND_UMS_FILE_VERSIONS',        g_rc.file_versions);
316    add_table_details(l_ums_tables, l_ums_table_count, 'FND_UMS_BUGFIX_FILE_VERSIONS', g_rc.bugfix_file_versions);
317 
318    if (g_debug_flag = DEBUG_STATS) then
319       debug(' ');
320       debug('Gathering Statistics for ' || l_ums_table_count || ' UMS table(s):');
321       debug(rpad('-', 50, '-'));
322    end if;
323 
324    for i in 0 .. l_ums_table_count - 1 loop
325       analyze_table(l_ums_tables(i));
326    end loop;
327 
328    g_debug_flag := l_debug_flag;
329 exception
330    when others then
331       g_debug_flag := l_debug_flag;
332       null;
333 end analyze_ums_tables;
334 
335 ------------------------------------------------------------------------
336 -- Maps download_mode to data_contents.
337 ------------------------------------------------------------------------
338 function get_data_contents(p_download_mode        in varchar2,
339                            p_last_definition_date in date,
340                            p_last_update_date     in date)
341 return data_contents
342 is
343    l_data_contents data_contents;
344 begin
345    l_data_contents.download_mode := p_download_mode;
346    l_data_contents.last_definition_date := p_last_definition_date;
347    l_data_contents.last_update_date := p_last_update_date;
348 
349    l_data_contents.has_bugfix_replacement := false;
350    l_data_contents.pil_level := PIL_LEVEL_NONE;
351    l_data_contents.has_files := false;
352    l_data_contents.download_code := '';
353 
354    if (p_download_mode = DL_MODE_NONE) then
355       l_data_contents.download_code := '';
356 
357    elsif (p_download_mode = DL_MODE_FILES_ONLY) then
358       l_data_contents.download_code := 'F';
359 
360       l_data_contents.has_files := true;
361 
362    elsif (p_download_mode = DL_MODE_REPLACEMENTS_ONLY) then
363       l_data_contents.download_code := 'BR';
364       l_data_contents.has_bugfix_replacement := true;
365 
366    elsif (p_download_mode = DL_MODE_REPLACEMENTS_FILES) then
367       l_data_contents.download_code := 'BRF';
368       l_data_contents.has_bugfix_replacement := true;
369 
370       l_data_contents.has_files := true;
371 
372    elsif (p_download_mode = DL_MODE_PREREQS_ONLY) then
373       l_data_contents.download_code := 'BRP';
374       l_data_contents.has_bugfix_replacement := true;
375 
376       l_data_contents.pil_level := PIL_LEVEL_PREREQS_INCLUDES;
377 
378    elsif (p_download_mode = DL_MODE_PREREQS_FILES) then
379       l_data_contents.download_code := 'BRPF';
380       l_data_contents.has_bugfix_replacement := true;
381 
382       l_data_contents.pil_level := PIL_LEVEL_PREREQS_INCLUDES;
383       l_data_contents.has_files := true;
384 
385    elsif (p_download_mode = DL_MODE_LINKS_ONLY) then
386       l_data_contents.download_code := 'BRPL';
387       l_data_contents.has_bugfix_replacement := true;
388 
389       l_data_contents.pil_level := PIL_LEVEL_LINKS;
390 
391    elsif (p_download_mode = DL_MODE_LINKS_FILES) then
392       l_data_contents.download_code := 'BRPLF';
393       l_data_contents.has_bugfix_replacement := true;
394 
395       l_data_contents.pil_level := PIL_LEVEL_LINKS;
396       l_data_contents.has_files := true;
397 
398    else
399       raise_application_error(ERROR_UNKNOWN_DOWNLOAD_MODE,
400          'Unknown DOWNLOAD_MODE: ' || p_download_mode);
401 
402    end if;
403 
404    return l_data_contents;
405 end get_data_contents;
406 
407 ------------------------------------------------------------------------
408 -- Drives download_mode from the has_ flags.
409 ------------------------------------------------------------------------
410 procedure derive_download_mode(px_data_contents in out nocopy data_contents)
411 is
412    l_download_mode varchar2(30);
413    l_download_code varchar2(30);
414 begin
415    l_download_mode := DL_MODE_NONE;
416    l_download_code := '';
417 
418    if (px_data_contents.has_bugfix_replacement) then
419       l_download_mode := DL_MODE_REPLACEMENTS_ONLY;
420       l_download_code := 'BR';
421 
422       if (px_data_contents.pil_level = PIL_LEVEL_PREREQS_INCLUDES) then
423          l_download_mode := DL_MODE_PREREQS_ONLY;
424          l_download_code := 'BRP';
425 
426          if (px_data_contents.has_files) then
427             l_download_mode := DL_MODE_PREREQS_FILES;
428             l_download_code := 'BRPF';
429          end if;
430 
431       elsif (px_data_contents.pil_level = PIL_LEVEL_LINKS) then
432          l_download_mode := DL_MODE_LINKS_ONLY;
433          l_download_code := 'BRPL';
434 
435          if (px_data_contents.has_files) then
436             l_download_mode := DL_MODE_LINKS_FILES;
437             l_download_code := 'BRPLF';
438          end if;
439 
440       elsif (px_data_contents.has_files) then
441          l_download_mode := DL_MODE_REPLACEMENTS_FILES;
442          l_download_code := 'BRF';
443       end if;
444 
445    elsif (px_data_contents.has_files) then
446       l_download_mode := DL_MODE_FILES_ONLY;
447       l_download_code := 'F';
448    end if;
449 
450    px_data_contents.download_mode := l_download_mode;
451    px_data_contents.download_code := l_download_code;
452 
453 end derive_download_mode;
454 
455 procedure debug_up_fnd_ums_bugfix
456   (p_release_name           in varchar2,
457    p_bug_number             in varchar2,
458    l_forced                 in boolean,
459    l_file_dc                in data_contents,
460    l_forced_db_dc           in data_contents,
461    l_db_dc                  in data_contents,
462    l_final_dc               in data_contents)
463 is
464    l_debug varchar2(32000);
465 begin
466 
467    if (g_debug_flag = DEBUG_ON) then
468       l_debug := 'Release Name: ' || p_release_name || ', ' ||
469 		 'Bug Number: ' || p_bug_number;
470 
471       if (l_forced) then
472 	 l_debug := l_debug || '   CUSTOM_MODE = FORCE';
473       end if;
474 
475       debug(l_debug);
476 
477       -- Print Download Mode details.
478 
479       l_debug := '  ' || rpad('File DM:', 10) ||
480 		 rpad(l_file_dc.download_mode || '(' || l_file_dc.download_code || ')', 24);
481 
482       l_debug := l_debug || '   ' || rpad('DB DM:', 8) ||
483 		 rpad(l_db_dc.download_mode || '(' || l_db_dc.download_code || ')', 24);
484 
485       if (l_forced) then
486 	 l_debug := l_debug || ' <- ' || rpad('Old DB DM:', 12) ||
487 		    rpad(l_forced_db_dc.download_mode || '(' || l_forced_db_dc.download_code || ')', 24);
488       end if;
489 
490       debug(l_debug);
491 
492       -- Print Last Definition Date details.
493 
494       l_debug := '  ' || rpad('File LDD:', 10) ||
495 		 rpad(to_char(l_file_dc.last_definition_date, G_STD_DATE_MASK), 24);
496 
497       if (l_file_dc.last_definition_date > l_db_dc.last_definition_date) then
498 	 l_debug := l_debug || ' > ';
499       elsif (l_file_dc.last_definition_date = l_db_dc.last_definition_date) then
500 	 l_debug := l_debug || ' = ';
501       else
502 	 l_debug := l_debug || ' < ';
503       end if;
504 
505       l_debug := l_debug || rpad('DB LDD:', 8) ||
506 		 rpad(to_char(l_db_dc.last_definition_date, G_STD_DATE_MASK), 24);
507 
508       if (l_forced) then
509 	 l_debug := l_debug || ' <- ' || rpad('Old DB LDD:', 12) ||
510 		    rpad(to_char(l_forced_db_dc.last_definition_date, G_STD_DATE_MASK), 24);
511       end if;
512 
513       debug(l_debug);
514 
515       -- Print Last Update Date details.
516 
517       l_debug := '  ' || rpad('File LUD:', 10) ||
518 		 rpad(to_char(l_file_dc.last_update_date, G_STD_DATE_MASK), 24);
519 
520       if (l_file_dc.last_update_date > l_db_dc.last_update_date) then
521 	 l_debug := l_debug || ' > ';
522       elsif (l_file_dc.last_update_date = l_db_dc.last_update_date) then
523 	 l_debug := l_debug || ' = ';
524       else
525 	 l_debug := l_debug || ' < ';
526       end if;
527 
528       l_debug := l_debug || rpad('DB LUD:', 8) ||
529 		 rpad(to_char(l_db_dc.last_update_date, G_STD_DATE_MASK), 24);
530 
531       if (l_forced) then
532 	 l_debug := l_debug || ' <- ' || rpad('Old DB LUD:', 12) ||
533 		    rpad(to_char(l_forced_db_dc.last_update_date, G_STD_DATE_MASK), 24);
534       end if;
535 
536       debug(l_debug);
537       debug(rpad('  ', 80, '-'));
538 
539       -- Print the upload flags.
540 
541       if (g_uc.upload_bugfix_replacement) then
542 	 l_debug := '  up_bugfix_replacement: Y, ';
543       else
544 	 l_debug := '  up_bugfix_replacement: N, ';
545       end if;
546 
547       if (g_uc.upload_prereqs_includes_links) then
548 	 l_debug := l_debug || 'up_prereqs_includes_links: Y, ';
549       else
550 	 l_debug := l_debug || 'up_prereqs_includes_links: N, ';
551       end if;
552 
553       if (g_uc.upload_files) then
554 	 l_debug := l_debug || 'up_files: Y';
555       else
556 	 l_debug := l_debug || 'up_files: N';
557       end if;
558 
559       debug(l_debug);
560 
561       -- Report final result.
562 
563       l_debug := '  ' || rpad('Final DM:', 10) ||
564 		 rpad(l_final_dc.download_mode || '(' || l_final_dc.download_code || ')', 24);
565 
566       debug(l_debug);
567 
568       l_debug := '  ' || rpad('Final LDD:',10) ||
569 		 rpad(to_char(l_final_dc.last_definition_date, G_STD_DATE_MASK), 24);
570 
571       debug(l_debug);
572 
573       l_debug := '  ' || rpad('Final LUD:',10) ||
574 		 rpad(to_char(l_final_dc.last_update_date, G_STD_DATE_MASK), 24);
575 
576       debug(l_debug);
577 
578       debug(' ');
579    end if;
580 
581 end debug_up_fnd_ums_bugfix;
582 
583 --------------------------------------------------------------------------------
584 procedure up_fnd_ums_bugfix
585   (p_upload_phase           in varchar2,
586    p_release_name           in varchar2,
587    p_baseline               in varchar2,
588    p_bug_number             in varchar2,
589    p_download_mode          in varchar2,
590    p_application_short_name in varchar2,
591    p_release_status         in varchar2,
592    p_type                   in varchar2,
593    p_abstract               in varchar2,
594    p_last_definition_date   in varchar2,
595    p_last_update_date       in varchar2,
596    p_custom_mode            in varchar2)
597 is
598    l_file_dc  data_contents;
599    l_db_dc    data_contents;
600    l_final_dc data_contents;
601    -- rjaiswal
602    l_baseline     varchar2(150);
603    l_forced       boolean;
604    l_forced_db_dc data_contents;
605 begin
606    -- rjaiswal
607    if (upper(p_application_short_name) <> 'AU') then
608      select decode(instr(p_baseline, '.',1,2) - 1, -1,p_baseline ,
609      substr(p_baseline , instr(p_baseline , '.',1,2) +1)) into l_baseline from dual;
610    else
611      select decode(instr(p_baseline, '.',1,1) - 1, -1,p_baseline ,
612      substr(p_baseline , instr(p_baseline , '.',1,1) +1,1)) into l_baseline from
613 dual;
614    end if;
615    if (p_upload_phase = 'BEGIN') then
616       -- Lock the entity first
617 
618       lock_entity('FND_UMS_BUGFIXES', 'TOP_LEVEL', p_release_name, p_bug_number);
619 
620       -- Gather LDT file details
621 
622       l_file_dc := get_data_contents(p_download_mode,
623                                      to_date(nvl(p_last_definition_date, p_last_update_date), G_STD_DATE_MASK),
624                                      to_date(p_last_update_date, G_STD_DATE_MASK));
625 
626       -- Gather database details
627 
628       declare
629          l_bugfix fnd_ums_bugfixes%ROWTYPE;
630       begin
631          select /*+ INDEX(fnd_ums_bugfixes fnd_ums_bugfixes_u2) */ *
632          into l_bugfix
633          from fnd_ums_bugfixes
634          where release_name = p_release_name
635          and bug_number = p_bug_number
636          and baseline = l_baseline;
637 
638 
639          g_bugfix_guid := l_bugfix.bugfix_guid;
640 
641          l_db_dc := get_data_contents(l_bugfix.download_mode,
642                                       l_bugfix.last_definition_date,
643                                       l_bugfix.last_update_date);
644       exception
645          when no_data_found then
646             -- there is no data for this bugfix in the database
647 
648             g_bugfix_guid := sys_guid();
649 
650             l_db_dc := get_data_contents(DL_MODE_NONE,
651                                          g_default_date,
652                                          g_default_date);
653       end;
654 
655       -- determine if any upload is allowed.
656 
657       g_uc.upload_bugfix_replacement     := false;
658       g_uc.upload_prereqs_includes_links := false;
659       g_uc.upload_files                  := false;
660 
661       l_forced := false;
662       if (p_custom_mode = 'FORCE') then
663          -- If the bugfix is not already FORCEd, then FORCE it to be re-uploaded.
664 
665          declare
666             l_already_forced boolean;
667          begin
668             declare
669                l_vc2 varchar2(1);
670             begin
671                -- if a collection doesn't have an entry at a given index then
672                -- fetching the entry from that index raises no_data_found exception.
673 
674                l_vc2 := g_forced_bugfixes(p_bug_number);
675                l_already_forced := true;
676             exception
677                when no_data_found then
678                   l_already_forced := false;
679             end;
680 
681             if (not l_already_forced) then
682                -- Force bugfix to be re-uploaded.
683                l_forced := true;
684 
685                l_forced_db_dc := l_db_dc;
686 
687                g_uc.upload_bugfix_replacement     := true;
688                g_uc.upload_prereqs_includes_links := true;
689                g_uc.upload_files                  := true;
690 
691                l_db_dc := get_data_contents(DL_MODE_NONE,
692                                             g_default_date,
693                                             g_default_date);
694 
695                -- Mark this bugfix as forced.
696 
697                g_forced_bugfixes(p_bug_number) := 'Y';
698             end if;
699          end;
700       end if;
701 
702       l_final_dc := l_db_dc;
703 
704       -- Decide whether or not bugfix and replacement (BR) should be uploaded
705       --
706       --          |                    DB
707       --          | no_data_found  files_only  bugfix_replacement_exists
708       -- ---------+------------------------------------------------------
709       --    files | delete         delete      do nothing
710       -- F   only | insert         insert
711       -- i        |
712       -- l     BR | delete         delete      file.LUD <= db.LUD : do nothing
713       -- e exists | insert         insert      file.LUD >  db.LUD : delete/insert
714       --
715 
716       if (l_file_dc.has_bugfix_replacement) then
717          -- File has bugfix and replacement data
718 
719          l_final_dc.has_bugfix_replacement := true;
720 
721          if (l_db_dc.has_bugfix_replacement) then
722             -- DB has bugfix and replacement data
723 
724             if (l_file_dc.last_update_date <= l_db_dc.last_update_date) then
725                -- File last update date is older or same, do nothing
726 
727                null;
728 
729             else
730                -- File update date is newer
731 
732                l_final_dc.last_update_date := l_file_dc.last_update_date;
733 
734                g_uc.upload_bugfix_replacement := true;
735 
736             end if; -- LUD
737          else
738             l_final_dc.last_update_date := l_file_dc.last_update_date;
739 
740             g_uc.upload_bugfix_replacement := true;
741 
742          end if;
743 
744       else
745          if (l_db_dc.has_bugfix_replacement) then
746             -- DB has bugfix and replacement data, do nothing
747             null;
748 
749          else
750             -- Create the dummy/template bugfix definition for foreign
751             -- key reference purposes.
752 
753             g_uc.upload_bugfix_replacement := true;
754 
755             l_final_dc.has_bugfix_replacement := false;
756          end if;
757       end if;
758 
759       -- Decide whether or not PIL (prereqs/includes/links) data should be uploaded
760 
761         if (l_file_dc.pil_level > PIL_LEVEL_NONE) then
762          -- File has PIL data
763 
764          if (l_db_dc.pil_level > PIL_LEVEL_NONE) then
765             -- DB has PIL data
766 
767             if (l_file_dc.last_definition_date < l_db_dc.last_definition_date) then
768                -- File last definition date is older, do nothing
769                null;
770 
771             elsif (l_file_dc.last_definition_date = l_db_dc.last_definition_date) then
772                -- File and DB last definition dates are same, upload the missing
773                -- definition data. Links might be missing.
774                --
775                --       | DB  |
776                --       | P L |
777                -- ------+-----+------------------------------
778                -- F   P | P L | <- 1st row : Final result
779                -- i     |     | <- 2nd row : What is uploaded
780                -- l   L | L L |
781                -- e     | L   |
782                --
783                --
784 
785                if (l_file_dc.pil_level > l_db_dc.pil_level) then
786                   -- Upload the link information
787 
788                   l_final_dc.last_definition_date := l_file_dc.last_definition_date;
789 
790                   g_uc.upload_prereqs_includes_links := true;
791 
792                   l_final_dc.pil_level := l_file_dc.pil_level;
793                end if;
794 
795             else
796                -- File definition date is newer
797 
798                l_final_dc.last_definition_date := l_file_dc.last_definition_date;
799 
800                g_uc.upload_prereqs_includes_links := true;
801 
802                l_final_dc.pil_level := l_file_dc.pil_level;
803             end if; -- LDD
804 
805          else
806             -- DB has no definition, insert data from file
807 
808             l_final_dc.last_definition_date := l_file_dc.last_definition_date;
809 
810             g_uc.upload_prereqs_includes_links := true;
811 
812             l_final_dc.pil_level := l_file_dc.pil_level;
813          end if; -- l_db_dc.pil_level
814 
815       else
816          -- File has no PIL data, do nothing
817          null;
818 
819       end if; -- l_file_dc.pil_level
820 
821       -- Decide whether or not files should be uploaded
822       --
823       --          | DB
824       --          | no_files       files exist
825       -- ---------+--------------------------------
826       -- F     no | do nothing     do nothing
827       -- i  files |
828       -- l        |
829       -- e  files | delete         file.LDD <= db.LDD : do nothing
830       --    exist | insert         file.LDD >  db.LDD : delete/insert
831       --
832 
833       if (l_file_dc.has_files) then
834          -- File has files data
835 
836          l_final_dc.has_files := true;
837 
838          if (l_db_dc.has_files) then
839             -- DB has files data
840 
841             if (l_file_dc.last_definition_date <= l_db_dc.last_definition_date) then
842                -- file.LDD is older than DB.LDD or they are same, do nothing
843 
844                null;
845 
846             else
847                -- file.LDD is newer than DB.LDD
848                -- Do not change the final.LDD. In ARU LDD reflects changes in dependency
849                -- tree and file contents. New f<bug_number>.ldt file only has file
850                -- contents and the LDD in this file does not reflect the correct LDD
851                -- of the bugfix dependency information.
852 
853                g_uc.upload_files := true;
854 
855             end if;
856 
857          else
858             -- DB has no files data
859 
860             g_uc.upload_files := true;
861 
862          end if;
863 
864       else
865          -- File has no files data, do nothing
866 
867          null;
868 
869       end if;
870 
871       -- Derive Final Download Mode
872 
873       derive_download_mode(l_final_dc);
874 
875       -- Debug
876 
877       if (g_debug_flag = DEBUG_ON) then
878          debug_up_fnd_ums_bugfix(p_release_name,
879                                  p_bug_number,
880                                  l_forced,
881                                  l_file_dc,
882                                  l_forced_db_dc,
883                                  l_db_dc,
884                                  l_final_dc);
885       end if;
886 
887       --
888       -- Abort the upload if there is nothing new to upload.
889       -- Disabled until FNDLOAD implements the abort logic.
890       --
891       if (g_debug_flag = DEBUG_ABORT) then
892          if (g_uc.upload_bugfix_replacement or
893              g_uc.upload_prereqs_includes_links or
894              g_uc.upload_files) then
895             null;
896 
897          else
898             if ((l_file_dc.last_update_date < l_db_dc.last_update_date) and
899                 (l_file_dc.last_definition_date < l_db_dc.last_definition_date)) then
900                -- File is older and has no more data than DB.
901 
902                raise_application_error(ERROR_ABORT,
903                                        MSG_ABORT_OLDER || p_bug_number);
904             else
905                -- Dates are same and file has no more data than DB.
906 
907                raise_application_error(ERROR_ABORT,
908                                        MSG_ABORT_LEVEL || p_bug_number);
909             end if;
910          end if;
911       end if;
912 
913       -- Real UPLOAD ...
914 
915       -- Delete children ...
916 
917       if (g_uc.upload_files) then
918          -- delete files
919 
920          delete from fnd_ums_bugfix_file_versions
921          where bugfix_guid = g_bugfix_guid;
922 
923          g_rc.bugfix_file_versions := g_rc.bugfix_file_versions + sql%rowcount;
924       end if;
925 
926       if (g_uc.upload_prereqs_includes_links) then
927          -- delete prereqs, includes
928 
929          delete from fnd_ums_bugfix_relationships
930          where bugfix_guid = g_bugfix_guid
931          and relation_type in (REL_TYPE_PREREQS,
932                                REL_TYPE_INDIRECTLY_PREREQS,
933                                REL_TYPE_INCLUDES,
934                                REL_TYPE_INDIRECTLY_INCLUDES);
935 
936          g_rc.bugfix_relationships := g_rc.bugfix_relationships + sql%rowcount;
937       end if;
938 
939       -- Insert the bugfix data if necessary
940 
941       if (g_uc.upload_bugfix_replacement) then
942          -- delete replacement
943 
944          delete from fnd_ums_bugfix_relationships
945          where bugfix_guid = g_bugfix_guid
946          and relation_type = REL_TYPE_REPLACED_BY;
947 
948          g_rc.bugfix_relationships := g_rc.bugfix_relationships + sql%rowcount;
949 
950          -- delete bugfix
951 
952          delete /*+ INDEX(fnd_ums_bugfixes fnd_ums_bugfixes_u1) */
953          from fnd_ums_bugfixes
954          where bugfix_guid = g_bugfix_guid;
955 
956          g_rc.bugfixes := g_rc.bugfixes + sql%rowcount;
957 
958          -- insert bugfix
959 
960          declare
961             l_application_short_name varchar2(32000);
962             l_release_status         varchar2(32000);
963             l_type                   varchar2(32000);
964             l_abstract               varchar2(32000);
965          begin
966             if (l_file_dc.download_mode = DL_MODE_FILES_ONLY) then
967                l_application_short_name := nvl(p_application_short_name, NOT_AVAILABLE);
968                l_release_status := nvl(p_release_status, NOT_AVAILABLE);
969                l_type := nvl(p_type, NOT_AVAILABLE);
970                l_abstract := nvl(p_abstract, NOT_AVAILABLE);
971             else
972                l_application_short_name := p_application_short_name;
973                l_release_status := p_release_status;
974                l_type := p_type;
975                l_abstract := p_abstract;
976             end if;
977 
978             insert into fnd_ums_bugfixes
979             (bugfix_guid,
980              release_name,
981              bug_number,
982              baseline,
983              download_mode,
984              application_short_name,
985              release_status,
986              type,
987              abstract,
988              last_definition_date,
989              last_update_date)
990             values
991             (g_bugfix_guid,
992              p_release_name,
993              p_bug_number,
994              l_baseline,
995              l_final_dc.download_mode,
996              l_application_short_name,
997              l_release_status,
998              l_type,
999              l_abstract,
1000              l_final_dc.last_definition_date,
1001              l_final_dc.last_update_date);
1002 
1003             g_rc.bugfixes := g_rc.bugfixes + sql%rowcount;
1004          end;
1005       elsif (g_uc.upload_prereqs_includes_links or g_uc.upload_files) then
1006          -- If PIL (affects DM and LDD) or Files (affects DM) are uploaded,
1007          -- but bugfix and replacement data is not uploaded
1008          -- then download_mode and last_definition_date should be updated.
1009          -- For Example: If database is RO, and ldt is LF, and dates are same
1010          -- then PIL and Files will be uploaded but bugfix and replacement
1011          -- data will not.
1012 
1013          update /*+ INDEX(fnd_ums_bugfixes fnd_ums_bugfixes_u1) */ fnd_ums_bugfixes
1014             set download_mode = l_final_dc.download_mode,
1015                 last_definition_date = l_final_dc.last_definition_date
1016           where bugfix_guid = g_bugfix_guid;
1017 
1018           g_rc.bugfixes := g_rc.bugfixes + sql%rowcount;
1019       end if;
1020 
1021    elsif(p_upload_phase = 'END') then
1022       -- no work to do
1023       null;
1024    else
1025       raise_application_error(ERROR_UNKNOWN_UPLOAD_PHASE,
1026          'Unknown UPLOAD_PHASE: ' || p_upload_phase);
1027    end if;
1028 
1029    -- do not catch exceptions here.
1030 end up_fnd_ums_bugfix;
1031 
1032 --------------------------------------------------------------------------------
1033 function new_file_guid_at
1034   (p_application_short_name in fnd_ums_files.application_short_name%type,
1035    p_location               in fnd_ums_files.location%type,
1036    p_name                   in fnd_ums_files.name%type)
1037 return raw
1038 is
1039    pragma autonomous_transaction;
1040    l_file_guid fnd_ums_files.file_guid%type;
1041 begin
1042    -- lock the entity first
1043 
1044    lock_entity('FND_UMS_FILES', p_application_short_name, p_location, p_name);
1045 
1046    -- check the existence again
1047 
1048    begin
1049       select /*+ INDEX(fnd_ums_files fnd_ums_files_u2) */ file_guid
1050       into l_file_guid
1051       from fnd_ums_files
1052       where application_short_name = p_application_short_name
1053       and location = p_location
1054       and name = p_name;
1055    exception
1056       when no_data_found then
1057          -- populate FND_UMS_FILES
1058 
1059          insert into fnd_ums_files
1060          (file_guid,
1061           application_short_name,
1062           location,
1063           name)
1064          values
1065          (sys_guid(),
1066           p_application_short_name,
1067           p_location,
1068           p_name)
1069          returning file_guid
1070          into l_file_guid;
1071 
1072          g_rc.files := g_rc.files + sql%rowcount;
1073    end;
1074 
1075    commit;
1076 
1077    return l_file_guid;
1078 
1079 exception
1080    when others then
1081       rollback;
1082       raise;
1083 end new_file_guid_at;
1084 
1085 --------------------------------------------------------------------------------
1086 function get_file_guid
1087   (p_application_short_name in fnd_ums_files.application_short_name%type,
1088    p_location               in fnd_ums_files.location%type,
1089    p_name                   in fnd_ums_files.name%type)
1090 return raw
1091 is
1092    l_file_guid fnd_ums_files.file_guid%type;
1093 begin
1094    begin
1095       select /*+ INDEX(fnd_ums_files fnd_ums_files_u2) */ file_guid
1096       into l_file_guid
1097       from fnd_ums_files
1098       where application_short_name = p_application_short_name
1099       and location = p_location
1100       and name = p_name;
1101    exception
1102       when no_data_found then
1103          l_file_guid := new_file_guid_at(p_application_short_name,
1104                                          p_location,
1105                                          p_name);
1106    end;
1107 
1108    return l_file_guid;
1109 end get_file_guid;
1110 
1111 --------------------------------------------------------------------------------
1112 function new_file_version_guid_at
1113   (p_file_guid in fnd_ums_file_versions.file_guid%type,
1114    p_version   in fnd_ums_file_versions.version%type)
1115 return raw
1116 is
1117    pragma autonomous_transaction;
1118    l_file_version_guid fnd_ums_file_versions.file_version_guid%type;
1119 begin
1120    -- lock the entity first
1121 
1122    lock_entity('FND_UMS_FILE_VERSIONS', p_file_guid, p_version);
1123 
1124    -- check the existence again
1125 
1126    begin
1127       select /*+ INDEX(fnd_ums_file_versions fnd_ums_file_versions_u2) */ file_version_guid
1128       into l_file_version_guid
1129       from fnd_ums_file_versions
1130       where file_guid = p_file_guid
1131       and version = p_version;
1132    exception
1133       when no_data_found then
1134          -- populate FND_UMS_FILE_VERSIONS
1135 
1136          insert into fnd_ums_file_versions
1137          (file_version_guid,
1138           file_guid,
1139           version)
1140          values
1141          (sys_guid(),
1142           p_file_guid,
1143           p_version)
1144          returning file_version_guid
1145          into l_file_version_guid;
1146 
1147          g_rc.file_versions := g_rc.file_versions + sql%rowcount;
1148    end;
1149 
1150    commit;
1151 
1152    return l_file_version_guid;
1153 
1154 exception
1155    when others then
1156       rollback;
1157       raise;
1158 end new_file_version_guid_at;
1159 
1160 --------------------------------------------------------------------------------
1161 function get_file_version_guid
1162   (p_file_guid in fnd_ums_file_versions.file_guid%type,
1163    p_version   in fnd_ums_file_versions.version%type)
1164 return raw
1165 is
1166    l_file_version_guid fnd_ums_file_versions.file_version_guid%type;
1167 begin
1168    begin
1169       select /*+ INDEX(fnd_ums_file_versions fnd_ums_file_versions_u2) */ file_version_guid
1170       into l_file_version_guid
1171       from fnd_ums_file_versions
1172       where file_guid = p_file_guid
1173       and version = p_version;
1174    exception
1175       when no_data_found then
1176          l_file_version_guid := new_file_version_guid_at(p_file_guid,
1177                                                          p_version);
1178    end;
1179 
1180    return l_file_version_guid;
1181 end get_file_version_guid;
1182 
1183 --------------------------------------------------------------------------------
1184 procedure up_fnd_ums_bugfix_file
1185   (p_application_short_name in varchar2,
1186    p_location               in varchar2,
1187    p_name                   in varchar2,
1188    p_version                in varchar2)
1189 is
1190    l_file_guid         fnd_ums_file_versions.file_guid%type;
1191    l_file_version_guid fnd_ums_file_versions.file_version_guid%type;
1192 begin
1193    if (g_uc.upload_files) then
1194       -- File upload is allowed.
1195 
1196       -- Get file_guid
1197 
1198       l_file_guid := get_file_guid(p_application_short_name,
1199                                    p_location,
1200                                    p_name);
1201 
1202       -- Get file_version_guid
1203 
1204       l_file_version_guid := get_file_version_guid(l_file_guid,
1205                                                    p_version);
1206 
1207       -- populate FND_UMS_BUGFIX_FILE_VERSIONS
1208 
1209       insert into fnd_ums_bugfix_file_versions
1210       (bugfix_guid,
1211        file_version_guid)
1212       values
1213       (g_bugfix_guid,
1214        l_file_version_guid);
1215 
1216       g_rc.bugfix_file_versions := g_rc.bugfix_file_versions + sql%rowcount;
1217    else
1218       -- File upload is not allowed.
1219       null;
1220    end if;
1221 end up_fnd_ums_bugfix_file;
1222 
1223 --------------------------------------------------------------------------------
1224 function new_bugfix_guid_at
1225   (p_release_name in fnd_ums_bugfixes.release_name%type,
1226    p_bug_number   in fnd_ums_bugfixes.bug_number%type)
1227 return raw
1228 is
1229    pragma autonomous_transaction;
1230    l_bugfix_guid fnd_ums_bugfixes.bugfix_guid%type;
1231 begin
1232    -- lock the entity first
1233 
1234    lock_entity('FND_UMS_BUGFIXES', p_release_name, p_bug_number);
1235 
1236    -- check the existence again
1237 
1238    begin
1239       select /*+ INDEX(fnd_ums_bugfixes fnd_ums_bugfixes_u2) */ bugfix_guid
1240       into l_bugfix_guid
1241       from fnd_ums_bugfixes
1242       where release_name = p_release_name
1243       and bug_number = p_bug_number;
1244    exception
1245       when no_data_found then
1246          -- If bugfix doesn't exist then create a DL_MODE_NONE bugfix.
1247          -- This happens in these two cases.
1248          -- - p_download_mode is NONE.
1249          --     This happens when INCLUDES, INDIRECTLY_INCLUDES relationships
1250          --     are downloaded under the top level bugfix.
1251          -- - forward relationship references.
1252          --     If two entities refer to each other, the first entity will
1253          --     have a forward relationship reference to the second one.
1254          --     That second one may not exist in the DB, so a bugfix must
1255          --     be created to get the bugfix_guid. This bugfix is marked
1256          --     as DL_MODE_NONE so that its definition will be replaced
1257          --     with the real definition.
1258 
1259          -- populate FND_UMS_BUGFIXES
1260 
1261          insert into fnd_ums_bugfixes
1262          (bugfix_guid,
1263           release_name,
1264           bug_number,
1265           download_mode,
1266           application_short_name,
1267           release_status,
1268           type,
1269           abstract,
1270           last_definition_date,
1271           last_update_date)
1272          values
1273          (sys_guid(),
1274           p_release_name,
1275           p_bug_number,
1276           DL_MODE_NONE,
1277           NOT_AVAILABLE,
1278           NOT_AVAILABLE,
1279           NOT_AVAILABLE,
1280           NOT_AVAILABLE,
1281           g_default_date,
1282           g_default_date)
1283          returning bugfix_guid
1284          into l_bugfix_guid;
1285 
1286          g_rc.bugfixes := g_rc.bugfixes + sql%rowcount;
1287    end;
1288 
1289    commit;
1290 
1291    return l_bugfix_guid;
1292 
1293 exception
1294    when others then
1295       rollback;
1296       raise;
1297 end new_bugfix_guid_at;
1298 
1299 --------------------------------------------------------------------------------
1300 function get_bugfix_guid
1301   (p_release_name in fnd_ums_bugfixes.release_name%type,
1302    p_bug_number   in fnd_ums_bugfixes.bug_number%type)
1303 return raw
1304 is
1305    l_bugfix_guid fnd_ums_bugfixes.bugfix_guid%type;
1306 begin
1307    begin
1308       select /*+ INDEX(fnd_ums_bugfixes fnd_ums_bugfixes_u2) */ bugfix_guid
1309       into l_bugfix_guid
1310       from fnd_ums_bugfixes
1311       where release_name = p_release_name
1312       and bug_number = p_bug_number;
1313    exception
1314       when no_data_found then
1315          l_bugfix_guid := new_bugfix_guid_at(p_release_name,
1316                                              p_bug_number);
1317    end;
1318 
1319    return l_bugfix_guid;
1320 end get_bugfix_guid;
1321 
1322 --------------------------------------------------------------------------------
1323 procedure up_fnd_ums_bugfix_relationship
1324   (p_relation_type                in varchar2,
1325    p_related_bugfix_release_name  in varchar2,
1326    p_related_bugfix_bug_number    in varchar2,
1327    p_related_bugfix_download_mode in varchar2)
1328 is
1329    l_related_bugfix_guid fnd_ums_bugfix_relationships.related_bugfix_guid%type;
1330 begin
1331    if (((g_uc.upload_prereqs_includes_links) and
1332         (p_relation_type in (REL_TYPE_PREREQS,
1333                              REL_TYPE_INDIRECTLY_PREREQS,
1334                              REL_TYPE_INCLUDES,
1335                              REL_TYPE_INDIRECTLY_INCLUDES))) or
1336        ((g_uc.upload_bugfix_replacement) and
1337         (p_relation_type = REL_TYPE_REPLACED_BY))) then
1338 
1339       -- Get the related_bugfix_guid
1340 
1341       l_related_bugfix_guid := get_bugfix_guid(p_related_bugfix_release_name,
1342                                                p_related_bugfix_bug_number);
1343 
1344       -- insert the relationship
1345 
1346       insert into fnd_ums_bugfix_relationships
1347       (bugfix_guid,
1348        relation_type,
1349        related_bugfix_guid)
1350       values
1351       (g_bugfix_guid,
1352        p_relation_type,
1353        l_related_bugfix_guid);
1354 
1355       g_rc.bugfix_relationships := g_rc.bugfix_relationships + sql%rowcount;
1356    else
1357       -- Either relationship upload is not allowed or
1358       -- REL_TYPE_REPLACES, REL_TYPE_REP_BY_FIRST_NON_OBS and unknown
1359       -- relationships are discarded.
1360       null;
1361    end if;
1362 end up_fnd_ums_bugfix_relationship;
1363 
1364 --------------------------------------------------------------------------------
1365 procedure up_fnd_ums_one_bugfix
1366   (p_upload_phase in varchar2,
1367    p_release_name in varchar2,
1368    p_baseline in varchar2,
1369    p_bug_number   in varchar2)
1370 is
1371 begin
1372    if (p_upload_phase = 'BEGIN') then
1373       analyze_ums_tables();
1374 
1375    elsif (p_upload_phase = 'END') then
1376       -- no work to do
1377       null;
1378    else
1379       raise_application_error(ERROR_UNKNOWN_UPLOAD_PHASE,
1380          'Unknown UPLOAD_PHASE: ' || p_upload_phase);
1381    end if;
1382 end up_fnd_ums_one_bugfix;
1383 
1384 --------------------------------------------------------------------------------
1385 procedure up_fnd_ums_bugfixes
1386   (p_upload_phase         in varchar2,
1387    p_entity_download_mode in varchar2,
1388    p_release_name         in varchar2,
1389    p_bug_number           in varchar2,
1390    p_start_date           in varchar2,
1391    p_end_date             in varchar2)
1392 is
1393 begin
1394    if (p_upload_phase = 'BEGIN') then
1395       analyze_ums_tables();
1396 
1397    elsif (p_upload_phase = 'END') then
1398       -- no work to do
1399       null;
1400    else
1401       raise_application_error(ERROR_UNKNOWN_UPLOAD_PHASE,
1402          'Unknown UPLOAD_PHASE: ' || p_upload_phase);
1403    end if;
1404 end up_fnd_ums_bugfixes;
1405 
1406 --------------------------------------------------------------------------------
1407 function newline
1408    return varchar2
1409 is
1410    l_newline varchar2(100);
1411    l_plsql   varchar2(2000);
1412 begin
1413    -- First try fnd_global.newline.
1414    begin
1415       --
1416       -- Use dynamic call not to have compile time dependency
1417       --
1418       l_plsql := 'begin :b_newline := fnd_global.newline(); end;';
1419       execute immediate l_plsql using out l_newline;
1420    exception
1421       when others then
1422          --
1423          -- Use dynamic call to go around the GSCC. chr() is not allowed.
1424          --
1425          l_plsql := 'begin ' ||
1426                     '   :b_newline := convert(chr(10), ' ||
1427                     '                         substr(userenv(''LANGUAGE''), ' ||
1428                     '                                instr(userenv(''LANGUAGE''), ''.'') + 1), ' ||
1429                     '                         ''US7ASCII''); ' ||
1430                     'end; ';
1431          execute immediate l_plsql using out l_newline;
1432    end;
1433 
1434    return l_newline;
1435 end newline;
1436 
1437 begin
1438    g_debug_flag := DEBUG_OFF;
1439    g_newline := fnd_ums_loader.newline();
1440 
1441    g_default_date := to_date('1900/01/01 00:00:00', G_STD_DATE_MASK);
1442 
1443    g_rc.bugfixes              := 0;
1444    g_rc.bugfix_relationships  := 0;
1445    g_rc.files                 := 0;
1446    g_rc.file_versions         := 0;
1447    g_rc.bugfix_file_versions  := 0;
1448 
1449 end fnd_oam_ums_loader;