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