@@ -28,7 +28,7 @@ create or replace package body ut_coverage is
2828 -- The subquery is optimized by:
2929 -- - COALESCE function -> it will execute only for TRIGGERS
3030 -- - scalar subquery cache -> it will only execute once for one trigger source code.
31- function populate_sources_tmp_table (a_coverage_options ut_coverage_options) return varchar2 is
31+ function get_populate_sources_tmp_sql (a_coverage_options ut_coverage_options) return varchar2 is
3232 l_result varchar2(32767);
3333 l_full_name varchar2(100);
3434 begin
@@ -98,6 +98,31 @@ create or replace package body ut_coverage is
9898 return l_result;
9999 end;
100100
101+ function is_tmp_table_populated return boolean is
102+ l_result integer;
103+ begin
104+ select 1 into l_result from ut_coverage_sources_tmp where rownum = 1;
105+ return (l_result = 1);
106+ exception
107+ when no_data_found then
108+ return false;
109+ end;
110+
111+ procedure populate_tmp_table(a_coverage_options ut_coverage_options, a_skipped_objects ut_object_names) is
112+ pragma autonomous_transaction;
113+ l_schema_names ut_varchar2_rows;
114+ begin
115+ delete from ut_coverage_sources_tmp;
116+ l_schema_names := coalesce(a_coverage_options.schema_names, ut_varchar2_rows(sys_context('USERENV','CURRENT_SCHEMA')));
117+ if a_coverage_options.file_mappings is not empty then
118+ execute immediate get_populate_sources_tmp_sql(a_coverage_options) using a_coverage_options.file_mappings, a_skipped_objects, a_coverage_options.include_objects;
119+ else
120+ execute immediate get_populate_sources_tmp_sql(a_coverage_options) using l_schema_names, a_skipped_objects, a_coverage_options.include_objects;
121+ end if;
122+ commit;
123+ end;
124+
125+
101126 /**
102127 * Public functions
103128 */
@@ -132,41 +157,24 @@ create or replace package body ut_coverage is
132157 end;
133158
134159 function get_coverage_data(a_coverage_options ut_coverage_options) return t_coverage is
135-
136- pragma autonomous_transaction;
137-
138- type t_coverage_row is record(
139- name varchar2(500),
140- line_number integer,
141- total_occur number(38,0)
142- );
143- type tt_coverage_rows is table of t_coverage_row;
144160 l_line_calls ut_coverage_helper.unit_line_calls;
145161 l_result t_coverage;
146162 l_new_unit t_unit_coverage;
147163 l_skipped_objects ut_object_names := ut_object_names();
148164
149165 type t_source_lines is table of binary_integer;
150- l_source_lines t_source_lines;
151166 line_no binary_integer;
152- l_schema_names ut_varchar2_rows;
153- l_query varchar2(32767);
154167 begin
155- l_schema_names := coalesce(a_coverage_options.schema_names, ut_varchar2_rows(sys_context('USERENV','CURRENT_SCHEMA')));
156168
157169 if not ut_coverage_helper.is_develop_mode() then
158170 --skip all the utplsql framework objects and all the unit test packages that could potentially be reported by coverage.
159171 l_skipped_objects := ut_utils.get_utplsql_objects_list() multiset union all coalesce(a_coverage_options.exclude_objects, ut_object_names());
160172 end if;
161173
162174 --prepare global temp table with sources
163- delete from ut_coverage_sources_tmp;
164- if a_coverage_options.file_mappings is not null and a_coverage_options.file_mappings.count > 0 then
165- execute immediate populate_sources_tmp_table(a_coverage_options) using a_coverage_options.file_mappings, l_skipped_objects, a_coverage_options.include_objects;
166- else
167- execute immediate populate_sources_tmp_table(a_coverage_options) using l_schema_names, l_skipped_objects, a_coverage_options.include_objects;
175+ if not is_tmp_table_populated() or ut_coverage_helper.is_develop_mode() then
176+ populate_tmp_table(a_coverage_options, l_skipped_objects);
168177 end if;
169- commit;
170178
171179 for src_object in (
172180 select o.owner, o.name, o.full_name, max(o.line) lines_count,
@@ -224,7 +232,6 @@ create or replace package body ut_coverage is
224232
225233 end loop;
226234
227- commit;
228235 return l_result;
229236 end get_coverage_data;
230237
0 commit comments