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