DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_ATU_INS

Source


1 Package Body ame_atu_ins as
2 /* $Header: amaturhi.pkb 120.6 2006/02/15 04:04 prasashe noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ame_atu_ins.';  -- Global package name
9 --
10 -- The following global variables are only to be used by
11 -- the set_base_key_value and pre_insert procedures.
12 --
13 g_attribute_id_i  number   default null;
14 g_application_id_i  number   default null;
15 --
16 -- ----------------------------------------------------------------------------
17 -- |------------------------< set_base_key_value >----------------------------|
18 -- ----------------------------------------------------------------------------
19 procedure set_base_key_value
20   (p_attribute_id  in  number
21   ,p_application_id  in  number) is
22 --
23   l_proc       varchar2(72) := g_package||'set_base_key_value';
24 --
25 Begin
26   hr_utility.set_location('Entering:'||l_proc, 10);
27   --
28   ame_atu_ins.g_attribute_id_i := p_attribute_id;
29   ame_atu_ins.g_application_id_i := p_application_id;
30   --
31   hr_utility.set_location(' Leaving:'||l_proc, 20);
32 End set_base_key_value;
33 --
34 --
35 -- ----------------------------------------------------------------------------
36 -- |----------------------------< dt_insert_dml >-----------------------------|
37 -- ----------------------------------------------------------------------------
38 -- {Start Of Comments}
39 --
40 -- Description:
41 --   This procedure controls the actual dml insert logic for datetrack. The
42 --   functions of this procedure are as follows:
43 --   1) Get the object_version_number.
44 --   2) To set the effective start and end dates to the corresponding
45 --      validation start and end dates. Also, the object version number
46 --      record attribute is set.
47 --   3) To set and unset the g_api_dml status as required (as we are about to
48 --      perform dml).
49 --   4) To insert the row into the schema with the derived effective start
50 --      and end dates and the object version number.
51 --   5) To trap any constraint violations that may have occurred.
52 --   6) To raise any other errors.
53 --
54 -- Prerequisites:
55 --   This is an internal private procedure which must be called from the
56 --   insert_dml and pre_update (logic permitting) procedure and must have
57 --   all mandatory arguments set.
58 --
59 -- In Parameters:
60 --   A Pl/Sql record structure.
61 --
62 -- Post Success:
63 --   The specified row will be inserted into the schema.
64 --
65 -- Post Failure:
66 --   On the insert dml failure it is important to note that we always reset the
67 --   g_api_dml status to false.
68 --   If a check or unique integrity constraint violation is raised the
69 --   constraint_error procedure will be called.
70 --   If any other error is reported, the error will be raised after the
71 --   g_api_dml status is reset.
72 --
73 -- Developer Implementation Notes:
74 --   This is an internal datetrack maintenance procedure which should
75 --   not be modified in anyway.
76 --
77 -- Access Status:
78 --   Internal Row Handler Use Only.
79 --
80 -- {End Of Comments}
81 -- ----------------------------------------------------------------------------
82 Procedure dt_insert_dml
83   (p_rec                     in out nocopy ame_atu_shd.g_rec_type
84   ,p_effective_date          in date
85   ,p_datetrack_mode          in varchar2
86   ,p_validation_start_date   in date
87   ,p_validation_end_date     in date
88   ) is
89 -- Cursor to select 'old' created AOL who column values
90 --
91   Cursor C_Sel1 Is
92     select t.creation_date
93     from   ame_attribute_usages t
94     where t.attribute_id = p_rec.attribute_id
95  and    t.application_id = p_rec.application_id
96     and    t.start_date =
97              ame_atu_shd.g_old_rec.start_date
98     and    t.end_date   = p_validation_start_date;
99 --
100    Cursor C_Sel2 Is
101     select created_by
102       from ame_attribute_usages t
103      where t.attribute_id = p_rec.attribute_id
104  and    t.application_id = p_rec.application_id
105        and ame_utility_pkg.is_seed_user(created_by) = ame_util.seededDataCreatedById
106        and rownum<2;
107 --
108   l_proc                varchar2(72) := g_package||'dt_insert_dml';
109   l_created_by          ame_attribute_usages.created_by%TYPE;
110   l_creation_date       ame_attribute_usages.creation_date%TYPE;
111   l_last_update_date    ame_attribute_usages.last_update_date%TYPE;
112   l_last_updated_by     ame_attribute_usages.last_updated_by%TYPE;
113   l_last_update_login   ame_attribute_usages.last_update_login%TYPE;
114   l_current_user_id     integer;
115   l_temp_count          integer;
116 --
117 Begin
118   hr_utility.set_location('Entering:'||l_proc, 5);
119   --
120   -- Set the effective start and end dates to the corresponding
121   -- validation start and end dates
122   --
123   p_rec.start_date  := p_validation_start_date;
124   p_rec.end_date    := p_validation_end_date;
125   l_current_user_id := fnd_global.user_id;
126   --
127   -- If the datetrack_mode is not INSERT then we must populate the WHO
128   -- columns with the 'old' creation values and 'new' updated values.
129   --
130   If (p_datetrack_mode <> hr_api.g_insert) then
131     hr_utility.set_location(l_proc, 10);
132     --
133       -- Get the object version number for the insert
134   --
135   p_rec.object_version_number :=
136    ame_atu_shd.get_object_version_number
137       (p_attribute_id =>  p_rec.attribute_id
138  ,p_application_id =>  p_rec.application_id
139       );
140   --
141     -- Select the 'old' created values
142     --
143     Open C_Sel1;
144     Fetch C_Sel1 Into l_creation_date;
145     If C_Sel1%notfound Then
146       --
147       -- The previous 'old' created row has not been found. We need
148       -- to error as an internal datetrack problem exists.
149       --
150       Close C_Sel1;
151       fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
152       fnd_message.set_token('PROCEDURE', l_proc);
153       fnd_message.set_token('STEP','10');
154       fnd_message.raise_error;
155     End If;
156     Close C_Sel1;
157     --
158     --
159     Open C_Sel2;
160     Fetch C_Sel2 Into l_temp_count;
161     if C_Sel2%found then
162       l_created_by := l_temp_count;
163     else
164       l_created_by := l_current_user_id;
165     end if;
166     Close C_Sel2;
167     --
168     -- Set the AOL updated WHO values
169     --
170     l_last_update_date   := sysdate;
171     l_last_updated_by    := l_current_user_id;
172     l_last_update_login  := l_current_user_id;
173   Else
174     p_rec.object_version_number := 1;  -- Initialise the object version
175     --
176     -- If the current user logged in using AME Developer responsibility
177     -- then the created_by value should be ame_util.seededDataCreatedById
178     --
179     if fnd_global.resp_name = 'AME Developer' then
180       l_created_by         := ame_util.seededDataCreatedById;
181     else
182       l_created_by         := l_current_user_id;
183     end if;
184     l_creation_date      := sysdate;
185     l_last_update_date   := sysdate;
186     l_last_updated_by    := l_current_user_id;
187     l_last_update_login  := l_current_user_id;
188   End If;
189   --
190   --
191   --
192   -- Insert the row into: ame_attribute_usages
193   --
194   insert into ame_attribute_usages
195       (attribute_id
196       ,application_id
197       ,query_string
198       ,use_count
199       ,user_editable
200       ,is_static
201       ,start_date
202       ,end_date
203       ,security_group_id
204       ,value_set_id
205       ,object_version_number
206       ,created_by
207       ,creation_date
208       ,last_update_date
209       ,last_updated_by
210       ,last_update_login
211       )
212   Values
213     (p_rec.attribute_id
214     ,p_rec.application_id
215     ,p_rec.query_string
216     ,p_rec.use_count
217     ,p_rec.user_editable
218     ,p_rec.is_static
219     ,p_rec.start_date
220     ,p_rec.end_date
221     ,p_rec.security_group_id
222     ,p_rec.value_set_id
223     ,p_rec.object_version_number
224     ,l_created_by
225     ,l_creation_date
226     ,l_last_update_date
227     ,l_last_updated_by
228     ,l_last_update_login
229     );
230   --
231   --
232   hr_utility.set_location(' Leaving:'||l_proc, 15);
233 --
234 Exception
235   When hr_api.check_integrity_violated Then
236     -- A check constraint has been violated
237     --
238     ame_atu_shd.constraint_error
239       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
240   When hr_api.unique_integrity_violated Then
241     -- Unique integrity has been violated
242     --
243     ame_atu_shd.constraint_error
244       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
245   When Others Then
246     --
247     Raise;
248 End dt_insert_dml;
249 --
250 -- ----------------------------------------------------------------------------
251 -- |------------------------------< insert_dml >------------------------------|
252 -- ----------------------------------------------------------------------------
253 Procedure insert_dml
254   (p_rec                   in out nocopy ame_atu_shd.g_rec_type
255   ,p_effective_date        in date
256   ,p_datetrack_mode        in varchar2
257   ,p_validation_start_date in date
258   ,p_validation_end_date   in date
259   ) is
260 --
261   l_proc        varchar2(72) := g_package||'insert_dml';
262 --
263 Begin
264   hr_utility.set_location('Entering:'||l_proc, 5);
265   --
266   ame_atu_ins.dt_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   --
274   hr_utility.set_location(' Leaving:'||l_proc, 10);
275 End insert_dml;
276 --
277 -- ----------------------------------------------------------------------------
278 -- |------------------------------< pre_insert >------------------------------|
279 -- ----------------------------------------------------------------------------
280 -- {Start Of Comments}
281 --
282 -- Description:
283 --   This private procedure contains any processing which is required before
284 --   the insert dml. Presently, if the entity has a corresponding primary
285 --   key which is maintained by an associating sequence, the primary key for
286 --   the entity will be populated with the next sequence value in
287 --   preparation for the insert dml.
288 --   Also, if comments are defined for this entity, the comments insert
289 --   logic will also be called, generating a comment_id if required.
290 --
291 -- Prerequisites:
292 --   This is an internal procedure which is called from the ins procedure.
293 --
294 -- In Parameters:
295 --   A Pl/Sql record structure.
296 --
297 -- Post Success:
298 --   Processing continues.
299 --
300 -- Post Failure:
301 --   If an error has occurred, an error message and exception will be raised
302 --   but not handled.
303 --
304 -- Developer Implementation Notes:
305 --   Any pre-processing required before the insert dml is issued should be
306 --   coded within this procedure. As stated above, a good example is the
307 --   generation of a primary key number via a corresponding sequence.
308 --   It is important to note that any 3rd party maintenance should be reviewed
309 --   before placing in this procedure.
310 --
311 -- Access Status:
312 --   Internal Row Handler Use Only.
313 --
314 -- {End Of Comments}
315 -- ----------------------------------------------------------------------------
316 Procedure pre_insert
317   (p_rec                   in out nocopy ame_atu_shd.g_rec_type
318   ,p_effective_date        in date
319   ,p_datetrack_mode        in varchar2
320   ,p_validation_start_date in date
321   ,p_validation_end_date   in date
322   ) is
323 --
324  Cursor C_Sel2 is
325     Select null
326       from ame_attribute_usages
327      where attribute_id =
328              ame_atu_ins.g_attribute_id_i
329        and application_id =
330              ame_atu_ins.g_application_id_i
331        and p_effective_date between start_date
332              and nvl(end_date - ame_util.oneSecond , p_effective_date);
333 --
334   l_proc        varchar2(72) := g_package||'pre_insert';
335   l_exists      varchar2(1);
336 --
337 Begin
338   hr_utility.set_location('Entering:'||l_proc, 5);
339   --
340     If (ame_atu_ins.g_attribute_id_i is not null or
341       ame_atu_ins.g_application_id_i is not null) Then
342     --
343     -- Verify registered primary key values not already in use
344     --
345     Open C_Sel2;
346     Fetch C_Sel2 into l_exists;
347     If C_Sel2%found Then
348        Close C_Sel2;
349        --
350        -- The primary key values are already in use.
351        --
352        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
353        fnd_message.set_token('TABLE_NAME','ame_attribute_usages');
354        fnd_message.raise_error;
355     End If;
356     Close C_Sel2;
357     --
358     -- Use registered key values and clear globals
359     --
360     p_rec.attribute_id :=
361       ame_atu_ins.g_attribute_id_i;
362     ame_atu_ins.g_attribute_id_i := null;
363     p_rec.application_id :=
364       ame_atu_ins.g_application_id_i;
365     ame_atu_ins.g_application_id_i := null;
366   End If;
367   --
368   --
369   hr_utility.set_location(' Leaving:'||l_proc, 10);
370 End pre_insert;
371 --
372 -- ----------------------------------------------------------------------------
376 --
373 -- |----------------------------< post_insert >-------------------------------|
374 -- ----------------------------------------------------------------------------
375 -- {Start Of Comments}
377 -- Description:
378 --   This private procedure contains any processing which is required after
379 --   the insert dml.
380 --
381 -- Prerequisites:
382 --   This is an internal procedure which is called from the ins procedure.
383 --
384 -- In Parameters:
385 --   A Pl/Sql record structure.
386 --
387 -- Post Success:
388 --   Processing continues.
389 --
390 -- Post Failure:
391 --   If an error has occurred, an error message and exception will be raised
392 --   but not handled.
393 --
394 -- Developer Implementation Notes:
395 --   Any post-processing required after the insert dml is issued should be
396 --   coded within this procedure. It is important to note that any 3rd party
397 --   maintenance should be reviewed before placing in this procedure.
398 --
399 -- Access Status:
400 --   Internal Row Handler Use Only.
401 --
402 -- {End Of Comments}
403 -- ----------------------------------------------------------------------------
404 Procedure post_insert
405   (p_rec                   in ame_atu_shd.g_rec_type
406   ,p_effective_date        in date
407   ,p_datetrack_mode        in varchar2
408   ,p_validation_start_date in date
409   ,p_validation_end_date   in date
410   ) is
411 --
412   l_proc        varchar2(72) := g_package||'post_insert';
413 --
414 Begin
415   hr_utility.set_location('Entering:'||l_proc, 5);
416   begin
417     --
418     ame_atu_rki.after_insert
419       (p_effective_date
420       => p_effective_date
421       ,p_validation_start_date
422       => p_validation_start_date
423       ,p_validation_end_date
424       => p_validation_end_date
425       ,p_attribute_id
426       => p_rec.attribute_id
427       ,p_application_id
428       => p_rec.application_id
429       ,p_query_string
430       => p_rec.query_string
431       ,p_use_count
432       => p_rec.use_count
433       ,p_user_editable
434       => p_rec.user_editable
435       ,p_is_static
436       => p_rec.is_static
437       ,p_start_date
438       => p_rec.start_date
439       ,p_end_date
440       => p_rec.end_date
441       ,p_security_group_id
442       => p_rec.security_group_id
443       ,p_value_set_id
444       => p_rec.value_set_id
445       ,p_object_version_number
446       => p_rec.object_version_number
447       );
448     --
449   exception
450     --
451     when hr_api.cannot_find_prog_unit then
452       --
453       hr_api.cannot_find_prog_unit_error
454         (p_module_name => 'AME_ATTRIBUTE_USAGES'
455         ,p_hook_type   => 'AI');
456       --
457   end;
458   --
459   hr_utility.set_location(' Leaving:'||l_proc, 10);
460 End post_insert;
461 --
462 -- ----------------------------------------------------------------------------
463 -- |-------------------------------< ins_lck >--------------------------------|
464 -- ----------------------------------------------------------------------------
465 -- {Start Of Comments}
466 --
467 -- Description:
468 --   The ins_lck process has one main function to perform. When inserting
469 --   a datetracked row, we must validate the DT mode.
470 --
471 -- Prerequisites:
472 --   This procedure can only be called for the datetrack mode of INSERT.
473 --
474 -- In Parameters:
475 --
476 -- Post Success:
477 --   On successful completion of the ins_lck process the parental
478 --   datetracked rows will be locked providing the p_enforce_foreign_locking
479 --   argument value is TRUE.
480 --   If the p_enforce_foreign_locking argument value is FALSE then the
481 --   parential rows are not locked.
482 --
483 -- Post Failure:
484 --   The Lck process can fail for:
485 --   1) When attempting to lock the row the row could already be locked by
486 --      another user. This will raise the HR_Api.Object_Locked exception.
487 --   2) When attempting to the lock the parent which doesn't exist.
488 --      For the entity to be locked the parent must exist!
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 ins_lck
499   (p_effective_date        in date
500   ,p_datetrack_mode        in varchar2
501   ,p_rec                   in ame_atu_shd.g_rec_type
502   ,p_validation_start_date out nocopy date
503   ,p_validation_end_date   out nocopy date
504   ) is
505 --
506   l_dummy                 varchar2(10);
507   l_proc                  varchar2(72) := g_package||'ins_lck';
508   l_validation_start_date date;
509   l_validation_end_date   date;
510 --
511 Begin
512   hr_utility.set_location('Entering:'||l_proc, 5);
513   --
514   -- Validate the datetrack mode mode getting the validation start
515   -- and end dates for the specified datetrack operation.
516   --
517   --
518   -- Set the validation start and end date OUT arguments
519   --
520 --  p_validation_start_date := l_validation_start_date;
521 --  p_validation_end_date   := l_validation_end_date;
522 -- MURTHY_CHANGES
523   p_validation_start_date := sysdate;
524   p_validation_end_date   := ame_utility_pkg.endOfTime;
525   -- lock the parent rows
526   begin
527     select null
528       into l_dummy
529       from ame_attributes
530       where attribute_id = p_rec.attribute_id
531        and  p_effective_date between start_date and
532                  nvl(end_date - ame_util.oneSecond, p_effective_date)
533        for update of end_date nowait;
534   exception
535     when others then
536     --
537     fnd_message.set_name('PER', 'AME_400478_CANNOT_LOCK_PARENT');
538     fnd_message.raise_error;
539   end;
540   --
541   hr_utility.set_location(' Leaving:'||l_proc, 20);
542   --
543 End ins_lck;
544 --
545 -- ----------------------------------------------------------------------------
546 -- |---------------------------------< ins >----------------------------------|
547 -- ----------------------------------------------------------------------------
548 Procedure ins
549   (p_effective_date in     date
550   ,p_rec            in out nocopy ame_atu_shd.g_rec_type
551   ) is
552 --
553   l_proc                        varchar2(72) := g_package||'ins';
554   l_datetrack_mode              varchar2(30) := hr_api.g_insert;
555   l_validation_start_date       date;
556   l_validation_end_date         date;
557 --
558 Begin
559   hr_utility.set_location('Entering:'||l_proc, 5);
560   --
561   -- Call the lock operation
562   --
563   hr_utility.set_location('Entering:'||l_proc, 15);
564   ame_atu_ins.ins_lck
565     (p_effective_date        => p_effective_date
566     ,p_datetrack_mode        => l_datetrack_mode
567     ,p_rec                   => p_rec
568     ,p_validation_start_date => l_validation_start_date
569     ,p_validation_end_date   => l_validation_end_date
570     );
571   --
572   -- Call the supporting insert validate operations
573   --
574   hr_utility.set_location('Entering:'||l_proc, 25);
575   ame_atu_bus.insert_validate
576     (p_rec                   => p_rec
577     ,p_effective_date        => p_effective_date
578     ,p_datetrack_mode        => l_datetrack_mode
579     ,p_validation_start_date => l_validation_start_date
580     ,p_validation_end_date   => l_validation_end_date
581     );
582   --
583   -- Call to raise any errors on multi-message list
584   hr_multi_message.end_validation_set;
585   --
586   -- Call the supporting pre-insert operation
587   --
588   hr_utility.set_location('Entering:'||l_proc, 35);
589   ame_atu_ins.pre_insert
590     (p_rec                   => p_rec
591     ,p_effective_date        => p_effective_date
592     ,p_datetrack_mode        => l_datetrack_mode
593     ,p_validation_start_date => l_validation_start_date
594     ,p_validation_end_date   => l_validation_end_date
595     );
596   --
597   -- Insert the row
598   --
599   hr_utility.set_location('Entering:'||l_proc, 45);
600   ame_atu_ins.insert_dml
601     (p_rec                   => p_rec
602     ,p_effective_date        => p_effective_date
603     ,p_datetrack_mode        => l_datetrack_mode
604     ,p_validation_start_date => l_validation_start_date
605     ,p_validation_end_date   => l_validation_end_date
606     );
607   --
608   -- Call the supporting post-insert operation
609   --
610   hr_utility.set_location('Entering:'||l_proc, 55);
611   ame_atu_ins.post_insert
612     (p_rec                   => p_rec
613     ,p_effective_date        => p_effective_date
614     ,p_datetrack_mode        => l_datetrack_mode
615     ,p_validation_start_date => l_validation_start_date
616     ,p_validation_end_date   => l_validation_end_date
617     );
618   --
619   -- Call to raise any errors on multi-message list
620   hr_multi_message.end_validation_set;
621   --
622   hr_utility.set_location('Leaving:'||l_proc,10);
623 end ins;
624 --
625 -- ----------------------------------------------------------------------------
626 -- |---------------------------------< ins >----------------------------------|
627 -- ----------------------------------------------------------------------------
628 Procedure ins
629   (p_attribute_id                   in     number
630   ,p_application_id                 in     number
631   ,p_effective_date                 in     date
632   ,p_use_count                      in     number
633   ,p_query_string                   in     varchar2 default null
634   ,p_user_editable                  in     varchar2 default ame_util.booleanTrue
635   ,p_is_static                      in     varchar2 default ame_util.booleanTrue
636   ,p_security_group_id              in     number   default null
637   ,p_value_set_id                   in     number   default null
638   ,p_object_version_number             out nocopy number
639   ,p_start_date                        out nocopy date
640   ,p_end_date                          out nocopy date
641   ) is
642 --
643   l_rec         ame_atu_shd.g_rec_type;
644   l_proc        varchar2(72) := g_package||'ins';
645 --
646 Begin
647   hr_utility.set_location('Entering:'||l_proc, 5);
648   --
649   -- Call conversion function to turn arguments into the
650   -- p_rec structure.
651   --
652   l_rec :=
653   ame_atu_shd.convert_args
654     (p_attribute_id
655     ,p_application_id
656     ,p_query_string
657     ,p_use_count
658     ,p_user_editable
659     ,p_is_static
660     ,null
661     ,null
662     ,p_security_group_id
663     ,p_value_set_id
664     ,null
665     );
666   --
667   -- Having converted the arguments into the ame_atu_rec
668   -- plsql record structure we call the corresponding record
669   -- business process.
670   --
671   ame_atu_ins.ins
672     (p_effective_date
673     ,l_rec
674     );
675   --
676   -- Set the OUT arguments.
677   --
678   p_start_date             := l_rec.start_date;
679   p_end_date               := l_rec.end_date;
680   p_object_version_number            := l_rec.object_version_number;
681   --
682   --
683   hr_utility.set_location(' Leaving:'||l_proc, 10);
684 End ins;
685 --
686 end ame_atu_ins;