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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Cleanup some grants to internal objects & tables
Removed grants:
- execute on ut_annotations
- execute on ut_annotation
- execute on ut_annotated_object
- execute on ut_annotated_objects
- select on ut_annotation_cache
- select on ut_annotation_cache_info
- execute ut_annotation_cache_manager
- execute ut_annotation_parser

Reorganized code to accommodate for grants removal.
Wrapped `sys.dbms_assert.qualified_sql_name` to support NULL values.
Replaced calls to `dbms_crypto.hash` with `ut_utils.get_hash` - default `SHA1`
  • Loading branch information
jgebal committed Jun 22, 2019
commit c7b802f5fe40b6d751dd46cc8fc5d27903f96faf
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
5 changes: 1 addition & 4 deletions source/api/ut_runner.pkb
Original file line number Diff line number Diff line change
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
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: 44 additions & 78 deletions source/core/annotations/ut_annotation_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ create or replace package body ut_annotation_manager as
limitations under the License.
*/

gc_max_objects_limit integer := 1000000;
------------------------------
--private definitions

Expand All @@ -24,29 +25,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 gc_max_objects_limit;
close l_rows;
return l_result;
end;
Expand All @@ -61,83 +61,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 gc_max_objects_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 +123,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 @@ -257,7 +222,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 +276,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 +286,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
)
/
2 changes: 1 addition & 1 deletion source/core/ut_metadata.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ create or replace package body ut_metadata as
if not l_result like '"%"' then
l_result := upper(l_result);
end if;
return sys.dbms_assert.qualified_sql_name(l_result);
return ut_utils.qualified_sql_name(l_result);
end;

function get_anydata_compound_type(a_data_value anydata) return varchar2 is
Expand Down
44 changes: 14 additions & 30 deletions source/core/ut_suite_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -401,20 +401,22 @@ create or replace package body ut_suite_manager is
l_cursor_text varchar2(32767);
l_result ut_varchar2_rows;
l_object_owner varchar2(250);
l_data ut_annotation_objs_cache_info;
begin
l_object_owner := sys.dbms_assert.qualified_sql_name(a_object_owner);
l_object_owner := ut_utils.qualified_sql_name(a_object_owner);
l_data := ut_annotation_cache_manager.get_annotations_objects_info(a_object_owner, 'PACKAGE');
l_cursor_text :=
q'[select i.object_name
from ]'||l_ut_owner||q'[.ut_suite_cache_package i
where
not exists (
select 1 from ]'||l_ut_owner||q'[.ut_annotation_cache_info o
select 1 from table(:l_data) o
where o.object_owner = i.object_owner
and o.object_name = i.object_name
and o.object_type = 'PACKAGE'
)
and i.object_owner = ']'||l_object_owner||q'[']';
open l_rows for l_cursor_text;
open l_rows for l_cursor_text using l_data;
fetch l_rows bulk collect into l_result limit 1000000;
close l_rows;
return l_result;
Expand Down Expand Up @@ -516,15 +518,9 @@ create or replace package body ut_suite_manager is
l_object_name varchar2(250);
l_procedure_name varchar2(250);
begin
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_name is not null then
l_object_name := sys.dbms_assert.qualified_sql_name(a_object_name);
end if;
if a_procedure_name is not null then
l_procedure_name := sys.dbms_assert.qualified_sql_name(a_procedure_name);
end if;
l_object_owner := ut_utils.qualified_sql_name(a_object_owner);
l_object_name := ut_utils.qualified_sql_name(a_object_name);
l_procedure_name := ut_utils.qualified_sql_name(a_procedure_name);
if a_path is null and a_object_name is not null then
execute immediate 'select min(path)
from '||l_ut_owner||q'[.ut_suite_cache
Expand All @@ -533,9 +529,7 @@ create or replace package body ut_suite_manager is
and name = nvl(:a_procedure_name, name)]'
into l_path using upper(l_object_owner), upper(l_object_name), upper(a_procedure_name);
else
if a_path is not null then
l_path := lower(sys.dbms_assert.qualified_sql_name(a_path));
end if;
l_path := lower(ut_utils.qualified_sql_name(a_path));
end if;
l_suite_item_name := case when l_tags.count > 0 then 'suite_items_tags' else 'suite_items' end;

Expand Down Expand Up @@ -804,12 +798,8 @@ create or replace package body ut_suite_manager is
l_owner_name varchar2(250);
l_package_name varchar2(250);
begin
if a_owner_name is not null then
l_owner_name := sys.dbms_assert.qualified_sql_name(a_owner_name);
end if;
if a_package_name is not null then
l_package_name := sys.dbms_assert.qualified_sql_name(a_package_name);
end if;
l_owner_name := ut_utils.qualified_sql_name(a_owner_name);
l_package_name := ut_utils.qualified_sql_name(a_package_name);

refresh_cache(l_owner_name);

Expand Down Expand Up @@ -894,15 +884,9 @@ create or replace package body ut_suite_manager is
l_package_name varchar2(250);
l_procedure_name varchar2(250);
begin
if a_owner_name is not null then
l_owner_name := sys.dbms_assert.qualified_sql_name(a_owner_name);
end if;
if a_package_name is not null then
l_package_name := sys.dbms_assert.qualified_sql_name(a_package_name);
end if;
if a_procedure_name is not null then
l_procedure_name := sys.dbms_assert.qualified_sql_name(a_procedure_name);
end if;
l_owner_name := ut_utils.qualified_sql_name(a_owner_name);
l_package_name := ut_utils.qualified_sql_name(a_package_name);
l_procedure_name := ut_utils.qualified_sql_name(a_procedure_name);

refresh_cache(l_owner_name);

Expand Down
19 changes: 19 additions & 0 deletions source/core/ut_utils.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -865,5 +865,24 @@ create or replace package body ut_utils is
return regexp_replace(a_item,a_prefix||a_connector);
end;

function get_hash(a_data raw, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
begin
return dbms_crypto.hash(a_data, a_hash_type);
end;

function get_hash(a_data clob, a_hash_type binary_integer := dbms_crypto.hash_sh1) return t_hash is
begin
return dbms_crypto.hash(a_data, a_hash_type);
end;

function qualified_sql_name(a_name varchar2) return varchar2 is
begin
return
case
when a_name is not null
then sys.dbms_assert.qualified_sql_name(a_name)
end;
end;

end ut_utils;
/
Loading