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