DBA Data[Home] [Help]

PACKAGE BODY: APPS.IRC_INO_INS

Source


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