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