1 Package Body hr_pab_ins as
2 /* $Header: hrpabrhi.pkb 115.1 99/07/17 05:36:11 porting ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' hr_pab_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 hr_pab_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_pab_shd.g_api_dml := true; -- Set the api dml status
62 --
63 -- Insert the row into: hr_pattern_bits
64 --
65 insert into hr_pattern_bits
66 ( pattern_bit_id,
67 pattern_bit_code,
68 bit_meaning,
69 time_unit_multiplier,
70 base_time_unit,
71 object_version_number
72 )
73 Values
74 ( p_rec.pattern_bit_id,
75 p_rec.pattern_bit_code,
76 p_rec.bit_meaning,
77 p_rec.time_unit_multiplier,
78 p_rec.base_time_unit,
79 p_rec.object_version_number
80 );
81 --
82 hr_pab_shd.g_api_dml := false; -- Unset the api dml status
83 --
84 hr_utility.set_location(' Leaving:'||l_proc, 10);
85 Exception
86 When hr_api.check_integrity_violated Then
87 -- A check constraint has been violated
88 hr_pab_shd.g_api_dml := false; -- Unset the api dml status
89 hr_pab_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 hr_pab_shd.g_api_dml := false; -- Unset the api dml status
94 hr_pab_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 hr_pab_shd.g_api_dml := false; -- Unset the api dml status
99 hr_pab_shd.constraint_error
100 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
101 When Others Then
102 hr_pab_shd.g_api_dml := false; -- Unset the api dml status
103 Raise;
104 End insert_dml;
105 --
106 -- ----------------------------------------------------------------------------
107 -- |------------------------------< pre_insert >------------------------------|
108 -- ----------------------------------------------------------------------------
109 -- {Start Of Comments}
110 --
111 -- Description:
112 -- This private procedure contains any processing which is required before
113 -- the insert dml. Presently, if the entity has a corresponding primary
114 -- key which is maintained by an associating sequence, the primary key for
115 -- the entity will be populated with the next sequence value in
116 -- preparation for the insert dml.
117 --
118 -- Pre Conditions:
119 -- This is an internal procedure which is called from the ins procedure.
120 --
121 -- In Parameters:
122 -- A Pl/Sql record structre.
123 --
124 -- Post Success:
125 -- Processing continues.
126 --
127 -- Post Failure:
128 -- If an error has occurred, an error message and exception will be raised
129 -- but not handled.
130 --
131 -- Developer Implementation Notes:
132 -- Any pre-processing required before the insert dml is issued should be
133 -- coded within this procedure. As stated above, a good example is the
134 -- generation of a primary key number via a corresponding sequence.
135 -- It is important to note that any 3rd party maintenance should be reviewed
136 -- before placing in this procedure.
137 --
138 -- Access Status:
139 -- Internal Table Handler Use Only.
140 --
141 -- {End Of Comments}
142 -- ----------------------------------------------------------------------------
143 Procedure pre_insert(p_rec in out hr_pab_shd.g_rec_type) is
144 --
145 l_proc varchar2(72) := g_package||'pre_insert';
146 --
147 Cursor C_Sel1 is select hr_pattern_bits_s.nextval from sys.dual;
148 --
149 Begin
150 hr_utility.set_location('Entering:'||l_proc, 5);
151 --
152 --
153 -- Select the next sequence number
154 --
155 Open C_Sel1;
156 Fetch C_Sel1 Into p_rec.pattern_bit_id;
157 Close C_Sel1;
158 --
159 hr_utility.set_location(' Leaving:'||l_proc, 10);
160 End pre_insert;
161 --
162 -- ----------------------------------------------------------------------------
163 -- |-----------------------------< post_insert >------------------------------|
164 -- ----------------------------------------------------------------------------
165 -- {Start Of Comments}
166 --
167 -- Description:
168 -- This private procedure contains any processing which is required after the
169 -- insert dml.
170 --
171 -- Pre Conditions:
172 -- This is an internal procedure which is called from the ins procedure.
173 --
174 -- In Parameters:
175 -- A Pl/Sql record structre.
176 --
177 -- Post Success:
178 -- Processing continues.
179 --
180 -- Post Failure:
181 -- If an error has occurred, an error message and exception will be raised
182 -- but not handled.
183 --
184 -- Developer Implementation Notes:
185 -- Any post-processing required after the insert dml is issued should be
186 -- coded within this procedure. It is important to note that any 3rd party
187 -- maintenance should be reviewed before placing in this procedure.
188 --
189 -- Access Status:
190 -- Internal Table Handler Use Only.
191 --
192 -- {End Of Comments}
193 -- ----------------------------------------------------------------------------
194 Procedure post_insert(p_rec in hr_pab_shd.g_rec_type) is
195 --
196 l_proc varchar2(72) := g_package||'post_insert';
197 --
198 Begin
199 hr_utility.set_location('Entering:'||l_proc, 5);
200 --
201 hr_utility.set_location(' Leaving:'||l_proc, 10);
202 End post_insert;
203 --
204 -- ----------------------------------------------------------------------------
205 -- |---------------------------------< ins >----------------------------------|
206 -- ----------------------------------------------------------------------------
207 Procedure ins
208 (
209 p_rec in out hr_pab_shd.g_rec_type,
210 p_validate in boolean default false
211 ) is
212 --
213 l_proc varchar2(72) := g_package||'ins';
214 --
215 Begin
216 hr_utility.set_location('Entering:'||l_proc, 5);
217 --
218 -- Determine if the business process is to be validated.
219 --
220 If p_validate then
221 --
222 -- Issue the savepoint.
223 --
224 SAVEPOINT ins_hr_pab;
225 End If;
226 --
227 -- Call the supporting insert validate operations
228 --
229 hr_pab_bus.insert_validate(p_rec);
230 --
231 -- Call the supporting pre-insert operation
232 --
233 pre_insert(p_rec);
234 --
235 -- Insert the row
236 --
237 insert_dml(p_rec);
238 --
239 -- Call the supporting post-insert operation
240 --
241 post_insert(p_rec);
242 --
243 -- If we are validating then raise the Validate_Enabled exception
244 --
245 If p_validate then
246 Raise HR_Api.Validate_Enabled;
247 End If;
248 --
249 hr_utility.set_location(' Leaving:'||l_proc, 10);
250 Exception
251 When HR_Api.Validate_Enabled Then
252 --
253 -- As the Validate_Enabled exception has been raised
254 -- we must rollback to the savepoint
255 --
256 ROLLBACK TO ins_hr_pab;
257 end ins;
258 --
259 -- ----------------------------------------------------------------------------
260 -- |---------------------------------< ins >----------------------------------|
261 -- ----------------------------------------------------------------------------
262 Procedure ins
263 (
264 p_pattern_bit_id out number,
265 p_pattern_bit_code in varchar2,
266 p_bit_meaning in varchar2,
267 p_time_unit_multiplier in number,
268 p_base_time_unit in varchar2,
269 p_object_version_number out number,
270 p_validate in boolean default false
271 ) is
272 --
273 l_rec hr_pab_shd.g_rec_type;
274 l_proc varchar2(72) := g_package||'ins';
275 --
276 Begin
277 hr_utility.set_location('Entering:'||l_proc, 5);
278 --
279 -- Call conversion function to turn arguments into the
280 -- p_rec structure.
281 --
282 l_rec :=
283 hr_pab_shd.convert_args
284 (
285 null,
286 p_pattern_bit_code,
287 p_bit_meaning,
288 p_time_unit_multiplier,
289 p_base_time_unit,
290 null
291 );
292 --
293 -- Having converted the arguments into the hr_pab_rec
294 -- plsql record structure we call the corresponding record business process.
295 --
296 ins(l_rec, p_validate);
297 --
298 -- As the primary key argument(s)
299 -- are specified as an OUT's we must set these values.
300 --
301 p_pattern_bit_id := l_rec.pattern_bit_id;
302 p_object_version_number := l_rec.object_version_number;
303 --
304 hr_utility.set_location(' Leaving:'||l_proc, 10);
305 End ins;
306 --
307 end hr_pab_ins;