Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6e4725

Browse files
committed
Integrated helper functions (clob_to_table, table_to_clob) with pipeline functionality.
1 parent 3648ee4 commit f6e4725

14 files changed

Lines changed: 96 additions & 77 deletions

source/core/types/ut_output_clob_list.tps

Lines changed: 0 additions & 2 deletions
This file was deleted.

source/core/types/ut_output_dbms_pipe.tpb

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,45 +42,30 @@ create or replace type body ut_output_dbms_pipe as
4242
ut_output_pipe_helper.flush(self.output_id);
4343
end;
4444

45-
static function get_lines(a_output_id varchar2, a_timeout_sec integer := 60*60*4) return ut_output_clob_list pipelined is
46-
l_flag integer;
47-
l_text_part ut_output_pipe_helper.t_pipe_item;
45+
static function get_lines(a_output_id varchar2, a_timeout_sec integer := 60*60*4) return ut_varchar2_list pipelined is
46+
c_max_line_length constant integer := 4000;
4847
l_text clob;
49-
l_timeout_occured boolean;
50-
l_need_to_send boolean;
51-
l_item_type integer;
48+
l_result_flag integer;
49+
l_results_tab ut_varchar2_list;
5250
begin
53-
if a_output_id is not null then
54-
55-
loop
56-
dbms_lob.createtemporary(l_text, true);
57-
l_need_to_send := false;
58-
59-
--build a row. As a rule one call to 'send' is one row.
60-
-- TODO - add detection of newline so that for each new line recieved in text, the code generates a new output row
61-
loop
62-
dbms_pipe.reset_buffer;
63-
l_timeout_occured := (dbms_pipe.receive_message(a_output_id, a_timeout_sec) != 0);
64-
exit when l_timeout_occured;
65-
l_item_type := dbms_pipe.next_item_type();
66-
exit when l_item_type in (ut_output_pipe_helper.gc_eom, ut_output_pipe_helper.gc_eot);
67-
dbms_pipe.unpack_message(l_text_part);
68-
if l_text_part is not null then
69-
dbms_lob.writeappend(l_text, length(l_text_part), l_text_part);
70-
end if;
71-
l_need_to_send := true;
72-
end loop;
73-
74-
if l_need_to_send then
75-
pipe row( l_text );
76-
dbms_lob.freetemporary(l_text);
77-
end if;
51+
if a_output_id is null then
52+
return;
53+
end if;
7854

79-
exit when (l_timeout_occured or l_item_type = ut_output_pipe_helper.gc_eot);
55+
loop
56+
dbms_lob.createtemporary(l_text, true);
57+
--get message as a clob data and recieve information if the message is ended, timed out or it is the end of transmission
58+
l_result_flag := ut_output_pipe_helper.get_message(a_output_id, a_timeout_sec, l_text);
59+
-- convert message into collection of varchar2(4000) for SQL processing
60+
select column_value bulk collect into l_results_tab from table( ut_utils.clob_to_table(l_text, c_max_line_length));
61+
--pipe results one by one
62+
for i in 1 .. l_results_tab.count loop
63+
pipe row( l_results_tab(i) );
8064
end loop;
65+
dbms_lob.freetemporary(l_text);
8166

82-
l_flag := dbms_pipe.remove_pipe(a_output_id);
83-
end if;
67+
exit when l_result_flag in (ut_output_pipe_helper.gc_eot, ut_output_pipe_helper.gc_timeout);
68+
end loop;
8469
return;
8570
end;
8671

source/core/types/ut_output_dbms_pipe.tps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ create or replace type ut_output_dbms_pipe under ut_output (
44
overriding member procedure send_line(self in out nocopy ut_output_dbms_pipe, a_text varchar2),
55
overriding member procedure send_clob(self in out nocopy ut_output_dbms_pipe, a_text clob),
66
overriding member procedure close(self in out nocopy ut_output_dbms_pipe),
7-
static function get_lines(a_output_id varchar2, a_timeout_sec integer := 60*60*4) return ut_output_clob_list pipelined
7+
static function get_lines(a_output_id varchar2, a_timeout_sec integer := 60*60*4) return ut_varchar2_list pipelined
88
) not final
99
/

source/core/types/ut_output_varchar2_list.tps

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
create or replace type ut_varchar2_list as table of varchar2(32767)
2+
/

source/core/ut_metadata.pkb

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,14 @@ create or replace package body ut_metadata as
132132

133133

