1 Package Body hr_qsf_ins as
2 /* $Header: hrqsfrhi.pkb 120.1.12020000.3 2013/03/20 12:06:16 bmaheshw ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' hr_qsf_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_field_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_field_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_qsf_ins.g_field_id_i := p_field_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_qsf_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 --
83 -- Insert the row into: hr_quest_fields
84 --
85 insert into hr_quest_fields
86 ( field_id,
87 questionnaire_template_id,
88 name,
89 type,
90 html_text,
91 sql_required_flag,
92 sql_text,
93 object_version_number
94 ,validation_type
95 ,validation_detail
96 ,display_sequence
97 )
98 Values
99 ( p_rec.field_id,
100 p_rec.questionnaire_template_id,
101 p_rec.name,
102 p_rec.type,
103 p_rec.html_text,
104 p_rec.sql_required_flag,
105 p_rec.sql_text,
106 p_rec.object_version_number
107 ,p_rec.validation_type
108 ,p_rec.validation_detail
109 ,p_rec.display_sequence
110 );
111 --
112 --
113 hr_utility.set_location(' Leaving:'||l_proc, 10);
114 Exception
115 When hr_api.check_integrity_violated Then
116 -- A check constraint has been violated
117 hr_qsf_shd.constraint_error
118 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
119 When hr_api.parent_integrity_violated Then
120 -- Parent integrity has been violated
121 hr_qsf_shd.constraint_error
122 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
123 When hr_api.unique_integrity_violated Then
124 -- Unique integrity has been violated
125 hr_qsf_shd.constraint_error
126 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
127 When Others Then
128 Raise;
129 End insert_dml;
130 --
131 -- ----------------------------------------------------------------------------
132 -- |------------------------------< pre_insert >------------------------------|
133 -- ----------------------------------------------------------------------------
134 -- {Start Of Comments}
135 --
136 -- Description:
137 -- This private procedure contains any processing which is required before
138 -- the insert dml. Presently, if the entity has a corresponding primary
139 -- key which is maintained by an associating sequence, the primary key for
140 -- the entity will be populated with the next sequence value in
141 -- preparation for the insert dml.
142 --
143 -- Prerequisites:
144 -- This is an internal procedure which is called from the ins procedure.
145 --
146 -- In Parameters:
147 -- A Pl/Sql record structre.
148 --
149 -- Post Success:
150 -- Processing continues.
151 --
152 -- Post Failure:
153 -- If an error has occurred, an error message and exception will be raised
154 -- but not handled.
155 --
156 -- Developer Implementation Notes:
157 -- Any pre-processing required before the insert dml is issued should be
158 -- coded within this procedure. As stated above, a good example is the
159 -- generation of a primary key number via a corresponding sequence.
160 -- It is important to note that any 3rd party maintenance should be reviewed
161 -- before placing in this procedure.
162 --
163 -- Access Status:
164 -- Internal Row Handler Use Only.
165 --
166 -- {End Of Comments}
167 -- ----------------------------------------------------------------------------
168 Procedure pre_insert(p_rec in out nocopy hr_qsf_shd.g_rec_type) is
169 --
170 l_proc varchar2(72) := g_package||'pre_insert';
171 l_exists varchar2(1);
172 --
173 Cursor C_Sel1 is select hr_quest_fields_s.nextval from sys.dual;
174 --
175 Cursor C_Sel2 is
176 select null
177 from hr_quest_fields
178 where field_id = hr_qsf_ins.g_field_id_i;
179 --
180 Begin
181 hr_utility.set_location('Entering:'||l_proc, 5);
182 --
183 if hr_qsf_ins.g_field_id_i is not null then
184 --
185 -- Verify registered primary key values not already in use
186 --
187 Open C_Sel2;
188 Fetch C_Sel2 into l_exists;
189 If C_Sel2%found then
190 Close C_Sel2;
191 --
192 -- The primary key values are already in use.
193 --
194 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
195 fnd_message.set_token('TABLE_NAME','hr_questionnaires');
196 fnd_message.raise_error;
197 end if;
198 Close C_Sel2;
199 --
200 -- Use registered key values and clear globals
201 --
202 p_rec.field_id := hr_qsf_ins.g_field_id_i;
203 hr_qsf_ins.g_field_id_i := null;
204 --
205 else
206 --
207 -- Select the next sequence number
208 --
209 Open C_Sel1;
210 Fetch C_Sel1 Into p_rec.field_id;
211 Close C_Sel1;
212 end if;
213 --
214 hr_utility.set_location(' Leaving:'||l_proc, 10);
215 End pre_insert;
216 --
217 -- ----------------------------------------------------------------------------
218 -- |-----------------------------< post_insert >------------------------------|
219 -- ----------------------------------------------------------------------------
220 -- {Start Of Comments}
221 --
222 -- Description:
223 -- This private procedure contains any processing which is required after the
224 -- insert dml.
225 --
226 -- Prerequisites:
227 -- This is an internal procedure which is called from the ins procedure.
228 --
229 -- In Parameters:
230 -- A Pl/Sql record structre.
231 --
232 -- Post Success:
233 -- Processing continues.
234 --
235 -- Post Failure:
236 -- If an error has occurred, an error message and exception will be raised
237 -- but not handled.
238 --
239 -- Developer Implementation Notes:
240 -- Any post-processing required after the insert dml is issued should be
241 -- coded within this procedure. It is important to note that any 3rd party
242 -- maintenance should be reviewed before placing in this procedure.
243 --
244 -- Access Status:
245 -- Internal Row Handler Use Only.
246 --
247 -- {End Of Comments}
248 -- ----------------------------------------------------------------------------
249 Procedure post_insert(p_rec in hr_qsf_shd.g_rec_type
250 ,p_effective_date in date
251 ) is
252 --
253 l_proc varchar2(72) := g_package||'post_insert';
254 --
255 Begin
256 hr_utility.set_location('Entering:'||l_proc, 5);
257 --
258 begin
259 hr_qsf_rki.after_insert
260 (p_field_id => p_rec.field_id
261 ,p_questionnaire_template_id => p_rec.questionnaire_template_id
262 ,p_name => p_rec.name
263 ,p_type => p_rec.type
264 ,p_html_text => p_rec.html_text
265 ,p_sql_required_flag => p_rec.sql_required_flag
266 ,p_sql_text => p_rec.sql_text
267 ,p_object_version_number => p_rec.object_version_number
268 ,p_effective_date => p_effective_date
269 ,p_validation_type => p_rec.validation_type
270 ,p_validation_detail => p_rec.validation_detail
271 ,p_display_sequence => p_rec.display_sequence
272 );
273 exception
274 when hr_api.cannot_find_prog_unit then
275 hr_api.cannot_find_prog_unit_error
276 (p_module_name => 'HR_QUEST_FIELDS'
277 ,p_hook_type => 'AI'
278 );
279 end;
280 --
281 hr_utility.set_location(' Leaving:'||l_proc, 10);
282 End post_insert;
283 --
284 -- ----------------------------------------------------------------------------
285 -- |---------------------------------< ins >----------------------------------|
286 -- ----------------------------------------------------------------------------
287 Procedure ins
288 (
289 p_rec in out nocopy hr_qsf_shd.g_rec_type,
290 p_effective_date in date
291 ) is
292 --
293 l_proc varchar2(72) := g_package||'ins';
294 --
295 Begin
296 hr_utility.set_location('Entering:'||l_proc, 5);
297 --
298 -- Call the supporting insert validate operations
299 --
300 hr_qsf_bus.insert_validate(p_rec, p_effective_date);
301 --
302 hr_multi_message.end_validation_set;
303 -- Call the supporting pre-insert operation
304 --
305 pre_insert(p_rec);
306 --
307 -- Insert the row
308 --
309 insert_dml(p_rec);
310 --
311 -- Call the supporting post-insert operation
312 --
313 post_insert(p_rec, p_effective_date);
314 hr_multi_message.end_validation_set;
315 end ins;
316 --
317 -- ----------------------------------------------------------------------------
318 -- |---------------------------------< ins >----------------------------------|
319 -- ----------------------------------------------------------------------------
320 Procedure ins
321 (
322 p_field_id out nocopy number,
323 p_questionnaire_template_id in number,
324 p_name in varchar2,
325 p_type in varchar2,
326 p_html_text in CLOB,
327 p_sql_required_flag in varchar2,
328 p_sql_text in varchar2 default null,
329 p_object_version_number out nocopy number,
330 p_effective_date in date
331 ,p_validation_type in varchar2
332 ,p_validation_detail in varchar2
333 ,p_display_sequence in number
334 ) is
335 --
336 l_rec hr_qsf_shd.g_rec_type;
337 l_proc varchar2(72) := g_package||'ins';
338 --
339 Begin
340 hr_utility.set_location('Entering:'||l_proc, 5);
341 --
342 -- Call conversion function to turn arguments into the
343 -- p_rec structure.
344 --
345 l_rec :=
346 hr_qsf_shd.convert_args
347 (
348 null,
349 p_questionnaire_template_id,
350 p_name,
351 p_type,
352 p_html_text,
353 p_sql_required_flag,
354 p_sql_text,
355 null
356 ,p_validation_type
357 ,p_validation_detail
358 ,p_display_sequence
359 );
360 --
361 -- Having converted the arguments into the hr_qsf_rec
362 -- plsql record structure we call the corresponding record business process.
363 --
364 ins(l_rec, p_effective_date);
365 --
366 -- As the primary key argument(s)
367 -- are specified as an OUT's we must set these values.
368 --
369 p_field_id := l_rec.field_id;
370 p_object_version_number := l_rec.object_version_number;
371 --
372 hr_utility.set_location(' Leaving:'||l_proc, 10);
373 End ins;
374 --
375 end hr_qsf_ins;