1 Package Body hr_cau_ins as
2 /* $Header: hrcaurhi.pkb 120.0 2005/05/29 02:29:58 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' hr_cau_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 set and unset the g_api_dml status as required (as we are about to
21 -- perform dml).
22 -- 3) To insert the row into the schema.
23 -- 4) To trap any constraint violations that may have occurred.
24 -- 5) To raise any other errors.
25 --
26 -- Pre Conditions:
27 -- This is an internal private procedure which must be called from the ins
28 -- procedure and must have all mandatory attributes set (except the
29 -- object_version_number which is initialised within this procedure).
30 --
31 -- In Parameters:
32 -- A Pl/Sql record structre.
33 --
34 -- Post Success:
35 -- The specified row will be inserted into the schema.
36 --
37 -- Post Failure:
38 -- On the insert 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 -- None.
47 --
48 -- Access Status:
49 -- Internal Table Handler Use Only.
50 --
51 -- {End Of Comments}
52 -- ----------------------------------------------------------------------------
53 Procedure insert_dml(p_rec in out nocopy hr_cau_shd.g_rec_type) is
54 --
55 l_proc varchar2(72) := g_package||'insert_dml';
56 --
57 Begin
58 hr_utility.set_location('Entering:'||l_proc, 5);
59 p_rec.object_version_number := 1; -- Initialise the object version
60 --
61 hr_cau_shd.g_api_dml := true; -- Set the api dml status
62 --
63 -- Insert the row into: hr_calendar_usages
64 --
65 insert into hr_calendar_usages
66 ( calendar_id,
67 calendar_usage_id,
68 primary_key_value,
69 purpose_usage_id,
70 start_date,
71 end_date,
72 object_version_number
73 )
74 Values
75 ( p_rec.calendar_id,
76 p_rec.calendar_usage_id,
77 p_rec.primary_key_value,
78 p_rec.purpose_usage_id,
79 p_rec.start_date,
80 p_rec.end_date,
81 p_rec.object_version_number
82 );
83 --
84 hr_cau_shd.g_api_dml := false; -- Unset the api dml status
85 --
86 hr_utility.set_location(' Leaving:'||l_proc, 10);
87 Exception
88 When hr_api.check_integrity_violated Then
89 -- A check constraint has been violated
90 hr_cau_shd.g_api_dml := false; -- Unset the api dml status
91 hr_cau_shd.constraint_error
92 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
93 When hr_api.parent_integrity_violated Then
94 -- Parent integrity has been violated
95 hr_cau_shd.g_api_dml := false; -- Unset the api dml status
96 hr_cau_shd.constraint_error
97 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
98 When hr_api.unique_integrity_violated Then
99 -- Unique integrity has been violated
100 hr_cau_shd.g_api_dml := false; -- Unset the api dml status
101 hr_cau_shd.constraint_error
102 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
103 When Others Then
104 hr_cau_shd.g_api_dml := false; -- Unset the api dml status
105 Raise;
106 End insert_dml;
107 --
108 -- ----------------------------------------------------------------------------
109 -- |------------------------------< pre_insert >------------------------------|
110 -- ----------------------------------------------------------------------------
111 -- {Start Of Comments}
112 --
113 -- Description:
114 -- This private procedure contains any processing which is required before
115 -- the insert dml. Presently, if the entity has a corresponding primary
116 -- key which is maintained by an associating sequence, the primary key for
117 -- the entity will be populated with the next sequence value in
118 -- preparation for the insert dml.
119 --
120 -- Pre Conditions:
121 -- This is an internal procedure which is called from the ins procedure.
122 --
123 -- In Parameters:
124 -- A Pl/Sql record structre.
125 --
126 -- Post Success:
127 -- Processing continues.
128 --
129 -- Post Failure:
130 -- If an error has occurred, an error message and exception will be raised
131 -- but not handled.
132 --
133 -- Developer Implementation Notes:
134 -- Any pre-processing required before the insert dml is issued should be
135 -- coded within this procedure. As stated above, a good example is the
136 -- generation of a primary key number via a corresponding sequence.
137 -- It is important to note that any 3rd party maintenance should be reviewed
138 -- before placing in this procedure.
139 --
140 -- Access Status:
141 -- Internal Table Handler Use Only.
142 --
143 -- {End Of Comments}
144 -- ----------------------------------------------------------------------------
145 Procedure pre_insert(p_rec in out nocopy hr_cau_shd.g_rec_type) is
146 --
147 l_proc varchar2(72) := g_package||'pre_insert';
148 --
149 Cursor C_Sel1 is select hr_calendar_usages_s.nextval from sys.dual;
150 --
151 Begin
152 hr_utility.set_location('Entering:'||l_proc, 5);
153 --
154 --
155 -- Select the next sequence number
156 --
157 Open C_Sel1;
158 Fetch C_Sel1 Into p_rec.calendar_usage_id;
159 Close C_Sel1;
160 --
161 hr_utility.set_location(' Leaving:'||l_proc, 10);
162 End pre_insert;
163 --
164 -- ----------------------------------------------------------------------------
165 -- |-----------------------------< post_insert >------------------------------|
166 -- ----------------------------------------------------------------------------
167 -- {Start Of Comments}
168 --
169 -- Description:
170 -- This private procedure contains any processing which is required after the
171 -- insert dml.
172 --
173 -- Pre Conditions:
174 -- This is an internal procedure which is called from the ins procedure.
175 --
176 -- In Parameters:
177 -- A Pl/Sql record structre.
178 --
179 -- Post Success:
180 -- Processing continues.
181 --
182 -- Post Failure:
183 -- If an error has occurred, an error message and exception will be raised
184 -- but not handled.
185 --
186 -- Developer Implementation Notes:
187 -- Any post-processing required after the insert dml is issued should be
188 -- coded within this procedure. It is important to note that any 3rd party
189 -- maintenance should be reviewed before placing in this procedure.
190 --
191 -- Access Status:
192 -- Internal Table Handler Use Only.
193 --
194 -- {End Of Comments}
195 -- ----------------------------------------------------------------------------
196 Procedure post_insert(p_rec in hr_cau_shd.g_rec_type) is
197 --
198 l_proc varchar2(72) := g_package||'post_insert';
199 --
200 Begin
201 hr_utility.set_location('Entering:'||l_proc, 5);
202 --
203 hr_utility.set_location(' Leaving:'||l_proc, 10);
204 End post_insert;
205 --
206 -- ----------------------------------------------------------------------------
207 -- |---------------------------------< ins >----------------------------------|
208 -- ----------------------------------------------------------------------------
209 Procedure ins
210 (
211 p_rec in out nocopy hr_cau_shd.g_rec_type,
212 p_validate in boolean default false
213 ) is
214 --
215 l_proc varchar2(72) := g_package||'ins';
216 --
217 Begin
218 hr_utility.set_location('Entering:'||l_proc, 5);
219 --
220 -- Determine if the business process is to be validated.
221 --
222 If p_validate then
223 --
224 -- Issue the savepoint.
225 --
226 SAVEPOINT ins_hr_cau;
227 End If;
228 --
229 -- Call the supporting insert validate operations
230 --
231 hr_cau_bus.insert_validate(p_rec);
232 --
233 -- Call the supporting pre-insert operation
234 --
235 pre_insert(p_rec);
236 --
237 -- Insert the row
238 --
239 insert_dml(p_rec);
240 --
241 -- Call the supporting post-insert operation
242 --
243 post_insert(p_rec);
244 --
245 -- If we are validating then raise the Validate_Enabled exception
246 --
247 If p_validate then
248 Raise HR_Api.Validate_Enabled;
249 End If;
250 --
251 hr_utility.set_location(' Leaving:'||l_proc, 10);
252 Exception
253 When HR_Api.Validate_Enabled Then
254 --
255 -- As the Validate_Enabled exception has been raised
256 -- we must rollback to the savepoint
257 --
258 ROLLBACK TO ins_hr_cau;
259 end ins;
260 --
261 -- ----------------------------------------------------------------------------
262 -- |---------------------------------< ins >----------------------------------|
263 -- ----------------------------------------------------------------------------
264 Procedure ins
265 (
266 p_calendar_id in number,
267 p_calendar_usage_id out nocopy number,
268 p_primary_key_value in number,
269 p_purpose_usage_id in number,
270 p_start_date in date,
271 p_end_date in date default hr_general.end_of_time,
272 p_object_version_number out nocopy number,
273 p_validate in boolean default false
274 ) is
275 --
276 l_rec hr_cau_shd.g_rec_type;
277 l_proc varchar2(72) := g_package||'ins';
278 --
279 Begin
280 hr_utility.set_location('Entering:'||l_proc, 5);
281 --
282 -- Call conversion function to turn arguments into the
283 -- p_rec structure.
284 --
285 l_rec :=
286 hr_cau_shd.convert_args
287 (
288 p_calendar_id,
289 null,
290 p_primary_key_value,
291 p_purpose_usage_id,
292 p_start_date,
293 p_end_date,
294 null
295 );
296 --
297 -- Having converted the arguments into the hr_cau_rec
298 -- plsql record structure we call the corresponding record business process.
299 --
300 ins(l_rec, p_validate);
301 --
302 -- As the primary key argument(s)
303 -- are specified as an OUT's we must set these values.
304 --
305 p_calendar_usage_id := l_rec.calendar_usage_id;
306 p_object_version_number := l_rec.object_version_number;
307 --
308 hr_utility.set_location(' Leaving:'||l_proc, 10);
309 End ins;
310 --
311 end hr_cau_ins;