1 Package Body pqh_atl_upd as
2 /* $Header: pqatlrhi.pkb 120.2 2006/05/23 15:58:59 srajakum ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pqh_atl_upd.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |------------------------------< update_dml >------------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 -- This procedure controls the actual dml update logic. The processing of
17 -- this procedure is:
18 -- 1) Increment the object_version_number by 1 if the object_version_number
19 -- is defined as an attribute for this entity.
20 -- 2) To update the specified row in the schema using the primary key in
21 -- the predicates.
22 -- 3) To trap any constraint violations that may have occurred.
23 -- 4) To raise any other errors.
24 --
25 -- Prerequisites:
26 -- This is an internal private procedure which must be called from the upd
27 -- procedure.
28 --
29 -- In Parameters:
30 -- A Pl/Sql record structre.
31 --
32 -- Post Success:
33 -- The specified row will be updated in 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 -- The update 'set' attribute list should be modified if any of your
41 -- attributes are not updateable.
42 --
43 -- Access Status:
44 -- Internal Row Handler Use Only.
45 --
46 -- {End Of Comments}
47 -- ----------------------------------------------------------------------------
48 Procedure update_dml(p_rec in out nocopy pqh_atl_shd.g_rec_type) is
49 --
50 l_proc varchar2(72) := g_package||'update_dml';
51 --
52 Begin
53 hr_utility.set_location('Entering:'||l_proc, 5);
54 --
55 --
56 -- Update the pqh_attributes_tl Row
57 --
58 update pqh_attributes_tl
59 set
60 attribute_id = p_rec.attribute_id,
61 attribute_name = p_rec.attribute_name,
62 language = p_rec.language,
63 source_lang = p_rec.source_lang
64 where attribute_id = p_rec.attribute_id
65 and language = p_rec.language;
66 --
67 --
68 hr_utility.set_location(' Leaving:'||l_proc, 10);
69 --
70 Exception
71 When hr_api.check_integrity_violated Then
72 -- A check constraint has been violated
73 pqh_atl_shd.constraint_error
74 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
75 When hr_api.parent_integrity_violated Then
76 -- Parent integrity has been violated
77 pqh_atl_shd.constraint_error
78 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
79 When hr_api.unique_integrity_violated Then
80 -- Unique integrity has been violated
81 pqh_atl_shd.constraint_error
82 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
83 When Others Then
84 Raise;
85 End update_dml;
86 --
87 -- ----------------------------------------------------------------------------
88 -- |------------------------------< pre_update >------------------------------|
89 -- ----------------------------------------------------------------------------
90 -- {Start Of Comments}
91 --
92 -- Description:
93 -- This private procedure contains any processing which is required before
94 -- the update dml.
95 --
96 -- Prerequisites:
97 -- This is an internal procedure which is called from the upd procedure.
98 --
99 -- In Parameters:
100 -- A Pl/Sql record structre.
101 --
102 -- Post Success:
103 -- Processing continues.
104 --
105 -- Post Failure:
106 -- If an error has occurred, an error message and exception will be raised
107 -- but not handled.
108 --
109 -- Developer Implementation Notes:
110 -- Any pre-processing required before the update dml is issued should be
111 -- coded within this procedure. It is important to note that any 3rd party
112 -- maintenance should be reviewed before placing in this procedure.
113 --
114 -- Access Status:
115 -- Internal Row Handler Use Only.
116 --
117 -- {End Of Comments}
118 -- ----------------------------------------------------------------------------
119 Procedure pre_update(p_rec in pqh_atl_shd.g_rec_type) is
120 --
121 l_proc varchar2(72) := g_package||'pre_update';
122 --
123 Begin
124 hr_utility.set_location('Entering:'||l_proc, 5);
125 --
126 hr_utility.set_location(' Leaving:'||l_proc, 10);
127 End pre_update;
128 --
129 -- ----------------------------------------------------------------------------
130 -- |-----------------------------< post_update >------------------------------|
131 -- ----------------------------------------------------------------------------
132 -- {Start Of Comments}
133 --
134 -- Description:
135 -- This private procedure contains any processing which is required after the
136 -- update dml.
137 --
138 -- Prerequisites:
139 -- This is an internal procedure which is called from the upd procedure.
140 --
141 -- In Parameters:
142 -- A Pl/Sql record structre.
143 --
144 -- Post Success:
145 -- Processing continues.
146 --
147 -- Post Failure:
148 -- If an error has occurred, an error message and exception will be raised
149 -- but not handled.
150 --
151 -- Developer Implementation Notes:
152 -- Any post-processing required after the update dml is issued should be
153 -- coded within this procedure. It is important to note that any 3rd party
154 -- maintenance should be reviewed before placing in this procedure.
155 --
156 -- Access Status:
157 -- Internal Row Handler Use Only.
158 --
159 -- {End Of Comments}
160 -- ----------------------------------------------------------------------------
161 Procedure post_update(p_rec in pqh_atl_shd.g_rec_type) is
162 --
163 l_proc varchar2(72) := g_package||'post_update';
164 --
165 Begin
166 hr_utility.set_location('Entering:'||l_proc, 5);
167 --
168 --
169 -- Start of API User Hook for post_update.
170 --
171 begin
172 --
173 pqh_atl_rku.after_update
174 (
175 p_attribute_id =>p_rec.attribute_id
176 ,p_attribute_name =>p_rec.attribute_name
177 ,p_language =>p_rec.language
178 ,p_source_lang =>p_rec.source_lang
179 ,p_attribute_name_o =>pqh_atl_shd.g_old_rec.attribute_name
180 ,p_language_o =>pqh_atl_shd.g_old_rec.language
181 ,p_source_lang_o =>pqh_atl_shd.g_old_rec.source_lang
182 );
183 --
184 exception
185 --
186 when hr_api.cannot_find_prog_unit then
187 --
188 hr_api.cannot_find_prog_unit_error
189 (p_module_name => 'pqh_attributes_tl'
190 ,p_hook_type => 'AU');
191 --
192 end;
193 --
194 -- End of API User Hook for post_update.
195 --
196 --
197 hr_utility.set_location(' Leaving:'||l_proc, 10);
198 End post_update;
199 --
200 -- ----------------------------------------------------------------------------
201 -- |-----------------------------< convert_defs >-----------------------------|
202 -- ----------------------------------------------------------------------------
203 -- {Start Of Comments}
204 --
205 -- Description:
206 -- The Convert_Defs procedure has one very important function:
207 -- It must return the record structure for the row with all system defaulted
208 -- values converted into its corresponding parameter value for update. When
209 -- we attempt to update a row through the Upd process , certain
210 -- parameters can be defaulted which enables flexibility in the calling of
211 -- the upd process (e.g. only attributes which need to be updated need to be
212 -- specified). For the upd process to determine which attributes
213 -- have NOT been specified we need to check if the parameter has a reserved
214 -- system default value. Therefore, for all parameters which have a
215 -- corresponding reserved system default mechanism specified we need to
216 -- check if a system default is being used. If a system default is being
217 -- used then we convert the defaulted value into its corresponding attribute
218 -- value held in the g_old_rec data structure.
219 --
220 -- Prerequisites:
221 -- This private function can only be called from the upd process.
222 --
223 -- In Parameters:
224 -- A Pl/Sql record structre.
225 --
226 -- Post Success:
227 -- The record structure will be returned with all system defaulted parameter
228 -- values converted into its current row attribute value.
229 --
230 -- Post Failure:
231 -- No direct error handling is required within this function. Any possible
232 -- errors within this procedure will be a PL/SQL value error due to conversion
233 -- of datatypes or data lengths.
234 --
235 -- Developer Implementation Notes:
236 -- None.
237 --
238 -- Access Status:
239 -- Internal Row Handler Use Only.
240 --
241 -- {End Of Comments}
242 -- ----------------------------------------------------------------------------
243 Procedure convert_defs(p_rec in out nocopy pqh_atl_shd.g_rec_type) is
244 --
245 l_proc varchar2(72) := g_package||'convert_defs';
246 --
247 Begin
248 --
249 hr_utility.set_location('Entering:'||l_proc, 5);
250 --
251 -- We must now examine each argument value in the
252 -- p_rec plsql record structure
253 -- to see if a system default is being used. If a system default
254 -- is being used then we must set to the 'current' argument value.
255 --
256 If (p_rec.attribute_name = hr_api.g_varchar2) then
257 p_rec.attribute_name :=
258 pqh_atl_shd.g_old_rec.attribute_name;
259 End If;
260 If (p_rec.source_lang = hr_api.g_varchar2) then
261 p_rec.source_lang :=
262 pqh_atl_shd.g_old_rec.source_lang;
263 End If;
264 --
265 hr_utility.set_location(' Leaving:'||l_proc, 10);
266 --
267 End convert_defs;
268 --
269 -- ----------------------------------------------------------------------------
270 -- |---------------------------------< upd >----------------------------------|
271 -- ----------------------------------------------------------------------------
272 Procedure upd
273 (
274 p_rec in out nocopy pqh_atl_shd.g_rec_type
275 ) is
276 --
277 l_proc varchar2(72) := g_package||'upd';
278 --
279 Begin
280 hr_utility.set_location('Entering:'||l_proc, 5);
281 --
282 -- We must lock the row which we need to update.
283 --
284 pqh_atl_shd.lck
285 (
286 p_rec.attribute_id,
287 p_rec.language
288 );
289 --
290 -- 1. During an update system defaults are used to determine if
291 -- arguments have been defaulted or not. We must therefore
292 -- derive the full record structure values to be updated.
293 --
294 -- 2. Call the supporting update validate operations.
295 --
296 convert_defs(p_rec);
297 pqh_atl_bus.update_validate(p_rec);
298 --
299 -- Call the supporting pre-update operation
300 --
301 pre_update(p_rec);
302 --
303 -- Update the row.
304 --
305 update_dml(p_rec);
306 --
307 -- Call the supporting post-update operation
308 --
309 post_update(p_rec);
310 End upd;
311 --
312 -- ----------------------------------------------------------------------------
313 -- |---------------------------------< upd >----------------------------------|
314 -- ----------------------------------------------------------------------------
315 Procedure upd
316 (
317 p_attribute_id in number,
318 p_attribute_name in varchar2 default hr_api.g_varchar2,
319 p_language in varchar2,
320 p_source_lang in varchar2 default hr_api.g_varchar2
321 ) is
322 --
323 l_rec pqh_atl_shd.g_rec_type;
324 l_proc varchar2(72) := g_package||'upd';
325 --
326 Begin
327 hr_utility.set_location('Entering:'||l_proc, 5);
328 --
329 -- Call conversion function to turn arguments into the
330 -- l_rec structure.
331 --
332 l_rec :=
333 pqh_atl_shd.convert_args
334 (
335 p_attribute_id,
336 p_attribute_name,
337 p_language,
338 p_source_lang
339 );
340 --
341 -- Having converted the arguments into the
342 -- plsql record structure we call the corresponding record
343 -- business process.
344 --
345 upd(l_rec);
346 --
347 --
348 hr_utility.set_location(' Leaving:'||l_proc, 10);
349 End upd;
350 --
351 -- ----------------------------------------------------------------------------
352 -- |------------------------------< upd_tl >----------------------------------|
353 -- ----------------------------------------------------------------------------
354 --
355 procedure upd_tl ( p_language_code in varchar2,
356 p_attribute_id in number,
357 p_attribute_name in varchar2 ) is
358 --
359 cursor csr_upd_langs is
360 select atl.language
361 from pqh_attributes_tl atl
362 where atl.attribute_id = p_attribute_id
363 AND p_language_code in (atl.language,atl.source_lang);
364 --
365 l_proc varchar2(72) := g_package||'upd_tl';
366 --
367 begin
368 --
369 hr_utility.set_location(' Entering:'||l_proc, 10);
370 --
371 for l_lang in csr_upd_langs loop
372 --
373 --
374 upd
375 (p_attribute_id => p_attribute_id,
376 p_attribute_name => p_attribute_name,
377 p_language => l_lang.language,
378 p_source_lang => p_language_code) ;
379 --
380 --
381 end loop;
382 --
383 hr_utility.set_location(' Leaving:'||l_proc, 20);
384 --
385 end upd_tl;
386 --
387 -- ----------- Translate Row -------------------------------------------
388 --
389 Procedure translate_row (
390 p_attribute_name in varchar2,
391 p_att_col_name in varchar2,
392 p_att_master_table_alias_name in varchar2,
393 p_legislation_code in varchar2,
394 p_owner in varchar2 ) is
395
396 --
397 cursor csr_attribute_id(p_column_name IN VARCHAR2, p_table_id IN NUMBER, p_legislation_code in varchar2) is
398 select attribute_id
399 from pqh_attributes
400 where key_column_name = p_att_col_name
401 and nvl(legislation_code,'$$$') = nvl(p_legislation_code,'$$$')
402 and nvl(master_table_route_id,-1) = nvl(p_table_id, -1);
403 --
404 cursor csr_table_id (p_table_alias IN VARCHAR2) is
405 select table_route_id
406 from pqh_table_route
407 where table_alias = p_table_alias;
408 --
409
410 l_attribute_id number(15);
411 l_att_master_table_route_id number(15);
412
413 X_CREATION_DATE DATE;
414 X_CREATED_BY NUMBER;
415 X_LAST_UPDATE_DATE DATE;
416 X_LAST_UPDATED_BY NUMBER;
417 X_LAST_UPDATE_LOGIN NUMBER;
418
419
420 begin
421 -- get attribute_id
422 --
423 open csr_table_id(p_table_alias => p_att_master_table_alias_name );
424 fetch csr_table_id into l_att_master_table_route_id;
425 close csr_table_id;
426 --
427 open csr_attribute_id(p_column_name => p_att_col_name, p_table_id => l_att_master_table_route_id, p_legislation_code => p_legislation_code);
428 fetch csr_attribute_id into l_attribute_id;
429 close csr_attribute_id;
430 --
431
432 -- populate WHO columns
433 if p_owner = 'SEED' then
434 X_CREATED_BY := 1;
435 X_LAST_UPDATED_BY := -1;
436 else
437 X_CREATED_BY := 0;
438 X_LAST_UPDATED_BY := 0;
439 end if;
440
441 X_CREATION_DATE := sysdate;
442 X_LAST_UPDATE_DATE := sysdate;
443 X_LAST_UPDATE_LOGIN := 0;
444 X_LAST_UPDATED_BY := fnd_load_util.owner_id(p_owner);
445
446 update pqh_attributes_tl
447 set attribute_name = p_attribute_name ,
448 last_update_date = X_LAST_UPDATE_DATE,
449 last_updated_by = X_LAST_UPDATED_BY,
450 last_update_login = X_LAST_UPDATE_LOGIN,
451 source_lang = USERENV('LANG')
452 where USERENV('LANG') in (language,source_lang)
453 and attribute_id = l_attribute_id ;
454 --
455 end translate_row;
456 --
457 end pqh_atl_upd;