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