DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_ACF_SHD

Source


1 Package Body ame_acf_shd as
2 /* $Header: amacfrhi.pkb 120.5 2006/12/23 12:19:44 avarri noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ame_acf_shd.';  -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |---------------------------< constraint_error >---------------------------|
12 -- ----------------------------------------------------------------------------
13 Procedure constraint_error
14   (p_constraint_name in all_constraints.constraint_name%TYPE
15   ) Is
16 --
17   l_proc        varchar2(72) := g_package||'constraint_error';
18 --
19 Begin
20   --
21   If (p_constraint_name = 'AME_ACTION_TYPE_CONFIG_PK') Then
22     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
23     fnd_message.set_token('PROCEDURE', l_proc);
24     fnd_message.set_token('STEP','5');
25     fnd_message.raise_error;
26   Else
27     fnd_message.set_name('PAY', 'HR_7877_API_INVALID_CONSTRAINT');
28     fnd_message.set_token('PROCEDURE', l_proc);
29     fnd_message.set_token('CONSTRAINT_NAME', p_constraint_name);
30     fnd_message.raise_error;
31   End If;
32   --
33 End constraint_error;
34 --
35 -- ----------------------------------------------------------------------------
36 -- |-----------------------------< api_updating >-----------------------------|
37 -- ----------------------------------------------------------------------------
38 Function api_updating
39   (p_effective_date                   in date
40   ,p_application_id                   in number
41   ,p_action_type_id                   in number
42   ,p_object_version_number            in number
43   ) Return Boolean Is
44   --
45   -- Cursor selects the 'current' row from the HR Schema
46   --
47   Cursor C_Sel1 is
48     select
49      application_id
50     ,action_type_id
51     ,voting_regime
52     ,order_number
53     ,chain_ordering_mode
54     ,start_date
55     ,end_date
56     ,object_version_number
57     from        ame_action_type_config
58     where       action_type_id = p_action_type_id
59  and    application_id = p_application_id
60     and         p_effective_date
61     between     start_date and nvl(end_date - ame_util.oneSecond,p_effective_date);
62 --
63   l_fct_ret     boolean;
64 --
65 Begin
66   --
67   If (p_effective_date is null or
71     -- One of the primary key arguments is null therefore we must
68       p_action_type_id is null or
69       p_object_version_number is null) Then
70     --
72     -- set the returning function value to false
73     --
74     l_fct_ret := false;
75   Else
76     If (p_action_type_id =
77         ame_acf_shd.g_old_rec.action_type_id and
78         p_object_version_number =
79         ame_acf_shd.g_old_rec.object_version_number
80 ) Then
81       --
82       -- The g_old_rec is current therefore we must
83       -- set the returning function to true
84       --
85       l_fct_ret := true;
86     Else
87       --
88       -- Select the current row
89       --
90       Open C_Sel1;
91       Fetch C_Sel1 Into ame_acf_shd.g_old_rec;
92       If C_Sel1%notfound Then
93         Close C_Sel1;
94         --
95         -- The primary key is invalid therefore we must error
96         --
97         fnd_message.set_name('PAY', 'HR_7220_INVALID_PRIMARY_KEY');
98         fnd_message.raise_error;
99       End If;
100       Close C_Sel1;
101                         If (p_object_version_number
102           <> ame_acf_shd.g_old_rec.object_version_number) Then
103         fnd_message.set_name('PAY', 'HR_7155_OBJECT_INVALID');
104         fnd_message.raise_error;
105       End If;
106       l_fct_ret := true;
107     End If;
108   End If;
109   Return (l_fct_ret);
110 --
111 End api_updating;
112 --
113 -- ----------------------------------------------------------------------------
114 -- |-----------------------< upd_end_date >-------------------------|
115 -- ----------------------------------------------------------------------------
116 Procedure upd_end_date
117   (p_effective_date                   in date
118   ,p_application_id                   in number
119   ,p_action_type_id                   in number
120   ,p_new_end_date           in date
121   ,p_validation_start_date            in date
122   ,p_validation_end_date              in date
123   ,p_object_version_number            out nocopy number
124   ) is
125 --
126   l_proc                  varchar2(72) := g_package||'upd_end_date';
127   l_current_user_id       integer;
128   l_object_version_number number;
129 --
130 Begin
131   hr_utility.set_location('Entering:'||l_proc, 5);
132   --
133     -- Because we are updating a row we must get the next object
134   -- version number.
135   --
136   l_object_version_number :=
137     ame_acf_shd.get_object_version_number
138       (p_action_type_id =>  p_action_type_id
139  ,p_application_id =>  p_application_id
140       );
141   --
142   hr_utility.set_location(l_proc, 10);
143   --
144   l_current_user_id := fnd_global.user_id;
145   --
146   -- Update the specified datetrack row setting the effective
147   -- end date to the specified new effective end date.
148   --
149   update ame_action_type_config t
150      set t.end_date              = p_new_end_date
151         ,t.last_updated_by       = l_current_user_id
152         ,t.last_update_date      = p_new_end_date
153         ,t.last_update_login     = l_current_user_id
154         ,t.object_version_number = l_object_version_number
155    where t.action_type_id = p_action_type_id
156  and    t.application_id = p_application_id
157      and p_effective_date between t.start_date
158           and nvl(t.end_date - ame_util.oneSecond,sysdate);
159   --
160   --
161   p_object_version_number := l_object_version_number;
162   hr_utility.set_location(' Leaving:'||l_proc, 15);
163   --
164 End upd_end_date;
165 --
166 -- ----------------------------------------------------------------------------
167 -- |---------------------------------< lck >----------------------------------|
168 -- ----------------------------------------------------------------------------
169 Procedure lck
170   (p_effective_date                   in date
171   ,p_datetrack_mode                   in varchar2
172   ,p_application_id                   in number
173   ,p_action_type_id                   in number
174   ,p_object_version_number            in number
175   ,p_validation_start_date            out nocopy date
176   ,p_validation_end_date              out nocopy date
177   ) is
178 --
179   l_proc                  varchar2(72) := g_package||'lck';
180   l_validation_start_date date;
181   l_validation_end_date   date;
182   l_argument              varchar2(30);
183   --
184   -- Cursor C_Sel1 selects the current locked row as of session date
185   -- ensuring that the object version numbers match.
186   --
187   Cursor C_Sel1 is
188     select
189      application_id
190     ,action_type_id
191     ,voting_regime
192     ,order_number
193     ,chain_ordering_mode
194     ,start_date
195     ,end_date
196     ,object_version_number
197     from    ame_action_type_config
198     where   action_type_id = p_action_type_id
199  and    application_id = p_application_id
200     and     p_effective_date
201     between start_date and nvl(end_date - ame_util.oneSecond, sysdate)
202     for update nowait;
203   --
204   --
205   --
206 Begin
207         hr_utility.set_location('Entering:'||l_proc, 5);
208   --
209   -- Ensure that all the mandatory arguments are not null
210   --
211   hr_api.mandatory_arg_error(p_api_name       => l_proc
212                             ,p_argument       => 'effective_date'
213                             ,p_argument_value => p_effective_date
214                             );
215   --
216   hr_api.mandatory_arg_error(p_api_name       => l_proc
217                             ,p_argument       => 'datetrack_mode'
218                             ,p_argument_value => p_datetrack_mode
219                             );
220   --
221   hr_api.mandatory_arg_error(p_api_name       => l_proc
222                             ,p_argument       => 'action_type_id'
223                             ,p_argument_value => p_action_type_id
224                             );
225   --
226     hr_api.mandatory_arg_error(p_api_name       => l_proc
227                             ,p_argument       => 'object_version_number'
228                             ,p_argument_value => p_object_version_number
229                             );
230   --
231   -- Check to ensure the datetrack mode is not INSERT.
232   --
233   If (p_datetrack_mode <> hr_api.g_insert) then
234     --
235     -- We must select and lock the current row.
236     --
237     Open  C_Sel1;
238     Fetch C_Sel1 Into ame_acf_shd.g_old_rec;
239     If C_Sel1%notfound then
240       Close C_Sel1;
241       --
242       -- The primary key is invalid therefore we must error
243       --
244       fnd_message.set_name('PAY', 'HR_7220_INVALID_PRIMARY_KEY');
245       fnd_message.raise_error;
246     End If;
247     Close C_Sel1;
248     If (p_object_version_number
249           <> ame_acf_shd.g_old_rec.object_version_number) Then
250         fnd_message.set_name('PAY', 'HR_7155_OBJECT_INVALID');
251         fnd_message.raise_error;
252     End If;
253     --
254     --
255     --
256   Else
257     --
258     -- We are doing a datetrack 'INSERT' which is illegal within this
259     -- procedure therefore we must error (note: to lck on insert the
260     -- private procedure ins_lck should be called).
261     --
262     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
263     fnd_message.set_token('PROCEDURE', l_proc);
264     fnd_message.set_token('STEP','20');
265     fnd_message.raise_error;
266   End If;
267   --
268   -- Set the validation start and end date OUT arguments
269   --
270   if (p_datetrack_mode = hr_api.g_update) then
271     p_validation_start_date := p_effective_date;
272     p_validation_end_date   := ame_acf_shd.g_old_rec.end_date;
273   elsif (p_datetrack_mode = hr_api.g_delete) then
274     p_validation_start_date := p_effective_date;
275     p_validation_end_date   := p_effective_date;
276   end if;
277   --
278   hr_utility.set_location(' Leaving:'||l_proc, 30);
279 --
280 -- We need to trap the ORA LOCK exception
281 --
282 Exception
283   When HR_Api.Object_Locked then
284     --
285     -- The object is locked therefore we need to supply a meaningful
286     -- error message.
287     --
288     fnd_message.set_name('PAY', 'HR_7165_OBJECT_LOCKED');
289     fnd_message.set_token('TABLE_NAME', 'ame_action_type_config');
290     fnd_message.raise_error;
291 End lck;
292 --
293 -- ----------------------------------------------------------------------------
294 -- |-----------------------------< convert_args >-----------------------------|
295 -- ----------------------------------------------------------------------------
296 Function convert_args
297   (p_application_id                 in number
298   ,p_action_type_id                 in number
299   ,p_voting_regime                  in varchar2
300   ,p_order_number                   in number
301   ,p_chain_ordering_mode            in varchar2
302   ,p_start_date                     in date
303   ,p_end_date                       in date
304   ,p_object_version_number          in number
305   )
306   Return g_rec_type is
307 --
308   l_rec   g_rec_type;
309 --
310 Begin
311   --
312   -- Convert arguments into local l_rec structure.
313   --
314   l_rec.application_id                   := p_application_id;
315   l_rec.action_type_id                   := p_action_type_id;
316   l_rec.voting_regime                    := p_voting_regime;
317   l_rec.order_number                     := p_order_number;
318   l_rec.chain_ordering_mode              := p_chain_ordering_mode;
319   l_rec.start_date                       := p_start_date;
320   l_rec.end_date                         := p_end_date;
321   l_rec.object_version_number            := p_object_version_number;
322   --
323   -- Return the plsql record structure.
324   --
325   Return(l_rec);
326 --
327 End convert_args;
328 --
329 -- ----------------------------------------------------------------------------
330 -- |------------------------< get_object_version_number >----------------------|
331 -- ----------------------------------------------------------------------------
332 Function get_object_version_number
333   (p_application_id  in  number
334   ,p_action_type_id  in  number
335   )
336   Return number is
337 --
338   l_ovn   number;
339 --
340 Begin
341   --
342   -- get the next ovn
343   --
344   select nvl(max(t.object_version_number),0) + 1
345     into l_ovn
346     from ame_action_type_config t
347    where t.action_type_id = p_action_type_id
348  and    t.application_id = p_application_id;
349   --
350   -- Return the new object_version_number.
351   --
352   Return(l_ovn);
353 --
354 End get_object_version_number;
355   --
356 --
357 end ame_acf_shd;