134134
function get_package_spec_source(a_owner varchar2, a_object_name varchar2) return clob is
135-
type t_source_tab is table of all_source.text%type;
136-
l_source clob;
137-
l_txt_tab t_source_tab;
135+
l_txt_tab ut_varchar2_list;
138136
l_cur sys_refcursor;
139137
begin
140-
141-
dbms_lob.createtemporary(l_source, true);
142138
l_cur := get_package_spec_source_cursor(a_owner, a_object_name);
143139
fetch l_cur bulk collect into l_txt_tab;
144-
for i in 1 .. cardinality(l_txt_tab) loop
145-
dbms_lob.writeappend(l_source, length(l_txt_tab(i)), l_txt_tab(i));
146-
end loop;
147140
close l_cur;
148-
return l_source;
149-
150-
end get_package_spec_source;
141+
return ut_utils.table_to_clob(l_txt_tab);
142+
end;
151143

152144
end;
153145
/

source/core/ut_output_pipe_helper.pkb

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,23 @@ create or replace package body ut_output_pipe_helper is
105105
return true;
106106
end;
107107

108+
procedure remove_pipe(a_output_id t_output_id) is
109+
l_status integer;
110+
begin
111+
l_status := dbms_pipe.remove_pipe(a_output_id);
112+
end;
113+
108114
-- - remove pipes associated with buffers that are not yet deleted
109115
-- - delete all the buffers
110116
-- TODO - The purge procedure needs to be called by top level program (ut_runner)
111117
-- in the EXCEPTION WHEN OTHERS block before raising back,
112118
-- so that it tries to remove pipes on any exception before raising back to caller
113119
procedure purge is
114-
l_pipe_removal_status integer;
115120
l_output_id t_output_id;
116121
begin
117122
l_output_id := g_outputs_buffer.first;
118123
while l_output_id is not null loop
119-
l_pipe_removal_status := dbms_pipe.remove_pipe(l_output_id);
124+
remove_pipe(l_output_id);
120125
l_output_id := g_outputs_buffer.next(l_output_id);
121126
end loop;
122127
g_outputs_buffer.delete;
@@ -176,7 +181,7 @@ create or replace package body ut_output_pipe_helper is
176181
g_outputs_buffer(a_output_id).to_flush := true;
177182
end if;
178183

179-
if (flush_buffers() = false) and all_buffers_to_flush then
184+
if (flush_buffers() = false) and all_buffers_to_flush() then
180185
--try as many times as there are seconds for timeout
181186
--each time try with one second delay
182187
for i in 1 .. a_timeout_seconds loop
@@ -194,5 +199,30 @@ create or replace package body ut_output_pipe_helper is
194199

195200
end;
196201

202+
function get_message(a_output_id t_output_id, a_timeout_seconds integer, a_text in out nocopy clob) return integer is
203+
l_result_flag integer :=0;
204+
l_status integer;
205+
l_text_part ut_output_pipe_helper.t_pipe_item;
206+
l_item_type integer;
207+
begin
208+
loop
209+
dbms_pipe.reset_buffer;
210+
if 0 != dbms_pipe.receive_message(a_output_id, a_timeout_seconds) then
211+
l_result_flag := gc_timeout;
212+
else
213+
l_result_flag := dbms_pipe.next_item_type();
214+
end if;
215+
exit when l_result_flag in (gc_eom, gc_eot, gc_timeout);
216+
217+
dbms_pipe.unpack_message(l_text_part);
218+
if l_text_part is not null then
219+
dbms_lob.writeappend(a_text, length(l_text_part), l_text_part);
220+
end if;
221+
end loop;
222+
if l_result_flag in (gc_eot, gc_timeout) then
223+
remove_pipe(a_output_id);
224+
end if;
225+
return l_result_flag;
226+
end;
197227
end;
198228
/

source/core/ut_output_pipe_helper.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ create or replace package ut_output_pipe_helper is
1212
gc_text constant integer := 9;
1313
gc_eom constant integer := 11;
1414
gc_eot constant integer := 23;
15+
gc_timeout constant integer := -1;
1516

1617
--adds message to pipe buffer and tries to sent all messages from the buffer
1718
--exists immediately when sending timesout (pipe full)
@@ -30,5 +31,7 @@ create or replace package ut_output_pipe_helper is
3031
-- If timed out, the open pies get purged and closed
3132
procedure flush(a_output_id t_output_id, a_timeout_seconds naturaln := gc_flush_timeout_seconds);
3233

34+
function get_message(a_output_id t_output_id, a_timeout_seconds integer, a_text in out nocopy clob) return integer;
35+
3336
end;
3437
/

source/core/ut_utils.pkb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ create or replace package body ut_utils is
126126
return case a_value when 1 then true when 0 then false end;
127127
end;
128128

