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

Skip to content

Cleanup grants of internal objects & tables #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ end;
PROMPT Granting $UT3_OWNER tables to $UT3_TESTER

begin
for i in ( select table_name from all_tables t where owner = 'UT3' and nested = 'NO' and IOT_TYPE is NULL)
for i in ( select table_name from all_tables t where owner = 'UT3' and nested = 'NO' and IOT_NAME is NULL)
loop
execute immediate 'grant select on UT3.'||i.table_name||' to UT3_TESTER';
end loop;
Expand Down
9 changes: 3 additions & 6 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ create or replace package body ut_runner is

procedure finish_run(a_run ut_run, a_force_manual_rollback boolean) is
begin
ut_utils.cleanup_temp_tables;
ut_event_manager.trigger_event(ut_event_manager.gc_finalize, a_run);
ut_metadata.reset_source_definition_cache;
ut_utils.read_cache_to_dbms_output();
ut_coverage_helper.cleanup_tmp_table();
ut_compound_data_helper.cleanup_diff();
if not a_force_manual_rollback then
rollback;
ut_utils.cleanup_session_temp_tables;
end if;
end;

Expand Down Expand Up @@ -196,7 +196,7 @@ create or replace package body ut_runner is
function get_suites_info(a_owner varchar2 := null, a_package_name varchar2 := null) return ut_suite_items_info pipelined is
l_cursor sys_refcursor;
l_results ut_suite_items_info;
c_bulk_limit constant integer := 10;
c_bulk_limit constant integer := 100;
begin
l_cursor := ut_suite_manager.get_suites_info( nvl(a_owner,sys_context('userenv', 'current_schema')), a_package_name );
loop
Expand Down Expand Up @@ -285,10 +285,7 @@ create or replace package body ut_runner is
if l_item is not null then
l_result :=
l_result ||
dbms_crypto.hash(
to_char( dbms_utility.get_hash_value( l_item, 1, a_random_seed ) ),
dbms_crypto.hash_sh1
);
ut_utils.get_hash( to_char( dbms_utility.get_hash_value( l_item, 1, a_random_seed ) ) );
end if;
exit when l_at_end;
l_result := l_result || chr(0);
Expand Down
2 changes: 1 addition & 1 deletion source/api/ut_suite_item_info.tps
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ create or replace type ut_suite_item_info as object (
object_owner varchar2( 250 ), -- the owner of test suite packages
object_name varchar2( 250 ), -- the name of test suite package
item_name varchar2( 250 ), -- the name of suite/test
item_description varchar2( 250 ), -- the description of suite/suite item
item_description varchar2( 4000 ), -- the description of suite/suite item
item_type varchar2( 250 ), -- the type of item (UT_SUITE/UT_SUITE_CONTEXT/UT_TEST)
item_line_no integer, -- line_number where annotation identifying the item exists
path varchar2( 4000 ),-- suitepath of the item
Expand Down
19 changes: 18 additions & 1 deletion source/core/annotations/ut_annotation_cache_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,29 @@ create or replace package body ut_annotation_cache_manager as
commit;
end;

function get_annotations_objects_info(a_object_owner varchar2, a_object_type varchar2) return ut_annotation_objs_cache_info is
l_result ut_annotation_objs_cache_info;
begin
select ut_annotation_obj_cache_info(
object_owner => i.object_owner,
object_name => i.object_name,
object_type => i.object_type,
needs_refresh => 'N',
parse_time => i.parse_time
)
bulk collect into l_result
from ut_annotation_cache_info i
where i.object_owner = a_object_owner
and i.object_type = a_object_type;
return l_result;
end;

function get_cache_schema_info(a_object_owner varchar2, a_object_type varchar2) return t_cache_schema_info is
l_result t_cache_schema_info;
begin
begin
select *
into l_result
into l_result
from ut_annotation_cache_schema s
where s.object_type = a_object_type and s.object_owner = a_object_owner;
exception
Expand Down
3 changes: 3 additions & 0 deletions source/core/annotations/ut_annotation_cache_manager.pks
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ create or replace package ut_annotation_cache_manager authid definer as
*/
function get_annotations_for_objects(a_cached_objects ut_annotation_objs_cache_info, a_parse_time timestamp) return sys_refcursor;


function get_annotations_objects_info(a_object_owner varchar2, a_object_type varchar2) return ut_annotation_objs_cache_info;

function get_cache_schema_info(a_object_owner varchar2, a_object_type varchar2) return t_cache_schema_info;

/**
Expand Down
122 changes: 43 additions & 79 deletions source/core/annotations/ut_annotation_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,28 @@ create or replace package body ut_annotation_manager as
l_ut_owner varchar2(250) := ut_utils.ut_owner;
l_objects_view varchar2(200) := ut_metadata.get_objects_view_name();
l_cursor_text varchar2(32767);
l_data ut_annotation_objs_cache_info;
l_result ut_annotation_objs_cache_info;
l_card natural;
begin
l_data := ut_annotation_cache_manager.get_annotations_objects_info(a_object_owner, a_object_type);
l_card := ut_utils.scale_cardinality(cardinality(l_data));

l_cursor_text :=
q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
object_owner => i.object_owner,
object_name => i.object_name,
object_type => i.object_type,
needs_refresh => null
)
from ]'||l_ut_owner||q'[.ut_annotation_cache_info i
'select /*+ cardinality(i '||l_card||') */
value(i)
from table( cast( :l_data as '||l_ut_owner||'.ut_annotation_objs_cache_info ) ) i
where
not exists (
select 1 from ]'||l_objects_view||q'[ o
select 1 from '||l_objects_view||q'[ o
where o.owner = i.object_owner
and o.object_name = i.object_name
and o.object_type = i.object_type
and o.owner = :a_object_owner
and o.object_type = :a_object_type
)
and i.object_owner = :a_object_owner
and i.object_type = :a_object_type]';
open l_rows for l_cursor_text using a_object_owner, a_object_type, a_object_owner, a_object_type;
fetch l_rows bulk collect into l_result limit 1000000;
and o.owner = ']'||ut_utils.qualified_sql_name(a_object_owner)||q'['
and o.object_type = ']'||ut_utils.qualified_sql_name(a_object_type)||q'['
)]';
open l_rows for l_cursor_text using l_data;
fetch l_rows bulk collect into l_result limit ut_utils.gc_max_objects_fetch_limit;
close l_rows;
return l_result;
end;
Expand All @@ -61,83 +60,48 @@ create or replace package body ut_annotation_manager as
l_ut_owner varchar2(250) := ut_utils.ut_owner;
l_objects_view varchar2(200) := ut_metadata.get_objects_view_name();
l_cursor_text varchar2(32767);
l_data ut_annotation_objs_cache_info;
l_result ut_annotation_objs_cache_info;
l_object_owner varchar2(250);
l_object_type varchar2(250);
begin
ut_event_manager.trigger_event(
'get_annotation_objs_info - start ( a_full_scan = ' || ut_utils.to_string(a_full_scan) || ' )'
);

