1 Package Body hr_lot_ins as
2 /* $Header: hrlotrhi.pkb 115.10 2002/12/04 05:45:04 hjonnala ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' hr_lot_ins.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |------------------------------< insert_dml >------------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 -- This procedure controls the actual dml insert logic. The processing of
17 -- this procedure are as follows:
18 -- 1) Initialise the object_version_number to 1 if the object_version_number
19 -- is defined as an attribute for this entity.
20 -- 2) To insert the row into the schema.
21 -- 3) To trap any constraint violations that may have occurred.
22 -- 4) To raise any other errors.
23 --
24 -- Prerequisites:
25 -- This is an internal private procedure which must be called from the ins
26 -- procedure and must have all mandatory attributes set (except the
27 -- object_version_number which is initialised within this procedure).
28 --
29 -- In Parameters:
30 -- A Pl/Sql record structre.
31 --
32 -- Post Success:
33 -- The specified row will be inserted into the schema.
34 --
35 -- Post Failure:
36 -- If a check, unique or parent integrity constraint violation is raised the
37 -- constraint_error procedure will be called.
38 --
39 -- Developer Implementation Notes:
40 -- None.
41 --
42 -- Access Status:
43 -- Internal Row Handler Use Only.
44 --
45 -- {End Of Comments}
46 -- ----------------------------------------------------------------------------
47 Procedure insert_dml(p_rec in out nocopy hr_lot_shd.g_rec_type) is
48 --
49 l_proc varchar2(72) := g_package||'insert_dml';
50 --
51 Begin
52 hr_utility.set_location('Entering:'||l_proc, 5);
53 --
54 -- Insert the row into: hr_locations_all_tl
55 --
56 insert into hr_locations_all_tl
57 ( location_id,
58 language,
59 source_lang,
60 location_code,
61 description
62 )
63 Values
64 ( p_rec.location_id,
65 p_rec.language,
66 p_rec.source_lang,
67 p_rec.location_code,
68 p_rec.description
69 );
70 --
71 hr_utility.set_location(' Leaving:'||l_proc, 10);
72 Exception
73 When hr_api.check_integrity_violated Then
74 -- A check constraint has been violated
75 hr_lot_shd.constraint_error
76 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
77 When hr_api.parent_integrity_violated Then
78 -- Parent integrity has been violated
79 hr_lot_shd.constraint_error
80 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
81 When hr_api.unique_integrity_violated Then
82 -- Unique integrity has been violated
83 hr_lot_shd.constraint_error
84 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
85 When Others Then
86 Raise;
87 End insert_dml;
88 --
89 -- ----------------------------------------------------------------------------
90 -- |------------------------------< pre_insert >------------------------------|
91 -- ----------------------------------------------------------------------------
92 -- {Start Of Comments}
93 --
94 -- Description:
95 -- This private procedure contains any processing which is required before
96 -- the insert dml. Presently, if the entity has a corresponding primary
97 -- key which is maintained by an associating sequence, the primary key for
98 -- the entity will be populated with the next sequence value in
99 -- preparation for the insert dml.
100 --
101 -- Prerequisites:
102 -- This is an internal procedure which is called from the ins procedure.
103 --
104 -- In Parameters:
105 -- A Pl/Sql record structre.
106 --
107 -- Post Success:
108 -- Processing continues.
109 --
110 -- Post Failure:
111 -- If an error has occurred, an error message and exception will be raised
112 -- but not handled.
113 --
114 -- Developer Implementation Notes:
115 -- Any pre-processing required before the insert dml is issued should be
116 -- coded within this procedure. As stated above, a good example is the
117 -- generation of a primary key number via a corresponding sequence.
118 -- It is important to note that any 3rd party maintenance should be reviewed
119 -- before placing in this procedure.
120 --
121 -- Access Status:
122 -- Internal Row Handler Use Only.
123 --
124 -- {End Of Comments}
125 -- ----------------------------------------------------------------------------
126 Procedure pre_insert(p_rec in out nocopy hr_lot_shd.g_rec_type,
127 p_location_id in number) is
128 --
129 l_proc varchar2(72) := g_package||'pre_insert';
130 --
131 --
132 --
133 Begin
134 hr_utility.set_location('Entering:'||l_proc, 5);
135 --
136 p_rec.location_id := p_location_id;
137 --
138 hr_utility.set_location(' Leaving:'||l_proc, 10);
139 End pre_insert;
140 --
141 -- ----------------------------------------------------------------------------
142 -- |-----------------------------< post_insert >------------------------------|
143 -- ----------------------------------------------------------------------------
144 -- {Start Of Comments}
145 --
146 -- Description:
147 -- This private procedure contains any processing which is required after the
148 -- insert dml.
149 --
150 -- Prerequisites:
151 -- This is an internal procedure which is called from the ins procedure.
152 --
153 -- In Parameters:
154 -- A Pl/Sql record structre.
155 --
156 -- Post Success:
157 -- Processing continues.
158 --
159 -- Post Failure:
160 -- If an error has occurred, an error message and exception will be raised
161 -- but not handled.
162 --
163 -- Developer Implementation Notes:
164 -- Any post-processing required after the insert dml is issued should be
165 -- coded within this procedure. It is important to note that any 3rd party
166 -- maintenance should be reviewed before placing in this procedure.
167 --
168 -- Access Status:
169 -- Internal Row Handler Use Only.
170 --
171 -- {End Of Comments}
172 -- ----------------------------------------------------------------------------
173 Procedure post_insert(p_rec in hr_lot_shd.g_rec_type) is
174 --
175 l_proc varchar2(72) := g_package||'post_insert';
176 --
177 Begin
178 hr_utility.set_location('Entering:'||l_proc, 5);
179 --
180 --
181 -- Start of API User Hook for post_insert.
182 --
183 begin
184 --
185 hr_lot_rki.after_insert
186 (
187 p_location_id =>p_rec.location_id
188 ,p_language =>p_rec.language
189 ,p_source_lang =>p_rec.source_lang
190 ,p_location_code =>p_rec.location_code
191 ,p_description =>p_rec.description
192 );
193 --
194 exception
195 --
196 when hr_api.cannot_find_prog_unit then
197 --
198 hr_api.cannot_find_prog_unit_error
199 (p_module_name => 'HR_LOCATIONS_ALL_TL'
200 ,p_hook_type => 'AI');
201 --
202 end;
203 --
204 -- End of API User Hook for post_insert.
205 --
206 --
207 hr_utility.set_location(' Leaving:'||l_proc, 10);
208 End post_insert;
209 --
210 -- ----------------------------------------------------------------------------
211 -- |---------------------------------< ins >----------------------------------|
212 -- ----------------------------------------------------------------------------
213 Procedure ins
214 (
215 p_rec in out nocopy hr_lot_shd.g_rec_type,
216 p_location_id in number,
217 p_business_group_id in number
218 ) is
219 --
220 l_proc varchar2(72) := g_package||'ins';
221 --
222 Begin
223 hr_utility.set_location('Entering:'||l_proc, 5);
224 --
225 -- Call the supporting insert validate operations
226 --
227 hr_lot_bus.insert_validate(p_rec, p_business_group_id);
228 --
229 -- Call the supporting pre-insert operation
230 --
231 pre_insert(p_rec, p_location_id);
232 --
233 -- Insert the row
234 --
235 insert_dml(p_rec);
236 --
237 -- Call the supporting post-insert operation
238 --
239 post_insert(p_rec);
240 end ins;
241 --
242 -- ----------------------------------------------------------------------------
243 -- |---------------------------------< ins >----------------------------------|
244 -- ----------------------------------------------------------------------------
245 Procedure ins
246 (
247 p_location_id in number,
248 p_language in varchar2,
249 p_source_lang in varchar2,
250 p_location_code in varchar2,
251 p_description in varchar2 default null,
252 p_business_group_id in number
253 ) is
254 --
255 l_rec hr_lot_shd.g_rec_type;
256 l_proc varchar2(72) := g_package||'ins';
257 --
258 Begin
259 hr_utility.set_location('Entering:'||l_proc, 5);
260 --
261 -- Call conversion function to turn arguments into the
262 -- p_rec structure.
263 --
264 -- api_updating() expects the location_id to be NULL on insert. For a TL insert,
265 -- however, we already know the location_id because we have just inserted a row on
266 -- the non-translated table. So to ensure api_updating() still works, pass
267 -- through NULL to convert_args, but add an extra parameter - p_location_id -
268 -- to the call to ins(). This parameter contains the real location_id.
269 --
270 l_rec :=
271 hr_lot_shd.convert_args
272 (
273 NULL,
274 p_language,
275 p_source_lang,
276 p_location_code,
277 p_description
278 );
279 --
280 -- Having converted the arguments into the hr_lot_rec
281 -- plsql record structure we call the corresponding record business process.
282 --
283 ins(l_rec,
284 p_location_id,
285 p_business_group_id);
286 --
287 --
288 hr_utility.set_location(' Leaving:'||l_proc, 10);
289 End ins;
290 --
291 -- -------------------------------------------------------------------------
292 -- |------------------------------< ins_tl >-------------------------------|
293 -- -------------------------------------------------------------------------
294 Procedure ins_tl
295 (p_language_code in varchar2,
296 p_location_id in number,
297 p_location_code in varchar2,
298 p_description in varchar2,
299 p_business_group_id in number
300 ) is
301 --
302 -- Cursor to obtain the list of base and installed languages
303 --
304 cursor csr_ins_langs is
305 select l.language_code
306 from fnd_languages l
307 where l.installed_flag in ('I', 'B')
308 and not exists (select null
309 from hr_locations_all_tl lot
310 where lot.location_id = p_location_id
311 and lot.language = l.language_code);
312 --
313 --
314 l_proc varchar2(72) := g_package||'ins_tl';
315 l_inserted_anything boolean := false;
316 --
317 Begin
318 hr_utility.set_location('Entering:'||l_proc, 10);
319 --
320 -- Insert a row for the base language and every installed language.
321 --
322 hr_utility.set_location(l_proc, 15);
323 for l_lang in csr_ins_langs loop
324 ins
325 (p_location_id => p_location_id
326 ,p_language => l_lang.language_code
327 ,p_source_lang => p_language_code
328 ,p_location_code => p_location_code
329 ,p_description => p_description
330 ,p_business_group_id => p_business_group_id
331 );
332 l_inserted_anything := true;
333 end loop;
334 --
335 if not l_inserted_anything then
336 hr_utility.set_message(800, 'PER_52517_NO_MLS_INSERTS');
337 hr_utility.raise_error;
338 end if;
339 --
340 -- Finally, set the global g_loc_bg_id for use when updating.
341 --
342 hr_lot_shd.set_value_business_group_id (p_business_group_id => p_business_group_id);
343 --
344 hr_utility.set_location(' Leaving:'||l_proc, 20);
345 End ins_tl;
346 --
347 end hr_lot_ins;