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