DBA Data[Home] [Help]

PACKAGE BODY: APPS.FF_ARC_SHD

Source


1 Package Body ff_arc_shd as
2 /* $Header: ffarcrhi.pkb 115.4 2002/12/23 13:59:55 arashid ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)	:= '  ff_arc_shd.';  -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |------------------------< return_api_dml_status >-------------------------|
12 -- ----------------------------------------------------------------------------
13 Function return_api_dml_status Return Boolean Is
14 --
15   l_proc 	varchar2(72) := g_package||'return_api_dml_status';
16 --
17 Begin
18   hr_utility.set_location('Entering:'||l_proc, 5);
19   --
20   Return (nvl(g_api_dml, false));
21   --
22   hr_utility.set_location(' Leaving:'||l_proc, 10);
23 End return_api_dml_status;
24 --
25 -- ----------------------------------------------------------------------------
26 -- |---------------------------< constraint_error >---------------------------|
27 -- ----------------------------------------------------------------------------
28 Procedure constraint_error
29             (p_constraint_name in all_constraints.constraint_name%TYPE) Is
30 --
31   l_proc 	varchar2(72) := g_package||'constraint_error';
32 --
33 Begin
34   hr_utility.set_location('Entering:'||l_proc, 5);
35   --
36   If (p_constraint_name = 'FF_ARCHIVE_ITEMS_FK1') Then
37     hr_utility.set_message(800, 'FF_34956_INVALID_USER_ENTITY');
38     hr_utility.raise_error;
39   ElsIf (p_constraint_name = 'FF_ARCHIVE_ITEMS_PK') Then
40     /*Raise Generic Primary Key Constraint violation, supplying con. name*/
41     hr_utility.set_message(800, 'HR_7220_INVALID_PRIMARY_KEY');
42     hr_utility.set_message_token('CONSTRAINT_NAME', p_constraint_name);
43     hr_utility.raise_error;
44   Else
45     hr_utility.set_message(801, 'HR_7877_API_INVALID_CONSTRAINT');
46     hr_utility.set_message_token('PROCEDURE', l_proc);
47     hr_utility.set_message_token('CONSTRAINT_NAME', p_constraint_name);
48     hr_utility.raise_error;
49   End If;
50   --
51   hr_utility.set_location(' Leaving:'||l_proc, 10);
52 End constraint_error;
53 --
54 -- ----------------------------------------------------------------------------
55 -- |-----------------------------< api_updating >-----------------------------|
56 -- ----------------------------------------------------------------------------
57 Function api_updating
58   (
59   p_archive_item_id                    in number,
60   p_object_version_number              in number
61   )      Return Boolean Is
62   --
63   -- Cursor selects the 'current' row from the HR Schema
64   --
65   Cursor C_Sel1 is
66     select
67 	archive_item_id,
68 	user_entity_id,
69         archive_type,
70 	context1,
71 	value,
72 	object_version_number
73     from	ff_archive_items
74     where	archive_item_id = p_archive_item_id;
75 --
76   l_proc	varchar2(72)	:= g_package||'api_updating';
77   l_fct_ret	boolean;
78 --
79 Begin
80   hr_utility.set_location('Entering:'||l_proc, 5);
81   --
82   If (
83 	p_archive_item_id is null and
84 	p_object_version_number is null
85      ) Then
86     --
87     -- One of the primary key arguments is null therefore we must
88     -- set the returning function value to false
89     --
90     l_fct_ret := false;
91   Else
92     If (
93 	p_archive_item_id = g_old_rec.archive_item_id and
94 	p_object_version_number = g_old_rec.object_version_number
95        ) Then
96       hr_utility.set_location(l_proc, 10);
97       --
98       -- The g_old_rec is current therefore we must
99       -- set the returning function to true
100       --
101       l_fct_ret := true;
102     Else
103       --
104       -- Select the current row into g_old_rec
105       --
106       Open C_Sel1;
107       Fetch C_Sel1 Into g_old_rec;
108       If C_Sel1%notfound Then
109         Close C_Sel1;
110         --
111         -- The primary key is invalid therefore we must error
112         --
113         hr_utility.set_message(801, 'HR_7220_INVALID_PRIMARY_KEY');
114         hr_utility.raise_error;
115       End If;
116       Close C_Sel1;
117       If (p_object_version_number <> g_old_rec.object_version_number) Then
118         hr_utility.set_message(801, 'HR_7155_OBJECT_INVALID');
119         hr_utility.raise_error;
120       End If;
121       hr_utility.set_location(l_proc, 15);
122       l_fct_ret := true;
123     End If;
124   End If;
125   hr_utility.set_location(' Leaving:'||l_proc, 20);
126   Return (l_fct_ret);
127 --
128 End api_updating;
129 --
130 -- ----------------------------------------------------------------------------
131 -- |---------------------------------< lck >----------------------------------|
132 -- ----------------------------------------------------------------------------
133 Procedure lck
134   (
135   p_archive_item_id                    in number,
136   p_object_version_number              in number
137   ) is
138 --
139 -- Cursor selects the 'current' row from the HR Schema
140 --
141   Cursor C_Sel1 is
142     select 	archive_item_id,
143 	user_entity_id,
144         archive_type,
145 	context1,
146 	value,
147 	object_version_number
148     from	ff_archive_items
149     where	archive_item_id = p_archive_item_id
150     for	update nowait;
151 --
152   l_proc	varchar2(72) := g_package||'lck';
153 --
154 Begin
155   hr_utility.set_location('Entering:'||l_proc, 5);
156   --
157   -- Add any mandatory argument checking here:
158   hr_api.mandatory_arg_error
159     (p_api_name       => l_proc,
160      p_argument       => 'object_version_number',
161      p_argument_value => p_object_version_number);
162   --
163   Open  C_Sel1;
164   Fetch C_Sel1 Into g_old_rec;
165   If C_Sel1%notfound then
166     Close C_Sel1;
167     --
168     -- The primary key is invalid therefore we must error
169     --
170     hr_utility.set_message(801, 'HR_7220_INVALID_PRIMARY_KEY');
171     hr_utility.raise_error;
172   End If;
173   Close C_Sel1;
174   If (p_object_version_number <> g_old_rec.object_version_number) Then
175         hr_utility.set_message(801, 'HR_7155_OBJECT_INVALID');
176         hr_utility.raise_error;
177       End If;
178 --
179   hr_utility.set_location(' Leaving:'||l_proc, 10);
180 --
181 -- We need to trap the ORA LOCK exception
182 --
183 Exception
184   When HR_Api.Object_Locked then
185     --
186     -- The object is locked therefore we need to supply a meaningful
187     -- error message.
188     --
189     hr_utility.set_message(801, 'HR_7165_OBJECT_LOCKED');
190     hr_utility.set_message_token('TABLE_NAME', 'ff_archive_items');
191     hr_utility.raise_error;
192 End lck;
193 --
194 -- ----------------------------------------------------------------------------
195 -- |-----------------------------< convert_args >-----------------------------|
196 -- ----------------------------------------------------------------------------
197 Function convert_args
198 	(
199 	p_archive_item_id               in number,
200 	p_user_entity_id                in number,
201         p_archive_type                  in varchar2,
202 	p_context1                      in number,
203 	p_value                         in varchar2,
204 	p_object_version_number         in number
205 	)
206 	Return g_rec_type is
207 --
208   l_rec	  g_rec_type;
209   l_proc  varchar2(72) := g_package||'convert_args';
210 --
211 Begin
212   --
213   hr_utility.set_location('Entering:'||l_proc, 5);
214   --
215   -- Convert arguments into local l_rec structure.
216   --
217   l_rec.archive_item_id                  := p_archive_item_id;
218   l_rec.user_entity_id                   := p_user_entity_id;
219   l_rec.archive_type                     := p_archive_type;
220   l_rec.context1                         := p_context1;
221   l_rec.value                            := p_value;
222   l_rec.object_version_number            := p_object_version_number;
223   --
224   -- Return the plsql record structure.
225   --
226   hr_utility.set_location(' Leaving:'||l_proc, 10);
227   Return(l_rec);
228 --
229 End convert_args;
230 --
231 --
232 -- ----------------------------------------------------------------------------
233 -- |-----------------------------< chk_value >-----------------------------|
234 -- ----------------------------------------------------------------------------
235 --
236 -- Check that the User entity exists, and that the data type is correct
237 -- (of the value).
238 --
239 procedure chk_value
240    (p_value	     in	  ff_archive_items.value%TYPE,
241     p_user_entity_id in   ff_archive_items.user_entity_id%TYPE)
242 is
243 --
244 proc_error      exception;
245 l_data_type     varchar2(1);
246 l_item_name     varchar2(80);
247 l_proc		varchar2(72)   := g_package||'chk_value';
248 l_conv_number   number;
249 l_conv_date     date;
250 --
251 -- Cursor to check that UE is the correct type
252 -- (X for archive items) and obtain the data
253 -- type.
254 --
255 cursor csr_entity_chk (c_user_entity_id number) is
256  select db.data_type, db.user_name
257  from ff_database_items db,
258       ff_user_entities ue
259  where ue.user_entity_id = c_user_entity_id
260  and ue.creator_type = 'X'
261  and ue.user_entity_id = db.user_entity_id;
262 --
263 Begin
264 --
265 hr_utility.set_location('Entering:'||l_proc, 5);
266 hr_utility.trace('p_value:'||p_value);
267 --
268 -- Only execute the checking code if the value has changed on
269 -- update (or insert and is not null).
270 --
271   if (((p_value is not null) and
272     nvl(ff_arc_shd.g_old_rec.value, hr_api.g_varchar2) <>
273      nvl(p_value, hr_api.g_varchar2))
274    or (p_value is null)) then
275    --
276    -- The value has changed or this is new, so check.
277    --
278    hr_utility.set_location(l_proc, 7);
279    --
280    -- Obtain the data type and name from the DBI
281    -- If this is not found, the creator type may be
282    -- wrong, or rows missing for this ue, so error.
283    --
284       open csr_entity_chk(p_user_entity_id);
285       fetch csr_entity_chk into l_data_type, l_item_name;
286       IF csr_entity_chk%notfound then
287          raise proc_error;
288       END IF;
289       close csr_entity_chk;
290    --
291    hr_utility.trace('Data type'||l_data_type);
292    hr_utility.trace('Name: '||l_item_name);
293    --
294    -- Ensure that this value is of the correct data type.
295    -- raising Oracle errors where necessary. This removes the
296    -- need for complex string manipulation to ascertain
297    -- value's correct formatting.
298    -- Note that the p_value string is not changed.
299    --
300      If l_data_type = 'N' then
301         --Number type, check the value.
302         --If this fails, an invalid_number exception will be raised.
303         --Otherwise the program can carry on as normal.
304         l_conv_number := to_number(p_value);
305      Elsif l_data_type = 'D' then
306         -- Date type must be in Canonical format. If this conversion
307         -- fails, raise invalid value error. Although this would
308         -- normally raise an ORA-1858, this saves user seeing the
309         -- default all_procedure_fail.
310         BEGIN
311         l_conv_date := fnd_date.canonical_to_date(p_value);
312         EXCEPTION WHEN others THEN
313            raise value_error;
314         END;
315         hr_utility.trace('Date:'||to_char(l_conv_date));
316      Elsif l_data_type = 'T' then
317         -- This data type (subj to checking) can hold any alpha-numeric
318         -- string. No checking as yet.
319         NULL;
320      End If;
321    --
322   end if;
323 --
324   hr_utility.set_location('Leaving:'||l_proc, 10);
325 --
326 exception
327 when proc_error then
328   -- The User Entity does not exist, or is not type X.
329   -- raise apt error.
330   hr_utility.set_message(800, 'FF_34956_INVALID_USER_ENTITY');
331   hr_utility.raise_error;
332 --
333 -- Raise Incorrect Datatype error in two circumstances.
334 --
335 when value_error then
336   hr_utility.set_message(800, 'FF_34960_INVALID_ARCHIVE_VALUE');
337   hr_utility.set_message_token('ITEM_NAME', l_item_name);
338   hr_utility.set_message_token('ITEM_VALUE', p_value);
339   hr_utility.raise_error;
340 when invalid_number then
341   hr_utility.set_message(800, 'FF_34960_INVALID_ARCHIVE_VALUE');
342   hr_utility.set_message_token('ITEM_NAME', l_item_name);
343   hr_utility.set_message_token('ITEM_VALUE', p_value);
344   hr_utility.raise_error;
345 when others then -- catch all for any other errors (standard).
346   hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
347   hr_utility.set_message_token('PROCEDURE', l_proc);
348   hr_utility.set_message_token('STEP','20');
349   hr_utility.raise_error;
350 --
351 end chk_value;
352 
353 end ff_arc_shd;