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

Skip to content

Commit 547de6e

Browse files
committed
Adding support for use of DBA_ views, if user executing tests has access to them (they are faster).
1 parent f510231 commit 547de6e

4 files changed

Lines changed: 58 additions & 29 deletions

File tree

source/core/coverage/ut_coverage.pkb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ create or replace package body ut_coverage is
3131
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);
34+
l_view_name varchar2(200) := ut_metadata.get_dba_view('dba_source');
3435
begin
3536
if a_coverage_options.file_mappings is not null and a_coverage_options.file_mappings.count > 0 then
3637
l_full_name := 'f.file_name';
@@ -48,7 +49,7 @@ create or replace package body ut_coverage is
4849
coalesce(
4950
case when type!='TRIGGER' then 0 end,
5051
(select min(t.line) - 1
51-
from all_source t
52+
from ]'||l_view_name||q'[ t
5253
where t.owner = s.owner and t.type = s.type and t.name = s.name
5354
and regexp_like( t.text, '[A-Za-z0-9$#_]*(begin|declare|compound).*','i'))
5455
) as line,
@@ -69,7 +70,7 @@ create or replace package body ut_coverage is
6970
)
7071
then 'Y'
7172
end as to_be_skipped
72-
from all_source s]';
73+
from ]'||l_view_name||q'[ s]';
7374
if a_coverage_options.file_mappings is not null and a_coverage_options.file_mappings.count > 0 then
7475
l_result := l_result || '
7576
join table(:file_mappings) f

source/core/ut_metadata.pkb

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,20 @@ create or replace package body ut_metadata as
6363
l_schema varchar2(200);
6464
l_package_name varchar2(200);
6565
l_procedure_name varchar2(200);
66+
l_view_name varchar2(200) := get_dba_view('dba_objects');
6667
begin
6768

6869
l_schema := a_owner_name;
6970
l_package_name := a_package_name;
7071

7172
do_resolve(l_schema, l_package_name, l_procedure_name);
7273

73-
select count(decode(status, 'VALID', 1, null)) / count(*)
74-
into l_cnt
75-
from all_objects
76-
where owner = l_schema
77-
and object_name = l_package_name
78-
and object_type in ('PACKAGE');
74+
execute immediate q'[select count(decode(status, 'VALID', 1, null)) / count(*)
75+
from ]'||l_view_name||q'[
76+
where owner = :l_schema
77+
and object_name = :l_package_name
78+
and object_type in ('PACKAGE')]'
79+
into l_cnt using l_schema, l_package_name;
7980

8081
-- expect both package and body to be valid
8182
return l_cnt = 1;
@@ -90,6 +91,7 @@ create or replace package body ut_metadata as
9091
l_schema varchar2(200);
9192
l_package_name varchar2(200);
9293
l_procedure_name varchar2(200);
94+
l_view_name varchar2(200) := get_dba_view('dba_procedures');
9395
begin
9496

9597
l_schema := a_owner_name;
@@ -98,12 +100,10 @@ create or replace package body ut_metadata as
98100

99101
do_resolve(l_schema, l_package_name, l_procedure_name);
100102

101-
select count(*)
102-
into l_cnt
103-
from all_procedures
104-
where owner = l_schema
105-
and object_name = l_package_name
106-
and procedure_name = l_procedure_name;
103+
execute immediate
104+
'select count(*) from '||l_view_name
105+
||' where owner = :l_schema and object_name = :l_package_name and procedure_name = :l_procedure_name'
106+
into l_cnt using l_schema, l_package_name, l_procedure_name;
107107

