DBA Data[Home] [Help]

PACKAGE BODY: APPS.JTF_DBSTREAM_UTILS

Source


1 PACKAGE BODY JTF_DBSTREAM_UTILS AS
2 /* $Header: JTFSTRMB.pls 115.10 2002/12/04 17:53:06 pseo ship $ */
3 
4   inputStream           streamType;
5   readerPosition        pls_integer;
6   readerCharIndex       pls_integer;
7   readerRowIndex        pls_integer := 1;
8   outputStream          streamType;
9   writerRowIndex        pls_integer;
10 
11   leadingDelimiter      constant varchar2(5) := '[';
12   trailingDelimiter     constant varchar2(5) := ']';
13 
14   INVALID_DELIMITER     exception;
15   INVALID_STRING_LENGTH exception;
16   INVALID_READER_POS	  exception;
17   INVALID_STREAM    	  exception;
18   NULL_STREAM    	      exception;
19   UNSUPPORTED_OPERATION exception;
20   END_OF_STREAM         exception;
21 
22   STREAM_OVERHEAD       constant pls_integer := 100;
23   MAX_STREAM_LENGTH     constant pls_integer := jtf_dbstring_utils.getMaxStringLength - STREAM_OVERHEAD;
24   MAX_STRING_LENGTH     constant pls_integer := 32767;
25 
26   INT_SEPARATOR         constant varchar2(1) := ':';
27 
28 ------------------------------------------------------------------------------
29 --  PRIVATE METHODS
30 -----------------------------------------------------------------------------
31 
32 procedure initInputStreamVariables is
33 begin
34   readerPosition  := 1;
35   readerCharIndex := 1;
36   readerRowIndex  := inputStream.FIRST;
37 exception
38 	when others then
39 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
40 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
41 	  fnd_message.set_token('MSG','jtf_dbstream_utils.initInputStreamVariables :'||SQLERRM);
42 	  app_exception.raise_exception;
43 end initInputStreamVariables;
44 -----------------------------------------------------------------------------
45 
46 procedure clearInputStream is
47 begin
48 	inputStream.DELETE;
49 exception
50 	when others then
51 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
52 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
53 	  fnd_message.set_token('MSG','jtf_dbstream_utils.clearInputStream :'||SQLERRM);
54 	  app_exception.raise_exception;
55 end clearInputStream;
56 
57 -----------------------------------------------------------------------------
58 
59 function getTrailingDelimiterPos(rowIndex in pls_integer
60                                 ,leadingDelimiterPos in pls_integer) return pls_integer is
61 begin
62  	return instr(inputStream(rowIndex),trailingDelimiter,leadingDelimiterPos);
63 exception
64 	when others then
65 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
66 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
67 	  fnd_message.set_token('MSG','jtf_dbstream_utils.getTrailingDelimiterPos :'||SQLERRM);
68 	  app_exception.raise_exception;
69 end getTrailingDelimiterPos;
70 ------------------------------------------------------------------------------
71 
72 function getStringLength(rowIndex in pls_integer
73                         ,leadingDelimiterPos in pls_integer
74                         ,trailingDelimiterPos in pls_integer) return integer is
75 begin
76   return to_number(substr(inputStream(rowIndex),leadingDelimiterPos + 1,trailingDelimiterPos - leadingDelimiterPos - 1));
77 exception
78 	when others then
79 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
80 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
81 	  fnd_message.set_token('MSG','jtf_dbstream_utils.getStringLength :'||SQLERRM);
82 	  app_exception.raise_exception;
83 end getStringLength;
84 ------------------------------------------------------------------------------
85 
86 procedure checkForCommonErrors is
87 begin
88 	if inputStream.COUNT = 0 then
89 		raise NULL_STREAM;
90 	elsif inputStream.COUNT > 2 then
91 		raise UNSUPPORTED_OPERATION;
92 	end if;
93 exception
94   when NULL_STREAM then
95     fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
96     fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
97     fnd_message.set_token('MSG','An unexpected error occurred in jtf_dbstream_utils.checkForCommonErrors: No input stream has been set.');
98     app_exception.raise_exception;
99   when UNSUPPORTED_OPERATION then
100     fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
101     fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
102     fnd_message.set_token('MSG','An unexpected error occurred in jtf_dbstream_utils.checkForCommonErrors: Streams made up of multiple rows are not supported in this release.'
103     ||jtf_dbstring_utils.getLineFeed||jtf_dbstring_utils.getLineFeed||'rows: <'||nvl(to_char(inputStream.COUNT),jtf_dbstring_utils.getNullString)||'>');
104     app_exception.raise_exception;
105 	when others then
106 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
107 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
108 	  fnd_message.set_token('MSG','jtf_dbstream_utils.checkForCommonErrors :'||SQLERRM);
109 	  app_exception.raise_exception;
110 end checkForCommonErrors;
111 ------------------------------------------------------------------------------
112 
113 function readNextString return varchar2 is
114   leadingDelimiterPos   pls_integer := readerCharIndex;
115   trailingDelimiterPos  pls_integer;
116   stringLength          integer;
117 begin
118   checkForCommonErrors;
119   if leadingDelimiterPos > length(inputStream(readerRowIndex))
120   and readerRowIndex >= inputStream.COUNT then
121     raise END_OF_STREAM;
122   elsif leadingDelimiterPos > length(inputStream(readerRowIndex))
123   and readerRowIndex < inputStream.COUNT then
124     readerRowIndex := inputStream.NEXT(readerRowIndex);
125     readerCharIndex := 1;
126     leadingDelimiterPos := 1;
127   end if;
128   if instr(inputStream(readerRowIndex),leadingDelimiter,leadingDelimiterPos) <> leadingDelimiterPos then
129     raise INVALID_DELIMITER;
130   end if;
131   trailingDelimiterPos := getTrailingDelimiterPos(readerRowIndex,leadingDelimiterPos);
132   if trailingDelimiterPos is null then
133     raise INVALID_STREAM;
134   end if;
135   stringLength := getStringLength(readerRowIndex,leadingDelimiterPos,trailingDelimiterPos);
136   readerCharIndex := trailingDelimiterPos + stringLength + 1;
137   readerPosition := readerPosition + 1;
138   return substr(inputStream(readerRowIndex),trailingDelimiterPos + 1,stringLength);
139 exception
140   when END_OF_STREAM then
141     fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
142     fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
143     fnd_message.set_token('MSG','An unexpected error occurred in jtf_dbstream_utils.readNextString: The end of the stream has been reached.');
144     app_exception.raise_exception;
145   when INVALID_DELIMITER then
146     fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
147     fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
148     fnd_message.set_token('MSG','An unexpected error occurred in jtf_dbstream_utils.readNextString: Invalid delimiter at:'
149     ||jtf_dbstring_utils.getLineFeed||jtf_dbstring_utils.getLineFeed||'position: <'||nvl(to_char(leadingDelimiterPos),jtf_dbstring_utils.getNullString)||'>'
150     ||jtf_dbstring_utils.getLineFeed||'row: <'||nvl(to_char(readerRowIndex),jtf_dbstring_utils.getNullString)||'>'
151     ||jtf_dbstring_utils.getLineFeed||jtf_dbstring_utils.getLineFeed||'in stream <'||inputStream(readerRowIndex)||'>');
152     app_exception.raise_exception;
153   when INVALID_STREAM then
154     fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
155     fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
156     fnd_message.set_token('MSG','An unexpected error occurred in jtf_dbstream_utils.readNextString: Invalid readerPositition:'
157     ||jtf_dbstring_utils.getLineFeed||jtf_dbstring_utils.getLineFeed||'readerPosition: <'||nvl(to_char(readerPosition),jtf_dbstring_utils.getNullString)||'>'
158     ||jtf_dbstring_utils.getLineFeed||'row: <'||nvl(to_char(readerRowIndex),jtf_dbstring_utils.getNullString)||'>'
159     ||jtf_dbstring_utils.getLineFeed||jtf_dbstring_utils.getLineFeed||'for stream <'||inputStream(readerRowIndex)||'>');
160     app_exception.raise_exception;
161 --	when others then
162 --	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
163 --	  fnd_message.set_token('MSG','jtf_dbstream_utils.readNextString :'||SQLERRM);
164 --	  app_exception.raise_exception;
165 end readNextString;
166 
167 
168 ------------------------------------------------------------------------------
169 --  update the readerIndexes. Should be called when the
170 --  readerPosition is manually changed.
171 --
172 --   NOTE: THE READER AND WRITER UTILS ONLY SUPPORT STREAMS UP TO 32767 BYTES
173 --         AND ONE ROW IN THE STREAM IN THIS VERSION.
174 -----------------------------------------------------------------------------
175 procedure updateReaderIndexes(newReaderPos in pls_integer) is
176   i integer := 1;
177   dummy jtf_dbstring_utils.maxString%TYPE;
178 begin
179   initInputStreamVariables;
180   while i < newReaderPos loop
181   	dummy := readNextString;
182   	i := i + 1;
183   end loop;
184 exception
185 	when others then
186 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
187 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
188 	  fnd_message.set_token('MSG','jtf_dbstream_utils.updateReaderIndexes :'||SQLERRM);
189 	  app_exception.raise_exception;
190 end updateReaderIndexes;
191 
192 
193 procedure writeNextString(s in varchar2) is
194   stringLength integer := nvl(length(s),0);
195   newString    jtf_dbstring_utils.maxString%TYPE := leadingDelimiter || to_char(stringLength) || trailingDelimiter || s;
196 begin
197 	if outputStream.COUNT = 0 then
198 		writerRowIndex := 1;
199 		outputStream(writerRowIndex) := null;
200 	end if;
201 	-- if (length(outputStream(writerRowIndex)) + length(newString)) > jtf_dbstring_utils.getMaxStringLength then
202 
203         --The length method is changed to lengthb to fix bug#2613658
204         if (lengthb(outputStream(writerRowIndex)) + lengthb(newString)) > MAX_STREAM_LENGTH then
205 		writerRowIndex := writerRowIndex + 1;
206 		outputStream(writerRowIndex) := null;
207 	end if;
208   outputStream(writerRowIndex) := outputStream(writerRowIndex) || newString;
209 exception
210 	when others then
211 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
212 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
213 	  fnd_message.set_token('MSG','jtf_dbstream_utils.writeNextString :'||SQLERRM);
214 	  app_exception.raise_exception;
215 end writeNextString;
216 
217 ------------------------------------------------------------------------------
218 --  PUBLIC METHODS
219 -----------------------------------------------------------------------------
220 
221 
222 procedure setLongInputStream(stream in streamType) is
223 begin
224 	clearInputStream;
225 	inputStream := stream;
226 	initInputStreamVariables;
227 exception
228 	when others then
229 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
230 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
231 	  fnd_message.set_token('MSG','jtf_dbstream_utils.setLongInputStream :'||SQLERRM);
232 	  app_exception.raise_exception;
233 end setLongInputStream;
234 
235 -----------------------------------------------------------------------------
236 procedure setInputStream(stream in varchar2) is
237 begin
238 	clearInputStream;
239 	inputStream(1) := stream;
240 	initInputStreamVariables;
241 exception
242 	when others then
243 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
244 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
245 	  fnd_message.set_token('MSG','jtf_dbstream_utils.setInputStream :'||SQLERRM);
246 	  app_exception.raise_exception;
247 end setInputStream;
248 -----------------------------------------------------------------------------
249 procedure setReaderPosition(i in pls_integer) is
250 begin
251  updateReaderIndexes(i);
252 exception
253 	when others then
254 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
255 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
256 	  fnd_message.set_token('MSG','jtf_dbstream_utils.setReaderPosition :'||SQLERRM);
257 	  app_exception.raise_exception;
258 end setReaderPosition;
259 -----------------------------------------------------------------------------
260 function endOfInputStream return boolean is
261 begin
262   if  readerRowIndex <= inputStream.COUNT
263   and	readerCharIndex < length(inputStream(readerRowIndex)) then
264   	return false;
265   else
266   	return true;
267   end if;
268 exception
269 	when others then
270 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
271 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
272 	  fnd_message.set_token('MSG','jtf_dbstream_utils.endOfInputStream :'||SQLERRM);
273 	  app_exception.raise_exception;
274 end endOfInputStream;
275 -----------------------------------------------------------------------------
276 function  readString   return varchar2 is
277 begin
278 	return readNextString;
279 exception
280 	when others then
281 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
282 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
283 	  fnd_message.set_token('MSG','jtf_dbstream_utils.readString :'||SQLERRM);
284 	  app_exception.raise_exception;
285 end readString;
286 -----------------------------------------------------------------------------
287 function  readDate     return date is
288 begin
289   return fnd_date.displaydate_to_date(readNextString);
290 exception
291 	when others then
292 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
293 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
294 	  fnd_message.set_token('MSG','jtf_dbstream_utils.readDate :'||SQLERRM);
295 	  app_exception.raise_exception;
296 end readDate;
297 -----------------------------------------------------------------------------
298 function  readDateTime return date is
299 begin
300  	return fnd_date.displayDT_to_date(readNextString);
301 exception
302 	when others then
303 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
304 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
305 	  fnd_message.set_token('MSG','jtf_dbstream_utils.readDateTime :'||SQLERRM);
306 	  app_exception.raise_exception;
307 end readDateTime;
308 -----------------------------------------------------------------------------
309 function  readBoolean  return boolean is
310 begin
311   return jtf_dbstring_utils.getBoolean(readNextString);
312 exception
313 	when others then
314 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
315 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
316 	  fnd_message.set_token('MSG','jtf_dbstream_utils.readBoolean :'||SQLERRM);
317 	  app_exception.raise_exception;
318 end readBoolean;
319 -----------------------------------------------------------------------------
320 function  readInt      return integer is
321 begin
322 	return to_number(readNextString);
323 exception
324 	when others then
325 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
326 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
327 	  fnd_message.set_token('MSG','jtf_dbstream_utils.readInt :'||SQLERRM);
328 	  app_exception.raise_exception;
329 end readInt;
330 -----------------------------------------------------------------------------
331 function  readNumber   return number is
332 begin
333 	return to_number(readNextString);
334 exception
335 	when others then
336 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
337 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
338 	  fnd_message.set_token('MSG','jtf_dbstream_utils.readNumber :'||SQLERRM);
339 	  app_exception.raise_exception;
340 end readNumber;
341 
342 -----------------------------------------------------------------------------
343 function  readCurrency(currencyCode in varchar2) return number is
344 begin
345   return to_number(readNextString,fnd_currency.get_format_mask(currencyCode,jtf_dbstring_utils.getCurrencyFormatLength));
346 end readCurrency;
347 
348 -----------------------------------------------------------------------------
349 function   getLongOutputStream return streamType is
350 begin
351 	return outPutStream;
352 exception
353 	when others then
354 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
355 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
356 	  fnd_message.set_token('MSG','jtf_dbstream_utils.getLongOutputStream :'||SQLERRM);
357 	  app_exception.raise_exception;
358 end getLongOutputStream;
362 	return outputStream(outPutStream.FIRST);
359 -----------------------------------------------------------------------------
360 function   getOutputStream return varchar2 is
361 begin
363 exception
364 	when others then
365 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
366 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
367 	  fnd_message.set_token('MSG','jtf_dbstream_utils.getOutputStream :'||SQLERRM);
368 	  app_exception.raise_exception;
369 end getOutputStream;
370 -----------------------------------------------------------------------------
371 function   isLongOutputStream return boolean is
372 begin
373 	if outputStream.COUNT > 1 then
374 		return true;
375 	else
376 		return false;
377 	end if;
378 exception
379 	when others then
380 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
381 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
382 	  fnd_message.set_token('MSG','jtf_dbstream_utils.isLongOutputStream :'||SQLERRM);
383 	  app_exception.raise_exception;
384 end isLongOutputStream;
385 -----------------------------------------------------------------------------
386 
387 procedure  clearOutputStream is
388 begin
389 	outPutStream.DELETE;
390 	writerRowIndex := null;
391 exception
392 	when others then
393 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
394 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
395 	  fnd_message.set_token('MSG','jtf_dbstream_utils.clearOutputStream :'||SQLERRM);
396 	  app_exception.raise_exception;
397 end clearOutputStream;
398 -----------------------------------------------------------------------------
399 procedure  writeString(s in varchar2) is
400 begin
401 	writeNextString(s);
402 exception
403 	when others then
404 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
405 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
406 	  fnd_message.set_token('MSG','jtf_dbstream_utils.writeString :'||SQLERRM);
407 	  app_exception.raise_exception;
408 end writeString;
409 -----------------------------------------------------------------------------
410 procedure  writeDate(d in date) is
411 begin
412   writeNextString(fnd_date.date_to_displayDate(d));
413 exception
414 	when others then
415 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
416 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
417 	  fnd_message.set_token('MSG','jtf_dbstream_utils.writeDate :'||SQLERRM);
418 	  app_exception.raise_exception;
419 end writeDate;
420 -----------------------------------------------------------------------------
421 procedure  writeDateTime(d in date) is
422 begin
423   writeNextString(fnd_date.date_to_displayDT(d));
424 exception
425 	when others then
426 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
427 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
428 	  fnd_message.set_token('MSG','jtf_dbstream_utils.writeDateTime :'||SQLERRM);
429 	  app_exception.raise_exception;
430 end writeDateTime;
431 -----------------------------------------------------------------------------
432 procedure  writeBoolean(b in boolean) is
433 begin
434 	writeNextString(jtf_dbstring_utils.getBooleanString(b));
435 exception
436 	when others then
437 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
438 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
439 	  fnd_message.set_token('MSG','jtf_dbstream_utils.writeBoolean :'||SQLERRM);
440 	  app_exception.raise_exception;
441 end writeBoolean;
442 -----------------------------------------------------------------------------
443 procedure  writeInt(i in integer) is
444 begin
445 	writeNextString(to_char(i));
446 exception
447 	when others then
448 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
449 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
450 	  fnd_message.set_token('MSG','jtf_dbstream_utils.writeInt :'||SQLERRM);
451 	  app_exception.raise_exception;
452 end writeInt;
453 -----------------------------------------------------------------------------
454 procedure  writeNumber(n in number) is
455 begin
456 	writeNextString(to_char(n));
457 exception
458 	when others then
459 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
460 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
461 	  fnd_message.set_token('MSG','jtf_dbstream_utils.writeNumber :'||SQLERRM);
462 	  app_exception.raise_exception;
463 end writeNumber;
464 -----------------------------------------------------------------------------
465 
466 procedure  writeCurrency(c in number, currencyCode in varchar2) is
467 begin
468   writeNextString(to_char(c,fnd_currency.get_format_mask(currencyCode,jtf_dbstring_utils.getCurrencyFormatLength)));
469 end writeCurrency;
470 
471 ----------------------------------------------------------------------------
472 FUNCTION getVersion RETURN VARCHAR2 IS
473   BEGIN
474     RETURN('$Header: JTFSTRMB.pls 115.10 2002/12/04 17:53:06 pseo ship $');  END getVersion;
475 -----------------------------------------------------------------------------
476 
477 /** appends  inputList to the inputStream and returns the inputStream */
478 function addNumberToString(inputList in number,
479                         inputStream in varchar2)
480   return varchar2 is
481 begin
482   if inputStream is not NULL then
483      return inputStream||INT_SEPARATOR||to_char(inputList);
484   else
485      return to_char(inputList);
486   end if;
490 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
487 
488 exception
489 	when others then
491 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
492 	  fnd_message.set_token('MSG','jtf_dbstream_utils.addNumberToString :'||SQLERRM);
493 	  app_exception.raise_exception;
494 end;
495 -----------------------------------------------------------------------------
496 /** appends all integers in inputList to the inputStream and returns the inputStream */
497 function addNumberToString(inputList in int_table,
498                         inputStream in varchar2 := null)
499   return varchar2 is
500 
501 l_inputStream varchar2(32767) := inputStream;
502 begin
503   for i in 1..inputList.count loop
504     l_inputStream := addNumberToString(inputList(i), l_inputStream);
505   end loop;
506 
507   return l_inputStream;
508 exception
509 	when others then
510 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
511 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
512 	  fnd_message.set_token('MSG','jtf_dbstream_utils.addIntToString :'||SQLERRM);
513 	  app_exception.raise_exception;
514 end;
515 -----------------------------------------------------------------------------
516 
517 /** returns an table of integers from a string */
518 function readFromString(inputStream in varchar2)
519   return int_table is
520 
521 l_number_list int_table;
522 l_inputStream varchar2(32767) := inputStream;
523 pos  pls_integer;
524 begin
525   null;
526 
527   if l_inputStream is not NULL then
528       pos := instr(l_inputStream,INT_SEPARATOR,1);
529       while pos > 0 loop
530        l_number_list(nvl(l_number_list.LAST,0) + 1) := to_number(substr(l_inputStream, 1, pos-1));
531        l_inputStream := substr(l_inputStream, pos+1);
532        pos := instr(l_inputStream,INT_SEPARATOR,1);
533       end loop;
534       l_number_list(nvl(l_number_list.LAST,0) + 1) := l_inputStream;
535   end if;
536 
537   return l_number_list;
538 exception
539 	when others then
540 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
541 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
542 	  fnd_message.set_token('MSG','jtf_dbstream_utils.readFromString :'||SQLERRM);
543 	  app_exception.raise_exception;
544 end;
545 -----------------------------------------------------------------------------
546 
547 
548 /** checks if an integer exists in the stream */
549 function checkNumberExists(inputStream in varchar2,
550                            value       in number)
551   return boolean is
552 l_inputStream varchar2(32767) := inputStream;
553 begin
554   -- the current string is of the format 123:456:789
555   -- we change it to :123:456:789: and look for the value we want
556   -- this method is used so that the first and last numbers can be
557   -- treated just like the any other number in the string.
558   -- also, we need to test for :value: so that we do not return true
559   -- for numbers that form a subset of the string e.g., 23
560 
561   l_inputStream := INT_SEPARATOR||l_inputStream||INT_SEPARATOR;
562   if (INSTR(l_inputStream, INT_SEPARATOR||to_char(value)||INT_SEPARATOR) > 0) then
563     return true;
564   else
565     return false;
566   end if;
567 
568 exception
569 	when others then
570 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
571 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
572 	  fnd_message.set_token('MSG','jtf_dbstream_utils.checkNumberExists :'||SQLERRM);
573 	  app_exception.raise_exception;
574 end;
575 -----------------------------------------------------------------------------
576 /** removes the all occurances of the number from the string */
577 function removeFromString(inputStream in varchar2,
578                           value       in number)
579 return varchar2 is
580 
581 l_inputStream varchar2(32767) := inputStream;
582 begin
583 
584   -- the current string is of the format 123:456:789
585   -- we change it to :123:456:789: and look for the value we want
586   -- this method is used so that the first and last numbers can be
587   -- treated just like the any other number in the string.
588   -- also, we need to replace :value: with :
589 
590   l_inputStream := INT_SEPARATOR||l_inputStream||INT_SEPARATOR;
591   l_inputStream := REPLACE(l_inputStream, INT_SEPARATOR||value||INT_SEPARATOR, INT_SEPARATOR);
592 
593   -- removing : at the beginning and end of the string
594 
595   l_inputStream := SUBSTR(l_inputStream, 2, length(l_inputStream)-2);
596 
597   return l_inputStream;
598 exception
599 	when others then
600 	  fnd_message.set_name('JTF','JTF_GRID_DB_ERRORS');
601 	  fnd_message.set_token('SOURCE','JTF_DBSTREAM_UTILS');
602 	  fnd_message.set_token('MSG','jtf_dbstream_utils.removeFromString :'||SQLERRM);
603 	  app_exception.raise_exception;
604 end;
605 
606 
607 
608 -----------------------------------------------------------------------------
609 END JTF_DBSTREAM_UTILS;