1 Package Body hr_pat_upd as
2 /* $Header: hrpatrhi.pkb 120.1 2011/09/21 08:58:39 hchintal noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' hr_pat_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 -- Pre Conditions:
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 Table Handler Use Only.
51 --
52 -- {End Of Comments}
53 -- ----------------------------------------------------------------------------
54 Procedure update_dml(p_rec in out nocopy hr_pat_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 hr_pat_shd.g_api_dml := true; -- Set the api dml status
66 --
67 -- Update the hr_patterns Row
68 --
69 update hr_patterns
70 set
71 pattern_id = p_rec.pattern_id,
72 pattern_name = p_rec.pattern_name,
73 pattern_start_weekday = p_rec.pattern_start_weekday,
74 pattern_start_time = p_rec.pattern_start_time,
75 object_version_number = p_rec.object_version_number
76 where pattern_id = p_rec.pattern_id;
77 --
78 hr_pat_shd.g_api_dml := false; -- Unset the api dml status
79 --
80 hr_utility.set_location(' Leaving:'||l_proc, 10);
81 --
82 Exception
83 When hr_api.check_integrity_violated Then
84 -- A check constraint has been violated
85 hr_pat_shd.g_api_dml := false; -- Unset the api dml status
86 hr_pat_shd.constraint_error
87 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
88 When hr_api.parent_integrity_violated Then
89 -- Parent integrity has been violated
90 hr_pat_shd.g_api_dml := false; -- Unset the api dml status
91 hr_pat_shd.constraint_error
92 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
93 When hr_api.unique_integrity_violated Then
94 -- Unique integrity has been violated
95 hr_pat_shd.g_api_dml := false; -- Unset the api dml status
96 hr_pat_shd.constraint_error
97 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
98 When Others Then
99 hr_pat_shd.g_api_dml := false; -- Unset the api dml status
100 Raise;
101 End update_dml;
102 --
103 -- ----------------------------------------------------------------------------
104 -- |------------------------------< pre_update >------------------------------|
105 -- ----------------------------------------------------------------------------
106 -- {Start Of Comments}
107 --
108 -- Description:
109 -- This private procedure contains any processing which is required before
110 -- the update dml.
111 --
112 -- Pre Conditions:
113 -- This is an internal procedure which is called from the upd procedure.
114 --
115 -- In Parameters:
116 -- A Pl/Sql record structre.
117 --
118 -- Post Success:
119 -- Processing continues.
120 --
121 -- Post Failure:
122 -- If an error has occurred, an error message and exception will be raised
123 -- but not handled.
124 --
125 -- Developer Implementation Notes:
126 -- Any pre-processing required before the update dml is issued should be
127 -- coded within this procedure. It is important to note that any 3rd party
128 -- maintenance should be reviewed before placing in this procedure.
129 --
130 -- Access Status:
131 -- Internal Table Handler Use Only.
132 --
133 -- {End Of Comments}
134 -- ----------------------------------------------------------------------------
135 Procedure pre_update(p_rec in hr_pat_shd.g_rec_type) is
136 --
137 l_proc varchar2(72) := g_package||'pre_update';
138 --
139 Begin
140 hr_utility.set_location('Entering:'||l_proc, 5);
141 --
142 hr_utility.set_location(' Leaving:'||l_proc, 10);
143 End pre_update;
144 --
145 -- ----------------------------------------------------------------------------
146 -- |-----------------------------< post_update >------------------------------|
147 -- ----------------------------------------------------------------------------
148 -- {Start Of Comments}
149 --
150 -- Description:
151 -- This private procedure contains any processing which is required after the
152 -- update dml.
153 --
154 -- Pre Conditions:
155 -- This is an internal procedure which is called from the upd procedure.
156 --
157 -- In Parameters:
158 -- A Pl/Sql record structre.
159 --
160 -- Post Success:
161 -- Processing continues.
162 --
163 -- Post Failure:
164 -- If an error has occurred, an error message and exception will be raised
165 -- but not handled.
166 --
167 -- Developer Implementation Notes:
168 -- Any post-processing required after the update dml is issued should be
169 -- coded within this procedure. It is important to note that any 3rd party
170 -- maintenance should be reviewed before placing in this procedure.
171 --
172 -- Access Status:
173 -- Internal Table Handler Use Only.
174 --
175 -- {End Of Comments}
176 -- ----------------------------------------------------------------------------
177 Procedure post_update(p_rec in hr_pat_shd.g_rec_type) is
178 --
179 l_proc varchar2(72) := g_package||'post_update';
180 --
181 Begin
182 hr_utility.set_location('Entering:'||l_proc, 5);
183 --
184 hr_utility.set_location(' Leaving:'||l_proc, 10);
185 End post_update;
186 --
187 -- ----------------------------------------------------------------------------
188 -- |-----------------------------< convert_defs >-----------------------------|
189 -- ----------------------------------------------------------------------------
190 -- {Start Of Comments}
191 --
192 -- Description:
193 -- The Convert_Defs procedure has one very important function:
194 -- It must return the record structure for the row with all system defaulted
195 -- values converted into its corresponding parameter value for update. When
196 -- we attempt to update a row through the Upd process , certain
197 -- parameters can be defaulted which enables flexibility in the calling of
198 -- the upd process (e.g. only attributes which need to be updated need to be
199 -- specified). For the upd process to determine which attributes
200 -- have NOT been specified we need to check if the parameter has a reserved
201 -- system default value. Therefore, for all parameters which have a
202 -- corresponding reserved system default mechanism specified we need to
203 -- check if a system default is being used. If a system default is being
204 -- used then we convert the defaulted value into its corresponding attribute
205 -- value held in the g_old_rec data structure.
206 --
207 -- Pre Conditions:
208 -- This private function can only be called from the upd process.
209 --
210 -- In Parameters:
211 -- A Pl/Sql record structre.
212 --
213 -- Post Success:
214 -- The record structure will be returned with all system defaulted parameter
215 -- values converted into its current row attribute value.
216 --
217 -- Post Failure:
218 -- No direct error handling is required within this function. Any possible
219 -- errors within this procedure will be a PL/SQL value error due to conversion
220
221 -- of datatypes or data lengths.
222 --
223 -- Developer Implementation Notes:
224 -- None.
225 --
226 -- Access Status:
227 -- Internal Table Handler Use Only.
228 --
229 -- {End Of Comments}
230 -- ----------------------------------------------------------------------------
231 Procedure convert_defs(p_rec in out nocopy hr_pat_shd.g_rec_type) is
232 --
233 l_proc varchar2(72) := g_package||'convert_defs';
234 --
235 Begin
236 --
237 hr_utility.set_location('Entering:'||l_proc, 5);
238 --
239 -- We must now examine each argument value in the
240 -- p_rec plsql record structure
241 -- to see if a system default is being used. If a system default
242 -- is being used then we must set to the 'current' argument value.
243 --
244 If (p_rec.pattern_name = hr_api.g_varchar2) then
245 p_rec.pattern_name :=
246 hr_pat_shd.g_old_rec.pattern_name;
247 End If;
248 If (p_rec.pattern_start_weekday = hr_api.g_varchar2) then
249 p_rec.pattern_start_weekday :=
250 hr_pat_shd.g_old_rec.pattern_start_weekday;
251 End If;
252 If (p_rec.pattern_start_time = hr_api.g_varchar2) then
253 p_rec.pattern_start_time :=
254 hr_pat_shd.g_old_rec.pattern_start_time;
255 End If;
256
257 --
258 hr_utility.set_location(' Leaving:'||l_proc, 10);
259 --
260 End convert_defs;
261 --
262 -- ----------------------------------------------------------------------------
263 -- |---------------------------------< upd >----------------------------------|
264 -- ----------------------------------------------------------------------------
265 Procedure upd
266 (
267 p_rec in out nocopy hr_pat_shd.g_rec_type,
268 p_validate in boolean default false
269 ) is
270 --
271 l_proc varchar2(72) := g_package||'upd';
272 --
273 Begin
274 hr_utility.set_location('Entering:'||l_proc, 5);
275 --
276 -- Determine if the business process is to be validated.
277 --
278 If p_validate then
279 --
280 -- Issue the savepoint.
281 --
282 SAVEPOINT upd_hr_pat;
283 End If;
284 --
285 -- We must lock the row which we need to update.
286 --
287 hr_pat_shd.lck
288 (
289 p_rec.pattern_id,
290 p_rec.object_version_number
291 );
292 --
293 -- 1. During an update system defaults are used to determine if
294 -- arguments have been defaulted or not. We must therefore
295 -- derive the full record structure values to be updated.
296 --
297 -- 2. Call the supporting update validate operations.
298 --
299 convert_defs(p_rec);
300 hr_pat_bus.update_validate(p_rec);
301 --
302 -- Call the supporting pre-update operation
303 --
304 pre_update(p_rec);
305 --
306 -- Update the row.
307 --
308 update_dml(p_rec);
309 --
310 -- Call the supporting post-update operation
311 --
312 post_update(p_rec);
313 --
314 -- If we are validating then raise the Validate_Enabled exception
315 --
316 If p_validate then
317 Raise HR_Api.Validate_Enabled;
318 End If;
319 --
320 hr_utility.set_location(' Leaving:'||l_proc, 10);
321 Exception
322 When HR_Api.Validate_Enabled Then
323 --
324 -- As the Validate_Enabled exception has been raised
325 -- we must rollback to the savepoint
326 --
327 ROLLBACK TO upd_hr_pat;
328 End upd;
329 --
330 -- ----------------------------------------------------------------------------
331 -- |---------------------------------< upd >----------------------------------|
332 -- ----------------------------------------------------------------------------
333 Procedure upd
334 (
335 p_pattern_id in number,
336 p_pattern_name in varchar2 default hr_api.g_varchar2,
337 p_pattern_start_weekday in varchar2 default hr_api.g_varchar2,
338 p_pattern_start_time in varchar2 default hr_api.g_varchar2,
339 p_object_version_number in out nocopy number,
340 p_validate in boolean default false
341 ) is
342 --
343 l_rec hr_pat_shd.g_rec_type;
344 l_proc varchar2(72) := g_package||'upd';
345 --
346 Begin
347 hr_utility.set_location('Entering:'||l_proc, 5);
348 --
349 -- Call conversion function to turn arguments into the
350 -- l_rec structure.
351 --
352 l_rec :=
353 hr_pat_shd.convert_args
354 (
355 p_pattern_id,
356 p_pattern_name,
357 p_pattern_start_weekday,
358 p_pattern_start_time,
359 p_object_version_number
360 );
361 --
362 -- Having converted the arguments into the
363 -- plsql record structure we call the corresponding record
364 -- business process.
365 --
366 upd(l_rec, p_validate);
367 p_object_version_number := l_rec.object_version_number;
368 --
369 hr_utility.set_location(' Leaving:'||l_proc, 10);
370 End upd;
371 --
372 end hr_pat_upd;