1 Package Body hr_ort_ins as
2 /* $Header: hrortrhi.pkb 115.4 2004/06/29 00:31:44 kjagadee noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' hr_ort_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_organization_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_organization_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_ort_ins.g_organization_id_i := p_organization_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
75 (p_rec in out nocopy hr_ort_shd.g_rec_type
76 ) is
77 --
78 l_proc varchar2(72) := g_package||'insert_dml';
79 --
80 Begin
81 hr_utility.set_location('Entering:'||l_proc, 5);
82 --
83 --
84 --
85 --
86 -- Insert the row into: hr_all_organization_units_tl
87 --
88 insert into hr_all_organization_units_tl
89 (organization_id
90 ,language
91 ,source_lang
92 ,name
93 )
94 Values
95 (p_rec.organization_id
96 ,p_rec.language
97 ,p_rec.source_lang
98 ,p_rec.name
99 );
100 --
101 --
102 --
103 hr_utility.set_location(' Leaving:'||l_proc, 10);
104 Exception
105 When hr_api.check_integrity_violated Then
106 -- A check constraint has been violated
107 --
108 hr_ort_shd.constraint_error
109 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
110 When hr_api.parent_integrity_violated Then
111 -- Parent integrity has been violated
112 --
113 hr_ort_shd.constraint_error
114 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
115 When hr_api.unique_integrity_violated Then
116 -- Unique integrity has been violated
117 --
118 hr_ort_shd.constraint_error
119 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
120 When Others Then
121 --
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
163 (p_rec in out nocopy hr_ort_shd.g_rec_type
164 ,p_organization_id in number
165 ) is
166 --
167 l_proc varchar2(72) := g_package||'pre_insert';
168 --
169 Begin
170 hr_utility.set_location('Entering:'||l_proc, 5);
171 --
172 p_rec.organization_id := p_organization_id;
173 --
174 hr_utility.set_location(' Leaving:'||l_proc, 10);
175 End pre_insert;
176 --
177 -- ----------------------------------------------------------------------------
178 -- |-----------------------------< post_insert >------------------------------|
179 -- ----------------------------------------------------------------------------
180 -- {Start Of Comments}
181 --
182 -- Description:
183 -- This private procedure contains any processing which is required after the
184 -- insert dml.
185 --
186 -- Prerequisites:
187 -- This is an internal procedure which is called from the ins procedure.
188 --
189 -- In Parameters:
190 -- A Pl/Sql record structre.
191 --
192 -- Post Success:
193 -- Processing continues.
194 --
195 -- Post Failure:
196 -- If an error has occurred, an error message and exception will be raised
197 -- but not handled.
198 --
199 -- Developer Implementation Notes:
200 -- Any post-processing required after the insert dml is issued should be
201 -- coded within this procedure. It is important to note that any 3rd party
202 -- maintenance should be reviewed before placing in this procedure.
203 --
204 -- Access Status:
205 -- Internal Row Handler Use Only.
206 --
207 -- {End Of Comments}
208 -- ----------------------------------------------------------------------------
209 Procedure post_insert
210 (p_rec in hr_ort_shd.g_rec_type
211 ) is
212 --
213 l_proc varchar2(72) := g_package||'post_insert';
214 --
215 Begin
216 hr_utility.set_location('Entering:'||l_proc, 5);
217 begin
218 --
219 hr_ort_rki.after_insert
220 (p_organization_id
221 => p_rec.organization_id
222 ,p_language
223 => p_rec.language
224 ,p_source_lang
225 => p_rec.source_lang
226 ,p_name
227 => p_rec.name
228 );
229 --
230 exception
231 --
232 when hr_api.cannot_find_prog_unit then
233 --
234 hr_api.cannot_find_prog_unit_error
235 (p_module_name => 'HR_ALL_ORGANIZATION_UNITS_TL'
236 ,p_hook_type => 'AI');
237 --
238 end;
239 --
240 hr_utility.set_location(' Leaving:'||l_proc, 10);
241 End post_insert;
242 --
243 -- ----------------------------------------------------------------------------
244 -- |---------------------------------< ins >----------------------------------|
245 -- ----------------------------------------------------------------------------
246 Procedure ins
247 (p_rec in out nocopy hr_ort_shd.g_rec_type
248 ,p_organization_id in number
249 ) is
250 --
251 l_proc varchar2(72) := g_package||'ins';
252 --
253 Begin
254 hr_utility.set_location('Entering:'||l_proc, 5);
255 --
256 -- Call the supporting insert validate operations
257 --
258 hr_ort_bus.insert_validate
259 (p_rec
260 );
261 --
262 -- Call the supporting pre-insert operation
263 --
264 hr_ort_ins.pre_insert
265 (p_rec => p_rec
266 ,p_organization_id => p_organization_id
267 );
268 --
269 -- Insert the row
270 --
271 hr_ort_ins.insert_dml(p_rec);
272 --
273 -- Call the supporting post-insert operation
274 --
275 hr_ort_ins.post_insert
276 (p_rec
277 );
278 --
279 hr_utility.set_location('Leaving:'||l_proc, 20);
280 end ins;
281 --
282 -- ----------------------------------------------------------------------------
283 -- |---------------------------------< ins >----------------------------------|
284 -- ----------------------------------------------------------------------------
285 Procedure ins
286 (p_organization_id in number
287 ,p_language in varchar2
288 ,p_source_lang in varchar2
289 ,p_name in varchar2
290 ) is
291 --
292 l_rec hr_ort_shd.g_rec_type;
293 l_proc varchar2(72) := g_package||'ins';
294 --
295 Begin
296 hr_utility.set_location('Entering:'||l_proc, 5);
297 --
298 -- Call conversion function to turn arguments into the
299 -- p_rec structure.
300 --
301 l_rec :=
302 hr_ort_shd.convert_args
303 (null
304 ,p_language
305 ,p_source_lang
306 ,p_name
307 );
308 --
309 -- Having converted the arguments into the hr_ort_rec
310 -- plsql record structure we call the corresponding record business process.
311 --
312 hr_ort_ins.ins
313 (p_rec => l_rec
314 ,p_organization_id => p_organization_id
315 );
316 --
317 -- As the primary key argument(s)
318 -- are specified as an OUT's we must set these values.
319 --
320 --
321 --
322 hr_utility.set_location(' Leaving:'||l_proc, 10);
323 End ins;
324 --
325 -- ----------------------------------------------------------------------------
326 -- |------------------------------< ins_tl >----------------------------------|
327 -- ----------------------------------------------------------------------------
328 Procedure ins_tl
329 (p_language_code in varchar2
330 ,p_organization_id in number
331 ,p_name in varchar2
332 ) is
333 --
334 -- Cursor to obtain the list of base and installed languages
335 --
336 cursor csr_ins_langs is
337 select l.language_code
338 from fnd_languages l
339 where l.installed_flag in ('I','B')
340 and not exists (select null
341 from hr_all_organization_units_tl ort
342 where ort.organization_id = p_organization_id
343 and ort.language = l.language_code);
344 --
345 l_proc varchar2(72) := g_package || 'ins_tl';
346 --
347 Begin
348 hr_utility.set_location('Entering:'||l_proc,10);
349 --
350 -- Insert a row for the base language and every installed language.
351 --
352 for l_lang in csr_ins_langs loop
353 hr_ort_ins.ins
354 (p_organization_id => p_organization_id
355 ,p_language => l_lang.language_code
356 ,p_source_lang => p_language_code
357 ,p_name => p_name
358 );
359 end loop;
360 --
361 hr_utility.set_location('Leaving:'||l_proc,20);
362 End ins_tl;
363 --
364 end hr_ort_ins;