1 Package Body ghr_evh_upd as
2 /* $Header: ghevhrhi.pkb 115.2 1999/11/09 22:35:45 pkm ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ghr_evh_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 set and unset the g_api_dml status as required (as we are about to
21 -- perform dml).
22 -- 3) To update the specified row in the schema using the primary key in
23 -- the predicates.
24 -- 4) To trap any constraint violations that may have occurred.
25 -- 5) To raise any other errors.
26 --
27 -- Prerequisites:
28 -- This is an internal private procedure which must be called from the upd
29 -- procedure.
30 --
31 -- In Parameters:
32 -- A Pl/Sql record structre.
33 --
34 -- Post Success:
35 -- The specified row will be updated in the schema.
36 --
37 -- Post Failure:
38 -- On the update dml failure it is important to note that we always reset the
39 -- g_api_dml status to false.
40 -- If a check, unique or parent integrity constraint violation is raised the
41 -- constraint_error procedure will be called.
42 -- If any other error is reported, the error will be raised after the
43 -- g_api_dml status is reset.
44 --
45 -- Developer Implementation Notes:
46 -- The update 'set' attribute list should be modified if any of your
47 -- attributes are not updateable.
48 --
49 -- Access Status:
50 -- Internal Row Handler Use Only.
51 --
52 -- {End Of Comments}
53 -- ----------------------------------------------------------------------------
54 Procedure update_dml(p_rec in out ghr_evh_shd.g_rec_type) is
55 --
56 l_proc varchar2(72) := g_package||'update_dml';
57 --
58 Begin
59 hr_utility.set_location('Entering:'||l_proc, 5);
60 --
61 -- Increment the object version
62 --
63 p_rec.object_version_number := p_rec.object_version_number + 1;
64 --
65 ghr_evh_shd.g_api_dml := true; -- Set the api dml status
66 --
67 -- Update the ghr_event_history Row
68 --
69 update ghr_event_history
70 set
71 event_history_id = p_rec.event_history_id,
72 event_id = p_rec.event_id,
73 table_name = p_rec.table_name,
74 record_id = p_rec.record_id,
75 start_date = p_rec.start_date,
76 end_date = p_rec.end_date,
77 comments = p_rec.comments,
78 object_version_number = p_rec.object_version_number
79 where event_history_id = p_rec.event_history_id;
80 --
81 ghr_evh_shd.g_api_dml := false; -- Unset the api dml status
82 --
83 hr_utility.set_location(' Leaving:'||l_proc, 10);
84 --
85 Exception
86 When hr_api.check_integrity_violated Then
87 -- A check constraint has been violated
88 ghr_evh_shd.g_api_dml := false; -- Unset the api dml status
89 ghr_evh_shd.constraint_error
90 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
91 When hr_api.parent_integrity_violated Then
92 -- Parent integrity has been violated
93 ghr_evh_shd.g_api_dml := false; -- Unset the api dml status
94 ghr_evh_shd.constraint_error
95 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
96 When hr_api.unique_integrity_violated Then
97 -- Unique integrity has been violated
98 ghr_evh_shd.g_api_dml := false; -- Unset the api dml status
99 ghr_evh_shd.constraint_error
100 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
101 When Others Then
102 ghr_evh_shd.g_api_dml := false; -- Unset the api dml status
103 Raise;
104 End update_dml;
105 --
106 -- ----------------------------------------------------------------------------
107 -- |------------------------------< pre_update >------------------------------|
108 -- ----------------------------------------------------------------------------
109 -- {Start Of Comments}
110 --
111 -- Description:
112 -- This private procedure contains any processing which is required before
113 -- the update dml.
114 --
115 -- Prerequisites:
116 -- This is an internal procedure which is called from the upd procedure.
117 --
118 -- In Parameters:
119 -- A Pl/Sql record structre.
120 --
121 -- Post Success:
122 -- Processing continues.
123 --
124 -- Post Failure:
125 -- If an error has occurred, an error message and exception will be raised
126 -- but not handled.
127 --
128 -- Developer Implementation Notes:
129 -- Any pre-processing required before the update dml is issued should be
130 -- coded within this procedure. It is important to note that any 3rd party
131 -- maintenance should be reviewed before placing in this procedure.
132 --
133 -- Access Status:
134 -- Internal Row Handler Use Only.
135 --
136 -- {End Of Comments}
137 -- ----------------------------------------------------------------------------
138 Procedure pre_update(p_rec in ghr_evh_shd.g_rec_type) is
139 --
140 l_proc varchar2(72) := g_package||'pre_update';
141 --
142 Begin
143 hr_utility.set_location('Entering:'||l_proc, 5);
144 --
145 hr_utility.set_location(' Leaving:'||l_proc, 10);
146 End pre_update;
147 --
148 -- ----------------------------------------------------------------------------
149 -- |-----------------------------< post_update >------------------------------|
150 -- ----------------------------------------------------------------------------
151 -- {Start Of Comments}
152 --
153 -- Description:
154 -- This private procedure contains any processing which is required after the
155 -- update dml.
156 --
157 -- Prerequisites:
158 -- This is an internal procedure which is called from the upd procedure.
159 --
160 -- In Parameters:
161 -- A Pl/Sql record structre.
162 --
163 -- Post Success:
164 -- Processing continues.
165 --
166 -- Post Failure:
167 -- If an error has occurred, an error message and exception will be raised
168 -- but not handled.
169 --
170 -- Developer Implementation Notes:
171 -- Any post-processing required after the update dml is issued should be
172 -- coded within this procedure. It is important to note that any 3rd party
173 -- maintenance should be reviewed before placing in this procedure.
174 --
175 -- Access Status:
176 -- Internal Row Handler Use Only.
177 --
178 -- {End Of Comments}
179 -- ----------------------------------------------------------------------------
180 Procedure post_update(p_rec in ghr_evh_shd.g_rec_type) is
181 --
182 l_proc varchar2(72) := g_package||'post_update';
183 --
184 Begin
185 hr_utility.set_location('Entering:'||l_proc, 5);
186 --
187 --
188 -- Start of API User Hook for post_update.
189 --
190 begin
191 --
192 ghr_evh_rku.after_update
193 (
194 p_event_history_id =>p_rec.event_history_id
195 ,p_event_id =>p_rec.event_id
196 ,p_table_name =>p_rec.table_name
197 ,p_record_id =>p_rec.record_id
198 ,p_start_date =>p_rec.start_date
199 ,p_end_date =>p_rec.end_date
200 ,p_comments =>p_rec.comments
201 ,p_object_version_number =>p_rec.object_version_number
202 ,p_event_id_o =>ghr_evh_shd.g_old_rec.event_id
203 ,p_table_name_o =>ghr_evh_shd.g_old_rec.table_name
204 ,p_record_id_o =>ghr_evh_shd.g_old_rec.record_id
205 ,p_start_date_o =>ghr_evh_shd.g_old_rec.start_date
206 ,p_end_date_o =>ghr_evh_shd.g_old_rec.end_date
207 ,p_comments_o =>ghr_evh_shd.g_old_rec.comments
208 ,p_object_version_number_o =>ghr_evh_shd.g_old_rec.object_version_number
209 );
210 --
211 exception
212 --
213 when hr_api.cannot_find_prog_unit then
214 --
215 hr_api.cannot_find_prog_unit_error
216 (p_module_name => 'ghr_event_history'
217 ,p_hook_type => 'AU');
218 --
219 end;
220 --
221 -- End of API User Hook for post_update.
222 --
223 --
224 hr_utility.set_location(' Leaving:'||l_proc, 10);
225 End post_update;
226 --
227 -- ----------------------------------------------------------------------------
228 -- |-----------------------------< convert_defs >-----------------------------|
229 -- ----------------------------------------------------------------------------
230 -- {Start Of Comments}
231 --
232 -- Description:
233 -- The Convert_Defs procedure has one very important function:
234 -- It must return the record structure for the row with all system defaulted
235 -- values converted into its corresponding parameter value for update. When
236 -- we attempt to update a row through the Upd process , certain
237 -- parameters can be defaulted which enables flexibility in the calling of
238 -- the upd process (e.g. only attributes which need to be updated need to be
239 -- specified). For the upd process to determine which attributes
240 -- have NOT been specified we need to check if the parameter has a reserved
241 -- system default value. Therefore, for all parameters which have a
242 -- corresponding reserved system default mechanism specified we need to
243 -- check if a system default is being used. If a system default is being
244 -- used then we convert the defaulted value into its corresponding attribute
245 -- value held in the g_old_rec data structure.
246 --
247 -- Prerequisites:
248 -- This private function can only be called from the upd process.
249 --
250 -- In Parameters:
251 -- A Pl/Sql record structre.
252 --
253 -- Post Success:
254 -- The record structure will be returned with all system defaulted parameter
255 -- values converted into its current row attribute value.
256 --
257 -- Post Failure:
258 -- No direct error handling is required within this function. Any possible
259 -- errors within this procedure will be a PL/SQL value error due to conversion
260 -- of datatypes or data lengths.
261 --
262 -- Developer Implementation Notes:
263 -- None.
264 --
265 -- Access Status:
266 -- Internal Row Handler Use Only.
267 --
268 -- {End Of Comments}
269 -- ----------------------------------------------------------------------------
270 Procedure convert_defs(p_rec in out ghr_evh_shd.g_rec_type) is
271 --
272 l_proc varchar2(72) := g_package||'convert_defs';
273 --
274 Begin
275 --
276 hr_utility.set_location('Entering:'||l_proc, 5);
277 --
278 -- We must now examine each argument value in the
279 -- p_rec plsql record structure
280 -- to see if a system default is being used. If a system default
281 -- is being used then we must set to the 'current' argument value.
282 --
283 If (p_rec.event_id = hr_api.g_number) then
284 p_rec.event_id :=
285 ghr_evh_shd.g_old_rec.event_id;
286 End If;
287 If (p_rec.table_name = hr_api.g_varchar2) then
288 p_rec.table_name :=
289 ghr_evh_shd.g_old_rec.table_name;
290 End If;
291 If (p_rec.record_id = hr_api.g_number) then
292 p_rec.record_id :=
293 ghr_evh_shd.g_old_rec.record_id;
294 End If;
295 If (p_rec.start_date = hr_api.g_date) then
296 p_rec.start_date :=
297 ghr_evh_shd.g_old_rec.start_date;
298 End If;
299 If (p_rec.end_date = hr_api.g_date) then
300 p_rec.end_date :=
301 ghr_evh_shd.g_old_rec.end_date;
302 End If;
303 If (p_rec.comments = hr_api.g_varchar2) then
304 p_rec.comments :=
305 ghr_evh_shd.g_old_rec.comments;
306 End If;
307
308 --
309 hr_utility.set_location(' Leaving:'||l_proc, 10);
310 --
311 End convert_defs;
312 --
313 -- ----------------------------------------------------------------------------
314 -- |---------------------------------< upd >----------------------------------|
315 -- ----------------------------------------------------------------------------
316 Procedure upd
317 (
318 p_rec in out ghr_evh_shd.g_rec_type
319 ) is
320 --
321 l_proc varchar2(72) := g_package||'upd';
322 --
323 Begin
324 hr_utility.set_location('Entering:'||l_proc, 5);
325 --
326 -- We must lock the row which we need to update.
327 --
328 ghr_evh_shd.lck
329 (
330 p_rec.event_history_id,
331 p_rec.object_version_number
332 );
333 --
334 -- 1. During an update system defaults are used to determine if
335 -- arguments have been defaulted or not. We must therefore
336 -- derive the full record structure values to be updated.
337 --
338 -- 2. Call the supporting update validate operations.
339 --
340 convert_defs(p_rec);
341 ghr_evh_bus.update_validate(p_rec);
342 --
343 -- Call the supporting pre-update operation
344 --
345 pre_update(p_rec);
346 --
347 -- Update the row.
348 --
349 update_dml(p_rec);
350 --
351 -- Call the supporting post-update operation
352 --
353 post_update(p_rec);
354 End upd;
355 --
356 -- ----------------------------------------------------------------------------
357 -- |---------------------------------< upd >----------------------------------|
358 -- ----------------------------------------------------------------------------
359 Procedure upd
360 (
361 p_event_history_id in number,
362 p_event_id in number default hr_api.g_number,
363 p_table_name in varchar2 default hr_api.g_varchar2,
364 p_record_id in number default hr_api.g_number,
365 p_start_date in date default hr_api.g_date,
366 p_end_date in date default hr_api.g_date,
367 p_comments in varchar2 default hr_api.g_varchar2,
368 p_object_version_number in out number
369 ) is
370 --
371 l_rec ghr_evh_shd.g_rec_type;
372 l_proc varchar2(72) := g_package||'upd';
373 --
374 Begin
375 hr_utility.set_location('Entering:'||l_proc, 5);
376 --
377 -- Call conversion function to turn arguments into the
378 -- l_rec structure.
379 --
380 l_rec :=
381 ghr_evh_shd.convert_args
382 (
383 p_event_history_id,
384 p_event_id,
385 p_table_name,
386 p_record_id,
387 p_start_date,
388 p_end_date,
389 p_comments,
390 p_object_version_number
391 );
392 --
393 -- Having converted the arguments into the
394 -- plsql record structure we call the corresponding record
395 -- business process.
396 --
397 upd(l_rec);
398 p_object_version_number := l_rec.object_version_number;
399 --
400 hr_utility.set_location(' Leaving:'||l_proc, 10);
401 End upd;
402 --
403 end ghr_evh_upd;