DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_PAT_INS

Source


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