DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_QSA_INS

Source


1 Package Body hr_qsa_ins as
2 /* $Header: hrqsarhi.pkb 115.12 2003/08/27 00:16:05 hpandya ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)  := '  hr_qsa_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_questionnaire_answer_id_i  number   default null;
14 -- ----------------------------------------------------------------------------
15 -- |------------------------< set_base_key_value >----------------------------|
16 -- ----------------------------------------------------------------------------
17 procedure set_base_key_value
18   (p_questionnaire_answer_id  in  number) is
19 --
20   l_proc       varchar2(72) := g_package||'set_base_key_value';
21 --
22 Begin
23   hr_utility.set_location('Entering:'||l_proc, 10);
24   --
25   hr_qsa_ins.g_questionnaire_answer_id_i := p_questionnaire_answer_id;
26   --
27   hr_utility.set_location(' Leaving:'||l_proc, 20);
28 End set_base_key_value;
29 --
30 -- ----------------------------------------------------------------------------
31 -- |------------------------------< insert_dml >------------------------------|
32 -- ----------------------------------------------------------------------------
33 -- {Start Of Comments}
34 --
35 -- Description:
36 --   This procedure controls the actual dml insert logic. The processing of
37 --   this procedure are as follows:
38 --   1) Initialise the object_version_number to 1 if the object_version_number
39 --      is defined as an attribute for this entity.
40 --   2) To set and unset the g_api_dml status as required (as we are about to
41 --      perform dml).
42 --   3) To insert the row into the schema.
43 --   4) To trap any constraint violations that may have occurred.
44 --   5) To raise any other errors.
45 --
46 -- Prerequisites:
47 --   This is an internal private procedure which must be called from the ins
48 --   procedure and must have all mandatory attributes set (except the
49 --   object_version_number which is initialised within this procedure).
50 --
51 -- In Parameters:
52 --   A Pl/Sql record structre.
53 --
54 -- Post Success:
55 --   The specified row will be inserted into the schema.
56 --
57 -- Post Failure:
58 --   On the insert dml failure it is important to note that we always reset the
59 --   g_api_dml status to false.
60 --   If a check, unique or parent integrity constraint violation is raised the
61 --   constraint_error procedure will be called.
62 --   If any other error is reported, the error will be raised after the
63 --   g_api_dml status is reset.
64 --
65 -- Developer Implementation Notes:
66 --   None.
67 --
68 -- Access Status:
69 --   Internal Row Handler Use Only.
70 --
71 -- {End Of Comments}
72 -- ----------------------------------------------------------------------------
73 Procedure insert_dml(p_rec in out nocopy hr_qsa_shd.g_rec_type) is
74 --
75   l_proc  varchar2(72) := g_package||'insert_dml';
76 --
77 Begin
78   hr_utility.set_location('Entering:'||l_proc, 5);
79   --
80   --
81   -- Insert the row into: hr_quest_answers
82   --
83   insert into hr_quest_answers
84   (  questionnaire_answer_id,
85   questionnaire_template_id,
86   type,
87   type_object_id,
88   business_group_id
89   )
90   Values
91   (  p_rec.questionnaire_answer_id,
92   p_rec.questionnaire_template_id,
93   p_rec.type,
94   p_rec.type_object_id,
95   p_rec.business_group_id
96   );
97   --
98   hr_utility.set_location(' Leaving:'||l_proc, 10);
99 Exception
100   When hr_api.check_integrity_violated Then
101     -- A check constraint has been violated
102     hr_qsa_shd.constraint_error
103       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
104   When hr_api.parent_integrity_violated Then
105     -- Parent integrity has been violated
106     hr_qsa_shd.constraint_error
107       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
108   When hr_api.unique_integrity_violated Then
109     -- Unique integrity has been violated
110     hr_qsa_shd.constraint_error
111       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
112   When Others Then
113     Raise;
114 End insert_dml;
115 --
116 -- ----------------------------------------------------------------------------
117 -- |------------------------------< pre_insert >------------------------------|
118 -- ----------------------------------------------------------------------------
119 -- {Start Of Comments}
120 --
121 -- Description:
122 --   This private procedure contains any processing which is required before
123 --   the insert dml. Presently, if the entity has a corresponding primary
124 --   key which is maintained by an associating sequence, the primary key for
125 --   the entity will be populated with the next sequence value in
126 --   preparation for the insert dml.
127 --
128 -- Prerequisites:
129 --   This is an internal procedure which is called from the ins procedure.
130 --
131 -- In Parameters:
132 --   A Pl/Sql record structre.
133 --
134 -- Post Success:
135 --   Processing continues.
136 --
137 -- Post Failure:
138 --   If an error has occurred, an error message and exception will be raised
139 --   but not handled.
140 --
141 -- Developer Implementation Notes:
142 --   Any pre-processing required before the insert dml is issued should be
143 --   coded within this procedure. As stated above, a good example is the
144 --   generation of a primary key number via a corresponding sequence.
145 --   It is important to note that any 3rd party maintenance should be reviewed
146 --   before placing in this procedure.
147 --
148 -- Access Status:
149 --   Internal Row Handler Use Only.
150 --
151 -- {End Of Comments}
152 -- ----------------------------------------------------------------------------
153 Procedure pre_insert(p_rec  in out nocopy hr_qsa_shd.g_rec_type) is
154 --
155   l_proc  varchar2(72) := g_package||'pre_insert';
156   l_exists  varchar2(1);
157 --
158   Cursor C_Sel1 is select hr_quest_answers_s.nextval from sys.dual;
159 --
160   Cursor C_Sel2 is
161          select null
162                 from hr_quest_answers
163                 where questionnaire_answer_id = hr_qsa_ins.g_questionnaire_answer_id_i;
164 --
165 Begin
166   hr_utility.set_location('Entering:'||l_proc, 5);
167   --
168   if hr_qsa_ins.g_questionnaire_answer_id_i is not null then
169     --
170     -- Verify registered primary key values not already in use
171     --
172     Open C_Sel2;
173     Fetch C_Sel2 into l_exists;
174     If C_Sel2%found then
175       Close C_Sel2;
176       --
177       -- The primary key values are already in use.
178       --
179       fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
180       fnd_message.set_token('TABLE_NAME','hr_questionnaires');
181       fnd_message.raise_error;
182     end if;
183     Close C_Sel2;
184     --
185     -- Use registered key values and clear globals
186     --
187     p_rec.questionnaire_answer_id := hr_qsa_ins.g_questionnaire_answer_id_i;
188     hr_qsa_ins.g_questionnaire_answer_id_i := null;
189   else
190     --
191   -- Select the next sequence number
192   --
193   Open C_Sel1;
194   Fetch C_Sel1 Into p_rec.questionnaire_answer_id;
195   Close C_Sel1;
196   --
197   end if;
198   --
199   hr_utility.set_location(' Leaving:'||l_proc, 10);
200 End pre_insert;
201 --
202 -- ----------------------------------------------------------------------------
203 -- |-----------------------------< post_insert >------------------------------|
204 -- ----------------------------------------------------------------------------
205 -- {Start Of Comments}
206 --
207 -- Description:
208 --   This private procedure contains any processing which is required after the
209 --   insert dml.
210 --
211 -- Prerequisites:
212 --   This is an internal procedure which is called from the ins procedure.
213 --
214 -- In Parameters:
215 --   A Pl/Sql record structre.
216 --
217 -- Post Success:
218 --   Processing continues.
219 --
220 -- Post Failure:
221 --   If an error has occurred, an error message and exception will be raised
222 --   but not handled.
223 --
224 -- Developer Implementation Notes:
225 --   Any post-processing required after the insert dml is issued should be
226 --   coded within this procedure. It is important to note that any 3rd party
227 --   maintenance should be reviewed before placing in this procedure.
228 --
229 -- Access Status:
230 --   Internal Row Handler Use Only.
231 --
232 -- {End Of Comments}
233 -- ----------------------------------------------------------------------------
234 Procedure post_insert(p_rec in hr_qsa_shd.g_rec_type
235          ,p_effective_date in date
236          ) is
237 --
238   l_proc  varchar2(72) := g_package||'post_insert';
239 --
240 Begin
241   hr_utility.set_location('Entering: '||l_proc, 5);
242   --
243   begin
244   hr_qsa_rki.after_insert
245     (p_questionnaire_answer_id   => p_rec.questionnaire_answer_id
246     ,p_questionnaire_template_id => p_rec.questionnaire_template_id
247     ,p_type           => p_rec.type
248     ,p_type_object_id       => p_rec.type_object_id
249     ,p_business_group_id       => p_rec.business_group_id
250     ,p_effective_date        => p_effective_date
251     );
252   exception
253   when hr_api.cannot_find_prog_unit then
254     hr_api.cannot_find_prog_unit_error
255       (p_module_name => 'HR_QUEST_ANSWERS'
256       ,p_hook_type   => 'AI'
257       );
258   end;
259   --
260   hr_utility.set_location(' Leaving:'||l_proc, 10);
261 End post_insert;
262 --
263 -- ----------------------------------------------------------------------------
264 -- |---------------------------------< ins >----------------------------------|
265 -- ----------------------------------------------------------------------------
266 Procedure ins
267   (
268   p_rec        in out nocopy hr_qsa_shd.g_rec_type,
269   p_effective_date  in date
270   ) is
271 --
272   l_proc  varchar2(72) := g_package||'ins';
273 --
274 Begin
275   hr_utility.set_location('Entering:'||l_proc, 5);
276   --
277   -- Call the supporting insert validate operations
278   --
279   hr_qsa_bus.insert_validate(p_rec, p_effective_date);
280   --
281   -- Call the supporting pre-insert operation
282   --
283   pre_insert(p_rec);
284   --
285   -- Insert the row
286   --
287   insert_dml(p_rec);
288   --
289   -- Call the supporting post-insert operation
290   --
291   post_insert(p_rec, p_effective_date);
292 end ins;
293 --
294 -- ----------------------------------------------------------------------------
295 -- |---------------------------------< ins >----------------------------------|
296 -- ----------------------------------------------------------------------------
297 Procedure ins
298   (
299   p_questionnaire_answer_id      out nocopy number,
300   p_questionnaire_template_id    in number,
301   p_type                         in varchar2,
302   p_type_object_id               in number,
303   p_business_group_id            in number,
304   p_effective_date     in date
305   ) is
306 --
307   l_rec    hr_qsa_shd.g_rec_type;
308   l_proc  varchar2(72) := g_package||'ins';
309 --
310 Begin
311   hr_utility.set_location('Entering:'||l_proc, 5);
312   --
313   -- Call conversion function to turn arguments into the
314   -- p_rec structure.
315   --
316   l_rec :=
317   hr_qsa_shd.convert_args
318   (
319   null,
320   p_questionnaire_template_id,
321   p_type,
322   p_type_object_id,
323   p_business_group_id
324   );
325   --
326   -- Having converted the arguments into the hr_qsa_rec
327   -- plsql record structure we call the corresponding record business process.
328   --
329   ins(l_rec, p_effective_date);
330   --
331   -- As the primary key argument(s)
332   -- are specified as an OUT's we must set these values.
333   --
334   p_questionnaire_answer_id := l_rec.questionnaire_answer_id;
335   --
336   --
337   hr_utility.set_location(' Leaving:'||l_proc, 10);
338 End ins;
339 --
340 end hr_qsa_ins;