[Home] [Help]
PACKAGE BODY: APPS.BSC_MESSAGE
Source
1 PACKAGE BODY BSC_MESSAGE AS
2 /* $Header: BSCUMSGB.pls 120.0 2005/06/01 16:02:21 appldev noship $ */
3
4 -- Global Variables
5 --
6 -- Message_Rec_Type
7 --
8 -- Type: message type
9 -- Source: calling funcation
10 -- Message: message string
11 --
12
13 Type Message_Rec_Type Is Record (
14 Type Number(3) := NULL,
15 Source Varchar2(80) := NULL,
16 Message Varchar2(2000) := NULL
17 );
18
19 --
20 -- Message_Tbl_Type: A global table type to store all messages
21 --
22 TYPE Message_Tbl_Type IS TABLE OF Message_Rec_Type
23 INDEX BY BINARY_INTEGER;
24
25 G_Msg_Tbl Message_Tbl_Type;
26
27 --
28 -- Global variables:
29 --
30 -- G_Msg_Count: holds number of all the messages on stack
31 -- G_T0_Count: number of type 0 messages on stack
32 -- G_T1_Count: number of type 1 messages on stack
33 -- G_T2_Count: number of type 2 messages on stack
34 -- G_T3_Count: number of type 3 messages on stack
35 -- G_Debug_Count: number of debug messages(type 4) on stack
36 -- G_session_id: database session_id
37 -- G_user_id: database user id
38 --
39 G_Msg_Count Number := 0;
40 G_T0_Count Number := 0;
41 G_T1_Count Number := 0;
42 G_T2_Count Number := 0;
43 G_T3_Count Number := 0;
44 G_Debug_Count Number := 0;
45 G_session_id Number := -1;
46 G_user_id Number := -1;
47 G_debug_flag Varchar2(3) := 'NO';
48
49 Procedure Init (
50 x_debug_flag IN Varchar2 := 'NO'
51 ) Is
52 Begin
53 G_Msg_Tbl.Delete;
54 G_Msg_Count := 0;
55 G_T0_Count := 0;
56 G_T1_Count := 0;
57 G_T2_Count := 0;
58 G_T3_Count := 0;
59 -- Init deletes all the messages in the stack: g_msg_tbl.delete,
60 -- and thus, debug message count goes down to zero as well.
61 G_Debug_Count := 0;
62
63 G_debug_flag := x_debug_flag;
64
65 if (x_debug_flag = 'YES') then
66 bsc_utility.enable_debug;
67 else
68 bsc_utility.disable_debug;
69 end if;
70
71 -- Ref: bug#3482442 In corner cases this query can return more than one
72 -- row and it will fail. AUDSID is not PK. After meeting with
73 -- Vinod and Kris and Venu, we should use FNG_GLOBAL.user_id
74 G_user_id := BSC_APPS.fnd_global_user_id;
75 G_session_id := USERENV('SESSIONID');
76
77 End Init;
78
79 Procedure Reset (
80 x_debug_flag IN Varchar2 := NULL
81 ) Is
82 Begin
83
84 BSC_Message.init(x_debug_flag);
85
86 End Reset;
87
88 Function Count (
89 x_type IN Number := NULL
90 ) Return Number Is
91 Begin
92 if (x_type is null) then
93 Return G_Msg_Count;
94 elsif (x_type = 0) then
95 return G_T0_Count;
96 elsif (x_type = 1) then
97 return G_T1_Count;
98 elsif (x_type = 2) then
99 return G_T2_Count;
100 elsif (x_type = 3) then
101 return G_T3_Count;
102 elsif (x_type = 4) then
103 return G_Debug_Count;
104 end if;
105
106 return (0); -- return zero for invalid type.
107
108 End Count;
109
110
111 Procedure Add (
112 x_message IN Varchar2,
113 x_source IN Varchar2,
114 x_type IN Number := 0,
115 x_mode IN Varchar2 := 'N'
116 ) Is
117 l_msg_str Varchar2(2000);
118 Begin
119
120 if (x_type = 0) then
121 l_msg_str := 'OBSC-1000: ' || x_source || ', ' || x_message;
122 else
123 if (x_message = NULL) then
124 l_msg_str := 'OBSC-2000: ' || x_source;
125 else
126 l_msg_str := x_message;
127 end if;
128 end if;
129
130 G_Msg_Count := G_Msg_Count + 1;
131
132 G_Msg_Tbl(G_Msg_Count).Type := x_type;
133 G_Msg_Tbl(G_Msg_Count).Source := x_source;
134 G_Msg_Tbl(G_Msg_Count).Message := l_msg_str;
135
136 if (x_type = 0) then
137 G_T0_Count := G_T0_Count + 1;
138 elsif (x_type = 1) then
139 G_T1_Count := G_T1_Count + 1;
140 elsif (x_type = 2) then
141 G_T2_Count := G_T2_Count + 1;
142 elsif (x_type = 3) then
143 G_T3_Count := G_T3_Count + 1;
144 elsif (x_type = 4) then
145 G_Debug_Count := G_Debug_Count + 1;
146 end if;
147
148 if (x_mode = 'I') then
149
150 Insert Into BSC_MESSAGE_LOGS(
151 Source,
152 Type,
153 Message,
154 Creation_Date, Created_By,
155 Last_Update_Date, Last_Updated_By,
156 Last_Update_Login)
157 Values(x_source, x_type, l_msg_str,
158 SYSDATE, G_user_id,
159 SYSDATE, G_user_id, G_session_id
160 );
161
162 end if;
163
164 End Add;
165
166
167
168 Procedure Flush Is
169 Begin
170
171 For i In 1 .. G_Msg_Count
172 Loop
173
174 Insert Into BSC_MESSAGE_LOGS(
175 Source,
176 Type,
177 Message,
178 Creation_Date, Created_By,
179 Last_Update_Date, Last_Updated_By,
180 Last_Update_Login)
181 Values (
182 G_Msg_Tbl(i).Source,
183 G_Msg_Tbl(i).Type,
184 G_Msg_Tbl(i).Message,
185 SYSDATE, G_user_id,
186 SYSDATE, G_user_id, G_session_id
187 );
188
189 End Loop;
190
191 BSC_Message.Reset(
192 x_debug_flag => G_debug_flag
193 );
194
195 End Flush;
196
197 --
198 -- Name: Clean
199 -- Desc: Delete message from BSC_MESSAGE_LOGS if debug_flag is 'NO'
200 --
201 Procedure Clean Is
202 Begin
203
204 if (G_debug_flag = 'NO') then
205
206 delete
207 from BSC_MESSAGE_LOGS
208 where
209 last_update_login = G_session_id;
210 end if;
211
212 Exception
213 When Others Then
214 BSC_MESSAGE.add(
215 x_message => sqlerrm,
216 x_source => 'BSC_MESSAGE.Clean'
217 );
218 End Clean;
219
220
221 Procedure Show Is
222 l_count Number;
223 Begin
224
225 l_count := G_Msg_Tbl.Count;
226
227 --dbms_output.put_line('OBSC Message Stacks: ' || to_char(l_count) || '/' ||
228 -- to_char(G_Msg_Count) || ' Messages.');
229
230 For i In 1 .. l_count
231 Loop
232 NULL;
233 --dbms_output.put_line(to_char(i) || '-' ||
234 -- To_Char(G_Msg_Tbl(i).Type) || ': ' ||
235 -- G_Msg_Tbl(i).Source || ' - ' ||
236 -- G_Msg_Tbl(i).Message
237 -- );
238 End Loop;
239
240 Exception
241 When Others Then
242 NULL;
243 --dbms_output.put_line('Fatal Error - ' || SQLERRM);
244
245 End Show;
246
247 END BSC_MESSAGE;