129-
function string_to_table(a_string varchar2, a_delimiter varchar2:= chr(10), a_skip_leading_delimiter varchar2 := 'N') return ut_output_varchar2_list pipelined is
129+
function string_to_table(a_string varchar2, a_delimiter varchar2:= chr(10), a_skip_leading_delimiter varchar2 := 'N') return ut_varchar2_list pipelined is
130130
l_offset integer := 1;
131131
l_length integer;
132132
l_delimiter_position integer;
@@ -155,13 +155,13 @@ create or replace package body ut_utils is
155155
return;
156156
end;
157157

158-
function clob_to_table(a_clob clob, a_delimiter varchar2:= chr(10), a_max_amount integer := 32767) return ut_output_varchar2_list pipelined is
158+
function clob_to_table(a_clob clob, a_max_amount integer := 32767, a_delimiter varchar2:= chr(10)) return ut_varchar2_list pipelined is
159159
l_offset integer := 1;
160160
l_length integer := dbms_lob.getlength(a_clob);
161161
l_amount integer := a_max_amount;
162162
l_buffer varchar2(32767);
163163
l_last_line varchar2(32767);
164-
l_results ut_output_varchar2_list;
164+
l_results ut_varchar2_list;
165165
l_has_last_line boolean;
166166
l_skip_leading_delimiter varchar2(1) := 'N';
167167
begin
@@ -197,5 +197,17 @@ create or replace package body ut_utils is
197197
return;
198198
end;
199199

200+
function table_to_clob(a_text_table ut_varchar2_list) return clob is
201+
l_result clob;
202+
l_text_table_rows integer := coalesce(cardinality(a_text_table),0);
203+
begin
204+
205+
dbms_lob.createtemporary(l_result, true);
206+
for i in 1 .. l_text_table_rows loop
207+
dbms_lob.writeappend(l_result, length(a_text_table(i)), a_text_table(i));
208+
end loop;
209+
return l_result;
210+
end;
211+
200212
end;
201213
/

source/core/ut_utils.pks

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ create or replace package ut_utils authid definer is
9898
a_skip_leading_delimiter - determines if the leading delimiter should be ignored, used by clob_to_table
9999

100100
Returns:
101-
ut_output_varchar2_list - table of string
101+
ut_varchar2_list - table of string
102102

103103
Splits a given string into table of string by delimiter.
104104
The delimiter gets removed.
105105
If null passed as any of the parameters, empty table is returned.
106106
If no occurence of a_delimiter found in a_text then text is returned as a single row of the table.
107107
If no text between delimiters found then an empty row is returned, example:
108-
string_to_table( 'a,,b', ',' ) gives table ut_output_varchar2_list( 'a', null, 'b' );
108+
string_to_table( 'a,,b', ',' ) gives table ut_varchar2_list( 'a', null, 'b' );
109109
*/
110-
function string_to_table(a_string varchar2, a_delimiter varchar2:= chr(10), a_skip_leading_delimiter varchar2 := 'N') return ut_output_varchar2_list pipelined;
110+
function string_to_table(a_string varchar2, a_delimiter varchar2:= chr(10), a_skip_leading_delimiter varchar2 := 'N') return ut_varchar2_list pipelined;
111111

112112
/*
113113
Function: clob_to_table
@@ -118,16 +118,18 @@ create or replace package ut_utils authid definer is
118118
a_max_amount - the maximum length of returned string (default 32767)
119119

120120
Returns:
121-
ut_output_varchar2_list - table of string
121+
ut_varchar2_list - table of string
122122

123123
Splits a given string into table of string by delimiter.
124124
The delimiter gets removed.
125125
If null passed as any of the parameters, empty table is returned.
126126
If split text is longer than a_max_amount it gets split into pieces of a_max_amount.
127127
If no text between delimiters found then an empty row is returned, example:
128-
string_to_table( 'a,,b', ',' ) gives table ut_output_varchar2_list( 'a', null, 'b' );
128+
string_to_table( 'a,,b', ',' ) gives table ut_varchar2_list( 'a', null, 'b' );
129129
*/
130-
function clob_to_table(a_clob clob, a_delimiter varchar2:= chr(10), a_max_amount integer := 32767) return ut_output_varchar2_list pipelined;
130+
function clob_to_table(a_clob clob, a_max_amount integer := 32767, a_delimiter varchar2:= chr(10)) return ut_varchar2_list pipelined;
131+
132+
function table_to_clob(a_text_table ut_varchar2_list) return clob;
131133

132134
end ut_utils;
133135
/

0 commit comments

Comments
 (0)