108108
--expect one method only for the package with that name.
109109
return l_cnt = 1;
@@ -132,12 +132,12 @@ create or replace package body ut_metadata as
132132
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2 is
133133
l_line varchar2(4000);
134134
l_cursor sys_refcursor;
135+
l_view_name varchar2(128) := get_dba_view('dba_source');
135136
begin
136-
open l_cursor for
137-
select text from all_source s
138-
where s.owner = a_owner and s.name = a_object_name and s.line = a_line_no
137+
open l_cursor for 'select text from '||l_view_name||q'[ s
138+
where s.owner = :a_owner and s.name = :a_object_name and s.line = :a_line_no
139139
-- skip the declarations, consider only definitions
140-
and s.type not in ('PACKAGE','TYPE');
140+
and s.type not in ('PACKAGE','TYPE')]' using a_owner, a_object_name, a_line_no;
141141
fetch l_cursor into l_line;
142142
close l_cursor;
143143
return ltrim(rtrim( l_line, chr(10) ));
@@ -146,5 +146,16 @@ create or replace package body ut_metadata as
146146
return null;
147147
end;
148148

149+
function get_dba_view(a_view_name varchar2) return varchar2 is
150+
l_invalid_object_name exception;
151+
l_result varchar2(128) := lower(a_view_name);
152+
pragma exception_init(l_invalid_object_name,-44002);
153+
begin
154+
l_result := dbms_assert.sql_object_name(l_result);
155+
return l_result;
156+
exception
157+
when l_invalid_object_name then
158+
return replace(l_result,'dba_','all_');
159+
end;
149160
end;
150161
/

source/core/ut_metadata.pks

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,12 @@ create or replace package ut_metadata authid current_user as
7979
*/
8080
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2;
8181

82+
/*
83+
function: get_dba_view
84+
85+
return the dba_xxx view name if it is accessible or all_xxx view otherwise
86+
*/
87+
function get_dba_view(a_view_name varchar2) return varchar2;
88+
8289
end ut_metadata;
8390
/

source/core/ut_suite_manager.pkb

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ create or replace package body ut_suite_manager is
3434

3535
function get_schema_info(a_owner_name varchar2) return t_schema_info is
3636
l_info t_schema_info;
37+
l_view_name varchar2(200) := ut_metadata.get_dba_view('all_objects');
3738
begin
39+
execute immediate q'[
3840
select nvl(max(t.last_ddl_time), date '4999-12-31'), count(*)
39-
into l_info
40-
from all_objects t
41-
where t.owner = a_owner_name
42-
and t.object_type in ('PACKAGE');
41+
from ]'||l_view_name||q'[ t
42+
where t.owner = :a_owner_name
43+
and t.object_type in ('PACKAGE')]'
44+
into l_info using a_owner_name;
4345
return l_info;
4446
end;
4547

@@ -206,6 +208,15 @@ create or replace package body ut_suite_manager is
206208
l_root varchar2(4000 char);
207209
l_root_suite ut_logical_suite;
208210

211+
type t_object_name is record(
212+
owner all_objects.owner%type,
213+
object_name all_objects.object_name%type
214+
);
215+
type t_object_names is table of t_object_name;
216+
217+
l_object_names t_object_names;
218+
l_view_name varchar2(200) := ut_metadata.get_dba_view('dba_objects');
219+
209220
l_schema_suites tt_schema_suites;
210221

211222
procedure put(a_root_suite in out nocopy ut_logical_suite, a_path varchar2, a_suite ut_logical_suite, a_parent_path varchar2 default null) is
@@ -270,14 +281,13 @@ create or replace package body ut_suite_manager is
270281

271282
begin
272283
-- form the single-dimension list of suites constructed from parsed packages
273-
for rec in (select t.owner
274-
,t.object_name
275-
from all_objects t
276-
where t.owner = a_owner_name
277-
and t.status = 'VALID' -- scan only valid specifications
278-
and t.object_type in ('PACKAGE')) loop
284+
execute immediate
285+
'select t.owner, t.object_name from '||l_view_name||' t '
286+
||q'[ where t.owner = :a_owner_name and t.status = 'VALID' and t.object_type in ('PACKAGE')]'
287+
bulk collect into l_object_names using a_owner_name;
288+
for i in 1 .. cardinality(l_object_names) loop
279289
-- parse the source of the package
280-
l_suite := config_package(rec.owner, rec.object_name);
290+
l_suite := config_package(l_object_names(i).owner, l_object_names(i).object_name);
281291

282292
if l_suite is not null then
283293
l_all_suites(l_suite.path) := l_suite;

0 commit comments

Comments
 (0)