l_data := ut_annotation_cache_manager.get_annotations_objects_info(a_object_owner, a_object_type);

if not a_full_scan then
l_cursor_text :=
q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
object_owner => i.object_owner,
object_name => i.object_name,
object_type => i.object_type,
needs_refresh => 'N'
)
from ]'||l_ut_owner||q'[.ut_annotation_cache_info i
where i.object_owner = :a_object_owner
and i.object_type = :a_object_type]';
open l_rows for l_cursor_text using a_object_owner, a_object_type;
l_result := l_data;
else
if a_object_owner is not null then
l_object_owner := sys.dbms_assert.qualified_sql_name(a_object_owner);
end if;
if a_object_type is not null then
l_object_type := sys.dbms_assert.qualified_sql_name(a_object_type);
end if;
l_cursor_text :=
q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
object_owner => o.owner,
object_name => o.object_name,
object_type => o.object_type,
needs_refresh => case when o.last_ddl_time < cast(i.parse_time as date) then 'N' else 'Y' end
)
from ]'||l_objects_view||q'[ o
left join ]'||l_ut_owner||q'[.ut_annotation_cache_info i
'select /*+ cardinality(i '||ut_utils.scale_cardinality(cardinality(l_data))||') */
'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
object_owner => o.owner,
object_name => o.object_name,
object_type => o.object_type,
needs_refresh => case when o.last_ddl_time < cast(i.parse_time as date) then 'N' else 'Y' end,
parse_time => i.parse_time
)
from ]'||l_objects_view||' o
left join table( cast(:l_data as '||l_ut_owner||q'[.ut_annotation_objs_cache_info ) ) i
on o.owner = i.object_owner
and o.object_name = i.object_name
and o.object_type = i.object_type
where o.owner = ']'||l_object_owner||q'['
and o.object_type = ']'||l_object_type||q'['
where o.owner = ']'||ut_utils.qualified_sql_name(a_object_owner)||q'['
and o.object_type = ']'||ut_utils.qualified_sql_name(a_object_type)||q'['
and ]'
|| case
when a_parse_date is null
then ':a_parse_date is null'
else 'o.last_ddl_time >= cast(:a_parse_date as date)'
end;
open l_rows for l_cursor_text using a_parse_date;
open l_rows for l_cursor_text using l_data, a_parse_date;
fetch l_rows bulk collect into l_result limit ut_utils.gc_max_objects_fetch_limit;
close l_rows;
end if;
fetch l_rows bulk collect into l_result limit 10000000;
close l_rows;
ut_event_manager.trigger_event('get_annotation_objs_info - end (count='||l_result.count||')');
return l_result;
end;

