1 Package Body ame_aty_upd as
2 /* $Header: amatyrhi.pkb 120.4 2005/11/22 03:14 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_aty_upd.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |----------------------------< dt_update_dml >-----------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 -- This procedure controls the execution of dml from the datetrack mode
17 -- of CORRECTION only. It is important to note that the object version
18 -- number is only increment by 1 because the datetrack correction is
19 -- soley for one datetracked row.
20 -- This procedure controls the actual dml update logic. The functions of
21 -- this procedure are as follows:
22 -- 1) Get the next object_version_number.
23 -- 2) To set and unset the g_api_dml status as required (as we are about to
24 -- perform dml).
25 -- 3) To update the specified row in the schema using the primary key in
26 -- the predicates.
27 -- 4) To trap any constraint violations that may have occurred.
28 -- 5) To raise any other errors.
29 --
30 -- Prerequisites:
31 -- This is an internal private procedure which must be called from the
32 -- update_dml procedure.
33 --
34 -- In Parameters:
35 -- A Pl/Sql record structure.
36 --
37 -- Post Success:
38 -- The specified row will be updated in the schema.
39 --
40 -- Post Failure:
41 -- On the update dml failure it is important to note that we always reset the
42 -- g_api_dml status to false.
43 -- If a check or unique integrity constraint violation is raised the
44 -- constraint_error procedure will be called.
45 -- If any other error is reported, the error will be raised after the
46 -- g_api_dml status is reset.
47 --
48 -- Developer Implementation Notes:
49 -- The update 'set' arguments list should be modified if any of your
50 -- attributes are not updateable.
51 --
52 -- Access Status:
53 -- Internal Row Handler Use Only.
54 --
55 -- {End Of Comments}
56 -- ----------------------------------------------------------------------------
57 Procedure dt_update_dml
58 (p_rec in out nocopy ame_aty_shd.g_rec_type
59 ,p_effective_date in date
60 ,p_datetrack_mode in varchar2
61 ,p_validation_start_date in date
62 ,p_validation_end_date in date
63 ) is
64 --
65 l_proc varchar2(72) := g_package||'dt_update_dml';
66 --
67 Begin
68 hr_utility.set_location('Entering:'||l_proc, 5);
69 --
70 If (p_datetrack_mode = hr_api.g_correction) then
71 hr_utility.set_location(l_proc, 10);
72 --
73 -- Because we are updating a row we must get the next object
74 -- version number.
75 --
76 p_rec.object_version_number :=
77 ame_aty_shd.get_object_version_number
78 (p_action_type_id => p_rec.action_type_id
79 );
80 --
81 --
82 --
83 -- Update the ame_action_types Row
84 --
85 update ame_action_types
86 set
87 action_type_id = p_rec.action_type_id
88 ,name = p_rec.name
89 ,procedure_name = p_rec.procedure_name
90 ,description = p_rec.description
91 ,security_group_id = p_rec.security_group_id
92 ,dynamic_description = p_rec.dynamic_description
93 ,description_query = p_rec.description_query
94 ,object_version_number = p_rec.object_version_number
95 where action_type_id = p_rec.action_type_id
96 and start_date = p_validation_start_date
97 and ((p_validation_end_date is null and end_date is null) or
98 (end_date = p_validation_end_date));
99 --
100 --
101 --
102 -- Set the effective start and end dates
103 --
104 p_rec.start_date := p_validation_start_date;
105 p_rec.end_date := p_validation_end_date;
106 End If;
107 --
108 hr_utility.set_location(' Leaving:'||l_proc, 15);
109 Exception
110 When hr_api.check_integrity_violated Then
111 -- A check constraint has been violated
112 --
113 ame_aty_shd.constraint_error
114 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
115 When hr_api.unique_integrity_violated Then
116 -- Unique integrity has been violated
117 --
118 ame_aty_shd.constraint_error
119 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
120 When Others Then
121 --
122 Raise;
123 End dt_update_dml;
124 --
125 -- ----------------------------------------------------------------------------
126 -- |------------------------------< update_dml >------------------------------|
127 -- ----------------------------------------------------------------------------
128 -- {Start Of Comments}
129 --
130 -- Description:
131 -- This procedure calls the dt_update_dml control logic which handles
132 -- the actual datetrack dml.
133 --
134 -- Prerequisites:
135 -- This is an internal private procedure which must be called from the upd
136 -- procedure.
137 --
138 -- In Parameters:
139 -- A Pl/Sql record structre.
140 --
141 -- Post Success:
142 -- Processing contines.
143 --
144 -- Post Failure:
145 -- No specific error handling is required within this procedure.
146 --
147 -- Developer Implementation Notes:
148 -- The update 'set' arguments list should be modified if any of your
149 -- attributes are not updateable.
150 --
151 -- Access Status:
152 -- Internal Row Handler Use Only.
153 --
154 -- {End Of Comments}
155 -- ----------------------------------------------------------------------------
156 Procedure update_dml
157 (p_rec in out nocopy ame_aty_shd.g_rec_type
158 ,p_effective_date in date
159 ,p_datetrack_mode in varchar2
160 ,p_validation_start_date in date
161 ,p_validation_end_date in date
162 ) is
163 --
164 l_proc varchar2(72) := g_package||'update_dml';
165 --
166 Begin
167 hr_utility.set_location('Entering:'||l_proc, 5);
168 --
169 ame_aty_upd.dt_update_dml
170 (p_rec => p_rec
171 ,p_effective_date => p_effective_date
172 ,p_datetrack_mode => p_datetrack_mode
173 ,p_validation_start_date => p_validation_start_date
174 ,p_validation_end_date => p_validation_end_date
175 );
176 --
177 hr_utility.set_location(' Leaving:'||l_proc, 10);
178 End update_dml;
179 --
180 -- ----------------------------------------------------------------------------
181 -- |----------------------------< dt_pre_update >-----------------------------|
182 -- ----------------------------------------------------------------------------
183 -- {Start Of Comments}
184 --
185 -- Description:
186 -- The dt_pre_update procedure controls the execution
187 -- of dml for the datetrack modes of: UPDATE, UPDATE_OVERRIDE
188 -- and UPDATE_CHANGE_INSERT only. The execution required is as
189 -- follows:
190 --
191 -- 1) Providing the datetrack update mode is not 'CORRECTION'
192 -- then set the effective end date of the current row (this
193 -- will be the validation_start_date - 1).
194 -- 2) If the datetrack mode is 'UPDATE_OVERRIDE' then call the
195 -- corresponding delete_dml process to delete any future rows
196 -- where the effective_start_date is greater than or equal to
197 -- the validation_start_date.
198 -- 3) Call the insert_dml process to insert the new updated row
199 -- details.
200 --
201 -- Prerequisites:
202 -- This is an internal procedure which is called from the
203 -- pre_update procedure.
204 --
205 -- In Parameters:
206 --
207 -- Post Success:
208 -- Processing continues.
209 --
210 -- Post Failure:
211 -- If an error has occurred, an error message and exception will be raised
212 -- but not handled.
213 --
214 -- Developer Implementation Notes:
215 -- This is an internal procedure which is required by Datetrack. Don't
216 -- remove or modify.
217 --
218 -- Access Status:
219 -- Internal Row Handler Use Only.
220 --
221 -- {End Of Comments}
222 -- ----------------------------------------------------------------------------
223 Procedure dt_pre_update
224 (p_rec in out nocopy ame_aty_shd.g_rec_type
225 ,p_effective_date in date
226 ,p_datetrack_mode in varchar2
227 ,p_validation_start_date in date
228 ,p_validation_end_date in date
229 ) is
230 --
231 l_proc varchar2(72) := g_package||'dt_pre_update';
232 l_dummy_version_number number;
233 --
234 Begin
235 hr_utility.set_location('Entering:'||l_proc, 5);
236 If (p_datetrack_mode <> hr_api.g_correction) then
237 --
238 -- Update the current effective end date
239 --
240 ame_aty_shd.upd_end_date
241 (p_effective_date => p_effective_date
242 ,p_action_type_id => p_rec.action_type_id
243 ,p_new_end_date => p_validation_start_date
244 ,p_validation_start_date => p_validation_start_date
245 ,p_validation_end_date => p_validation_end_date
246 ,p_object_version_number => l_dummy_version_number
247 );
248 --
249 If (p_datetrack_mode = hr_api.g_update_override) then
250 --
251 -- As the datetrack mode is 'UPDATE_OVERRIDE' then we must
252 -- delete any future rows
253 --
254 ame_aty_del.delete_dml
255 (p_rec => p_rec
256 ,p_effective_date => p_effective_date
257 ,p_datetrack_mode => p_datetrack_mode
258 ,p_validation_start_date => p_validation_start_date
259 ,p_validation_end_date => p_validation_end_date
260 );
261 End If;
262 --
263 -- We must now insert the updated row
264 --
265 ame_aty_ins.insert_dml
266 (p_rec => p_rec
267 ,p_effective_date => p_effective_date
268 ,p_datetrack_mode => p_datetrack_mode
269 ,p_validation_start_date => p_validation_start_date
270 ,p_validation_end_date => p_validation_end_date
271 );
272 End If;
273 hr_utility.set_location(' Leaving:'||l_proc, 20);
274 End dt_pre_update;
275 --
276 -- ----------------------------------------------------------------------------
277 -- |------------------------------< pre_update >------------------------------|
278 -- ----------------------------------------------------------------------------
279 -- {Start Of Comments}
280 --
281 -- Description:
282 -- This private procedure contains any processing which is required before
283 -- the update dml.
284 --
285 -- Prerequisites:
286 -- This is an internal procedure which is called from the upd procedure.
287 --
288 -- In Parameters:
289 -- A Pl/Sql record structure.
290 --
291 -- Post Success:
292 -- Processing continues.
293 --
294 -- Post Failure:
295 -- If an error has occurred, an error message and exception will be raised
296 -- but not handled.
297 -- Developer Implementation Notes:
298 -- Any pre-processing required before the update dml is issued should be
299 -- coded within this procedure. It is important to note that any 3rd party
300 -- maintenance should be reviewed before placing in this procedure. The call
301 -- to the dt_update_dml procedure should NOT be removed.
302 --
303 -- Access Status:
304 -- Internal Row Handler Use Only.
305 --
306 -- {End Of Comments}
307 -- ----------------------------------------------------------------------------
308 Procedure pre_update
309 (p_rec in out nocopy ame_aty_shd.g_rec_type
310 ,p_effective_date in date
311 ,p_datetrack_mode in varchar2
312 ,p_validation_start_date in date
313 ,p_validation_end_date in date
314 ) is
315 --
316 l_proc varchar2(72) := g_package||'pre_update';
317 --
318 Begin
319 hr_utility.set_location('Entering:'||l_proc, 5);
320 --
321 --
322 --
323 dt_pre_update
324 (p_rec => p_rec
325 ,p_effective_date => p_effective_date
326 ,p_datetrack_mode => p_datetrack_mode
327 ,p_validation_start_date => p_validation_start_date
328 ,p_validation_end_date => p_validation_end_date
329 );
330 --
331 hr_utility.set_location(' Leaving:'||l_proc, 10);
332 End pre_update;
333 --
334 -- ----------------------------------------------------------------------------
335 -- |----------------------------< post_update >-------------------------------|
336 -- ----------------------------------------------------------------------------
337 -- {Start Of Comments}
338 --
339 -- Description:
340 -- This private procedure contains any processing which is required after
341 -- the update dml.
342 --
343 -- Prerequisites:
344 -- This is an internal procedure which is called from the upd procedure.
345 --
346 -- In Parameters:
347 -- A Pl/Sql record structure.
348 --
349 -- Post Success:
350 -- Processing continues.
351 --
352 -- Post Failure:
353 -- If an error has occurred, an error message and exception will be raised
354 -- but not handled.
355 --
356 -- Developer Implementation Notes:
357 -- Any post-processing required after the update dml is issued should be
358 -- coded within this procedure. It is important to note that any 3rd party
359 -- maintenance should be reviewed before placing in this procedure.
360 --
361 -- Access Status:
362 -- Internal Row Handler Use Only.
363 --
364 -- {End Of Comments}
365 -- ----------------------------------------------------------------------------
366 Procedure post_update
367 (p_rec in ame_aty_shd.g_rec_type
368 ,p_effective_date in date
369 ,p_datetrack_mode in varchar2
370 ,p_validation_start_date in date
371 ,p_validation_end_date in date
372 ) is
373 --
374 l_proc varchar2(72) := g_package||'post_update';
375 --
376 Begin
377 hr_utility.set_location('Entering:'||l_proc, 5);
378 begin
379 --
380 ame_aty_rku.after_update
381 (p_effective_date
382 => p_effective_date
383 ,p_datetrack_mode
384 => p_datetrack_mode
385 ,p_validation_start_date
386 => p_validation_start_date
387 ,p_validation_end_date
388 => p_validation_end_date
389 ,p_action_type_id
390 => p_rec.action_type_id
391 ,p_name
392 => p_rec.name
393 ,p_procedure_name
394 => p_rec.procedure_name
395 ,p_start_date
396 => p_rec.start_date
397 ,p_end_date
398 => p_rec.end_date
399 ,p_description
400 => p_rec.description
401 ,p_security_group_id
402 => p_rec.security_group_id
403 ,p_dynamic_description
404 => p_rec.dynamic_description
405 ,p_description_query
406 => p_rec.description_query
407 ,p_object_version_number
408 => p_rec.object_version_number
409 ,p_name_o
410 => ame_aty_shd.g_old_rec.name
411 ,p_procedure_name_o
412 => ame_aty_shd.g_old_rec.procedure_name
413 ,p_start_date_o
414 => ame_aty_shd.g_old_rec.start_date
415 ,p_end_date_o
416 => ame_aty_shd.g_old_rec.end_date
417 ,p_description_o
418 => ame_aty_shd.g_old_rec.description
419 ,p_security_group_id_o
420 => ame_aty_shd.g_old_rec.security_group_id
421 ,p_dynamic_description_o
422 => ame_aty_shd.g_old_rec.dynamic_description
423 ,p_description_query_o
424 => ame_aty_shd.g_old_rec.description_query
425 ,p_object_version_number_o
426 => ame_aty_shd.g_old_rec.object_version_number
427 );
428 --
429 exception
430 --
431 when hr_api.cannot_find_prog_unit then
432 --
433 hr_api.cannot_find_prog_unit_error
434 (p_module_name => 'AME_ACTION_TYPES'
435 ,p_hook_type => 'AU');
436 --
437 end;
438 --
439 hr_utility.set_location(' Leaving:'||l_proc, 10);
440 End post_update;
441 --
442 -- ----------------------------------------------------------------------------
443 -- |-----------------------------< convert_defs >-----------------------------|
444 -- ----------------------------------------------------------------------------
445 -- {Start Of Comments}
446 --
447 -- Description:
448 -- The Convert_Defs procedure has one very important function:
449 -- It must return the record structure for the row with all system defaulted
450 -- values converted into its corresponding parameter value for update. When
451 -- we attempt to update a row through the Upd process , certain
452 -- parameters can be defaulted which enables flexibility in the calling of
453 -- the upd process (e.g. only attributes which need to be updated need to be
454 -- specified). For the upd process to determine which attributes
455 -- have NOT been specified we need to check if the parameter has a reserved
456 -- system default value. Therefore, for all parameters which have a
457 -- corresponding reserved system default mechanism specified we need to
458 -- check if a system default is being used. If a system default is being
459 -- used then we convert the defaulted value into its corresponding attribute
460 -- value held in the g_old_rec data structure.
461 --
462 -- Prerequisites:
463 -- This private function can only be called from the upd process.
464 --
465 -- In Parameters:
466 -- A Pl/Sql record structure.
467 --
468 -- Post Success:
469 -- The record structure will be returned with all system defaulted parameter
470 -- values converted into its current row attribute value.
471 --
472 -- Post Failure:
473 -- No direct error handling is required within this function. Any possible
474 -- errors within this procedure will be a PL/SQL value error due to
475 -- conversion of datatypes or data lengths.
476 --
477 -- Developer Implementation Notes:
478 -- None.
479 --
480 -- Access Status:
481 -- Internal Row Handler Use Only.
482 --
483 -- {End Of Comments}
484 -- ----------------------------------------------------------------------------
485 Procedure convert_defs
486 (p_rec in out nocopy ame_aty_shd.g_rec_type
487 ) is
488 --
489 Begin
490 --
491 -- We must now examine each argument value in the
492 -- p_rec plsql record structure
493 -- to see if a system default is being used. If a system default
494 -- is being used then we must set to the 'current' argument value.
495 --
496 If (p_rec.name = hr_api.g_varchar2) then
497 p_rec.name :=
498 ame_aty_shd.g_old_rec.name;
499 End If;
500 If (p_rec.procedure_name = hr_api.g_varchar2) then
501 p_rec.procedure_name :=
502 ame_aty_shd.g_old_rec.procedure_name;
503 End If;
504 If (p_rec.description = hr_api.g_varchar2) then
505 p_rec.description :=
506 ame_aty_shd.g_old_rec.description;
507 End If;
508 If (p_rec.security_group_id = hr_api.g_number) then
509 p_rec.security_group_id :=
510 ame_aty_shd.g_old_rec.security_group_id;
511 End If;
512 If (p_rec.dynamic_description = hr_api.g_varchar2) then
513 p_rec.dynamic_description :=
514 ame_aty_shd.g_old_rec.dynamic_description;
515 End If;
516 If (p_rec.description_query = hr_api.g_varchar2) then
517 p_rec.description_query :=
518 ame_aty_shd.g_old_rec.description_query;
519 End If;
520 --
521 End convert_defs;
522 --
523 -- ----------------------------------------------------------------------------
524 -- |---------------------------------< upd >----------------------------------|
525 -- ----------------------------------------------------------------------------
526 Procedure upd
527 (p_effective_date in date
528 ,p_datetrack_mode in varchar2
529 ,p_rec in out nocopy ame_aty_shd.g_rec_type
530 ) is
531 --
532 l_proc varchar2(72) := g_package||'upd';
533 l_validation_start_date date;
534 l_validation_end_date date;
535 --
536 Begin
537 hr_utility.set_location('Entering:'||l_proc, 5);
538 --
539 -- Ensure that the DateTrack update mode is valid
540 --
541 dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode);
542 --
543 -- We must lock the row which we need to update.
544 --
545 ame_aty_shd.lck
546 (p_effective_date => p_effective_date
547 ,p_datetrack_mode => p_datetrack_mode
548 ,p_action_type_id => p_rec.action_type_id
549 ,p_object_version_number => p_rec.object_version_number
550 ,p_validation_start_date => l_validation_start_date
551 ,p_validation_end_date => l_validation_end_date
552 );
553 --
554 -- 1. During an update system defaults are used to determine if
555 -- arguments have been defaulted or not. We must therefore
556 -- derive the full record structure values to be updated.
557 --
558 -- 2. Call the supporting update validate operations.
559 --
560 ame_aty_upd.convert_defs(p_rec);
561 --
562 ame_aty_bus.update_validate
563 (p_rec => p_rec
564 ,p_effective_date => p_effective_date
565 ,p_datetrack_mode => p_datetrack_mode
566 ,p_validation_start_date => l_validation_start_date
567 ,p_validation_end_date => l_validation_end_date
568 );
569 --
570 -- Call to raise any errors on multi-message list
571 hr_multi_message.end_validation_set;
572 --
573 -- Call the supporting pre-update operation
574 --
575 pre_update
576 (p_rec => p_rec
577 ,p_effective_date => p_effective_date
578 ,p_datetrack_mode => p_datetrack_mode
579 ,p_validation_start_date => l_validation_start_date
580 ,p_validation_end_date => l_validation_end_date
581 );
582 --
583 -- Update the row.
584 --
585 update_dml
586 (p_rec => p_rec
587 ,p_effective_date => p_effective_date
588 ,p_datetrack_mode => p_datetrack_mode
589 ,p_validation_start_date => l_validation_start_date
590 ,p_validation_end_date => l_validation_end_date
591 );
592 --
593 -- Call the supporting post-update operation
594 --
595 post_update
596 (p_rec => p_rec
597 ,p_effective_date => p_effective_date
598 ,p_datetrack_mode => p_datetrack_mode
599 ,p_validation_start_date => l_validation_start_date
600 ,p_validation_end_date => l_validation_end_date
601 );
602 --
603 -- Call to raise any errors on multi-message list
604 hr_multi_message.end_validation_set;
605 End upd;
606 --
607 -- ----------------------------------------------------------------------------
608 -- |------------------------------< upd >-------------------------------------|
609 -- ----------------------------------------------------------------------------
610 Procedure upd
611 (p_effective_date in date
612 ,p_datetrack_mode in varchar2
613 ,p_action_type_id in number
614 ,p_object_version_number in out nocopy number
615 ,p_name in varchar2 default hr_api.g_varchar2
616 ,p_procedure_name in varchar2 default hr_api.g_varchar2
617 ,p_description in varchar2 default hr_api.g_varchar2
618 ,p_dynamic_description in varchar2 default hr_api.g_varchar2
619 ,p_security_group_id in number default hr_api.g_number
620 ,p_description_query in varchar2 default hr_api.g_varchar2
621 ,p_start_date out nocopy date
622 ,p_end_date out nocopy date
623 ) is
624 --
625 l_rec ame_aty_shd.g_rec_type;
626 l_proc varchar2(72) := g_package||'upd';
627 --
628 Begin
629 hr_utility.set_location('Entering:'||l_proc, 5);
630 --
631 -- Call conversion function to turn arguments into the
632 -- l_rec structure.
633 --
634 l_rec :=
635 ame_aty_shd.convert_args
636 (p_action_type_id
637 ,p_name
638 ,p_procedure_name
639 ,p_start_date
640 ,p_end_date
641 ,p_description
642 ,p_security_group_id
643 ,p_dynamic_description
644 ,p_description_query
645 ,p_object_version_number
646 );
647 --
648 -- Having converted the arguments into the
649 -- plsql record structure we call the corresponding record
650 -- business process.
651 --
652 ame_aty_upd.upd
653 (p_effective_date
654 ,p_datetrack_mode
655 ,l_rec
656 );
657 --
658 -- Set the out parameters
659 --
660 p_object_version_number := l_rec.object_version_number;
661 p_start_date := l_rec.start_date;
662 p_end_date := l_rec.end_date;
663 --
664 --
665 hr_utility.set_location(' Leaving:'||l_proc, 10);
666 End upd;
667 --
668 end ame_aty_upd;