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