function get_sources_to_annotate(a_object_owner varchar2, a_object_type varchar2) return sys_refcursor is
l_result sys_refcursor;
l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
begin
open l_result for
q'[select s.name, s.text
from (select s.name, s.text, s.line,
max(case when s.text like '%--%\%%' escape '\'
and regexp_like(s.text,'--\s*%')
then 'Y' else 'N' end
)
over(partition by s.name) is_annotated
from ]'||l_sources_view||q'[ s
where s.type = :a_object_type
and s.owner = :a_object_owner
) s
where s.is_annotated = 'Y'
order by s.name, s.line]'
using a_object_type, a_object_owner, a_object_type, a_object_owner;

return l_result;
end;

function get_sources_to_annotate(a_object_owner varchar2, a_object_type varchar2, a_objects_to_refresh ut_annotation_objs_cache_info) return sys_refcursor is
l_result sys_refcursor;
l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
Expand All @@ -158,12 +122,12 @@ create or replace package body ut_annotation_manager as
on s.name = r.object_name
and s.owner = r.object_owner
and s.type = r.object_type
where s.type = :a_object_type
and s.owner = :a_object_owner
where s.owner = ']'||ut_utils.qualified_sql_name(a_object_owner)||q'['
and s.type = ']'||ut_utils.qualified_sql_name(a_object_type)||q'['
) s
where s.is_annotated = 'Y'
order by s.name, s.line]'
using a_objects_to_refresh, a_object_type, a_object_owner;
using a_objects_to_refresh;

return l_result;
end;
Expand Down Expand Up @@ -207,7 +171,6 @@ create or replace package body ut_annotation_manager as
l_object_lines.delete;
end if;
close a_sources_cursor;
commit;
end;


Expand Down Expand Up @@ -257,7 +220,6 @@ create or replace package body ut_annotation_manager as
procedure trigger_obj_annotation_rebuild is
l_sql_text ora_name_list_t;
l_parts binary_integer;
l_object_to_parse ut_annotation_obj_cache_info;
l_restricted_users ora_name_list_t;

function get_source_from_sql_text(a_object_name varchar2, a_sql_text ora_name_list_t, a_parts binary_integer) return sys_refcursor is
Expand Down Expand Up @@ -312,8 +274,6 @@ create or replace package body ut_annotation_manager as
return;
end if;

l_object_to_parse := ut_annotation_obj_cache_info(ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type, 'Y');

if ora_sysevent = 'CREATE' then
l_parts := ORA_SQL_TXT(l_sql_text);
build_annot_cache_for_sources(
Expand All @@ -324,9 +284,13 @@ create or replace package body ut_annotation_manager as
build_annot_cache_for_sources(
ora_dict_obj_owner, ora_dict_obj_type,
get_source_for_object(ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type)
);
);
elsif ora_sysevent = 'DROP' then
ut_annotation_cache_manager.remove_from_cache(ut_annotation_objs_cache_info(l_object_to_parse));
ut_annotation_cache_manager.remove_from_cache(
ut_annotation_objs_cache_info(
ut_annotation_obj_cache_info(ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type, 'Y', null)
)
);
end if;
end if;
end;
Expand Down
3 changes: 2 additions & 1 deletion source/core/annotations/ut_annotation_obj_cache_info.tps
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ create type ut_annotation_obj_cache_info as object(
object_owner varchar2(250),
object_name varchar2(250),
object_type varchar2(250),
needs_refresh varchar2(1)
needs_refresh varchar2(1),
parse_time timestamp
)
/
Loading