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
Prev Previous commit
Next Next commit
Fixed issues with parsing code through trigger.
Added disabling trigger on annotation parser tests.
  • Loading branch information
jgebal committed Jun 8, 2019
commit 242b2a3fbce7af7a6e5f7568d01d7bf3aa6cf0b3
3 changes: 3 additions & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ SQL
time "$SQLCLI" sys/$ORACLE_PWD@//$CONNECTION_STR AS SYSDBA <<-SQL
set feedback off
@create_utplsql_owner.sql $UT3_TESTER $UT3_TESTER_PASSWORD $UT3_TABLESPACE
--needed for disabling DDL trigger and testint parser without trigger enabled/present
grant alter any trigger to ut3_tester;
grant administer database trigger to $UT3_TESTER;
exit
SQL

Expand Down
8 changes: 4 additions & 4 deletions source/core/annotations/ut_annotation_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ create or replace package body ut_annotation_manager as
fetch a_sources_cursor bulk collect into l_names, l_lines limit c_lines_fetch_limit;
for i in 1 .. l_names.count loop
if l_names(i) != l_name then
l_annotations := ut_annotation_parser.parse_object_annotations(l_object_lines);
l_annotations := ut_annotation_parser.parse_object_annotations(l_object_lines, a_object_type);
ut_annotation_cache_manager.update_cache(
ut_annotated_object(a_object_owner, l_name, a_object_type, l_parse_time, l_annotations)
);
Expand All @@ -196,7 +196,7 @@ create or replace package body ut_annotation_manager as

end loop;
if a_sources_cursor%rowcount > 0 then
l_annotations := ut_annotation_parser.parse_object_annotations(l_object_lines);
l_annotations := ut_annotation_parser.parse_object_annotations(l_object_lines, a_object_type);
ut_annotation_cache_manager.update_cache(
ut_annotated_object(a_object_owner, l_name, a_object_type, l_parse_time, l_annotations)
);
Expand Down Expand Up @@ -263,14 +263,14 @@ create or replace package body ut_annotation_manager as
l_sql_text ora_name_list_t := a_sql_text;
begin
if a_parts > 0 then
l_sql_text(1) := regexp_replace(l_sql_text(1),'^\s*create(\s+or\s+replace)?(\s+(non)?editionable)?\s+', modifier => 'i');
l_sql_text(1) := regexp_replace(l_sql_text(1),'^\s*create(\s+or\s+replace){0,1}(\s+(editionable|noneditionable)){0,1}\s+{0,1}', modifier => 'i');
for i in 1..a_parts loop
ut_utils.append_to_clob(l_sql_clob, l_sql_text(i));
end loop;
l_sql_lines := ut_utils.convert_collection( ut_utils.clob_to_table(l_sql_clob) );
end if;
open l_result for
select a_object_name as name, column_value||chr(10) as text from table(l_sql_lines) where rownum <1;
select a_object_name as name, column_value||chr(10) as text from table(l_sql_lines);
return l_result;
end;
begin
Expand Down
8 changes: 6 additions & 2 deletions source/core/annotations/ut_annotation_parser.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ create or replace package body ut_annotation_parser as
return l_result;
end parse_object_annotations;

function parse_object_annotations(a_source_lines dbms_preprocessor.source_lines_t) return ut_annotations is
function parse_object_annotations(a_source_lines dbms_preprocessor.source_lines_t, a_object_type varchar2) return ut_annotations is
l_processed_lines dbms_preprocessor.source_lines_t;
l_source clob;
l_annotations ut_annotations := ut_annotations();
Expand All @@ -235,7 +235,11 @@ create or replace package body ut_annotation_parser as
--convert to post-processed source clob
begin
--get post-processed source
l_processed_lines := sys.dbms_preprocessor.get_post_processed_source(a_source_lines);
if a_object_type = 'TYPE' then
l_processed_lines := a_source_lines;
else
l_processed_lines := sys.dbms_preprocessor.get_post_processed_source(a_source_lines);
end if;
--convert to clob
for i in 1..l_processed_lines.count loop
ut_utils.append_to_clob(l_source, replace(l_processed_lines(i), chr(13)||chr(10), chr(10)));
Expand Down
2 changes: 1 addition & 1 deletion source/core/annotations/ut_annotation_parser.pks
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ create or replace package ut_annotation_parser authid current_user as
* @param a_source_lines ordered lines of source code to be parsed
* @return array containing annotations
*/
function parse_object_annotations(a_source_lines dbms_preprocessor.source_lines_t) return ut_annotations;
function parse_object_annotations(a_source_lines dbms_preprocessor.source_lines_t, a_object_type varchar2) return ut_annotations;


/**
Expand Down
1 change: 1 addition & 0 deletions source/core/annotations/ut_trigger_annotation_parsing.trg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ begin
'ANONYMOUS','APPQOSSYS','AUDSYS','DBSFWUSER','DBSNMP','DIP','GGSYS','GSMADMIN_INTERNAL',
Comment thread
lwasylow marked this conversation as resolved.
Outdated
'GSMCATUSER','GSMUSER','ORACLE_OCM','OUTLN','REMOTE_SCHEDULER_AGENT','SYS','SYS$UMF',
'SYSBACKUP','SYSDG','SYSKM','SYSRAC','SYSTEM','WMSYS','XDB','XS$NULL')
and not (ora_dict_obj_type = 'TYPE' and ora_dict_obj_name like 'SYS\_PLSQL\_%' escape '\')
)
or (ora_dict_obj_owner = UPPER('&&UT3_OWNER')
and ora_dict_obj_name = 'UT3_TRIGGER_ALIVE'
Expand Down
3 changes: 2 additions & 1 deletion source/core/annotations/ut_trigger_check.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ create or replace package body ut_trigger_check is
*/

g_is_trigger_live boolean := false;
gc_check_object_name constant varchar2(128) := 'UT3_TRIGGER_ALIVE';

function is_alive return boolean is
pragma autonomous_transaction;
Expand All @@ -32,6 +31,8 @@ create or replace package body ut_trigger_check is
begin
if ora_dict_obj_owner = ut_utils.ut_owner and ora_dict_obj_name = gc_check_object_name and ora_dict_obj_type = 'SYNONYM' then
g_is_trigger_live := true;
else
g_is_trigger_live := false;
end if;
end;

Expand Down
7 changes: 6 additions & 1 deletion source/core/annotations/ut_trigger_check.pks
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ create or replace package ut_trigger_check authid definer is
limitations under the License.
*/

gc_check_object_name constant varchar2(128) := 'UT3_TRIGGER_ALIVE';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would that not be better to define in utils for example and refer to it via package constant in trigger and this package ? Its only called twice but one less line to maintain ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be removed as no longer used - thanks


/**
* checks if the trigger &&UT3_OWNER._PARSE is enabled and operational.
*/

function is_alive return boolean;

/**
* If called from a DDL trigger when creating object gc_check_object_name, sts alive flag to true
* Otherwise sets alive flag to false.
*/
procedure is_alive;

end;
Expand Down
19 changes: 17 additions & 2 deletions test/ut3_tester/core/annotations/test_annotation_manager.pkb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
create or replace package body test_annotation_manager is

procedure disable_ddl_trigger is
pragma autonomous_transaction;
begin
execute immediate 'alter trigger ut3.ut_trigger_annotation_parsing disable';
execute immediate 'begin ut3.ut_trigger_check.is_alive(); end;';
end;

procedure enable_ddl_trigger is
pragma autonomous_transaction;
begin
execute immediate 'alter trigger ut3.ut_trigger_annotation_parsing enable';
end;

procedure create_dummy_package is
pragma autonomous_transaction;
begin
Expand Down Expand Up @@ -49,6 +62,9 @@ create or replace package body test_annotation_manager is
pragma autonomous_transaction;
begin
execute immediate q'[drop package dummy_test_package]';
exception
when others then
null;
end;

procedure recompile_dummy_test_package is
Expand Down Expand Up @@ -241,8 +257,7 @@ create or replace package body test_annotation_manager is
order by annotation_position;

open l_expected for
select 2 as annotation_position, 'suite' as annotation_name,
'dummy_test_suite' as annotation_text, '' as subobject_name
select 2 as annotation_position, 'suite' as annotation_name, 'dummy_test_suite' as annotation_text, '' as subobject_name
from dual union all
select 3, 'rollback' , 'manual', '' as subobject_name
from dual union all
Expand Down
26 changes: 15 additions & 11 deletions test/ut3_tester/core/annotations/test_annotation_manager.pks
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,21 @@ create or replace package test_annotation_manager is

procedure drop_dummy_test_package;

--%context(Without DDL trigger)

--%beforeall
procedure disable_ddl_trigger;

--%afterall
procedure enable_ddl_trigger;

--%beforeeach(create_dummy_package)
--%aftereach(drop_dummy_package)

--%test(Adds new package to annotation cache info)
--%beforetest(create_dummy_package)
--%aftertest(drop_dummy_package)
--%disabled(TODO - make it run with triger disabled)
procedure add_new_package;

--%test(Updates annotation cache info for modified package)
--%beforetest(create_dummy_package)
--%aftertest(drop_dummy_package)
--%disabled(TODO - make it run with triger disabled)
procedure update_modified_package;

--%test(Adds annotations to cache for unit test package)
Expand All @@ -36,23 +41,22 @@ create or replace package test_annotation_manager is
procedure add_new_test_package;

--%test(Updates annotations in cache for modified test package)
--%beforetest(create_dummy_test_package)
--%aftertest(drop_dummy_test_package)
procedure update_modified_test_package;

--%test(Keeps annotations in cache when object was removed but user can't see whole schema)
--%beforetest(create_dummy_test_package,create_parse_proc_as_ut3$user#)
--%aftertest(drop_parse_proc_as_ut3$user#)
--%disabled(no longer true with trigger enabled)
procedure keep_dropped_data_in_cache;

--%test(Does not return data for dropped object)
--%beforetest(create_dummy_test_package)
procedure no_data_for_dropped_object;

--%test(Remove object from cache when object dropped and user can see whole schema)
--%beforetest(create_dummy_test_package)
procedure cleanup_dropped_data_in_cache;

--%endcontext

--TODO add tests with trigger

end test_annotation_manager;
/
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ v58yvbLAXLi9gYHwoIvAgccti+Cmpg0DKLY=
-- %some_annotation_like_text
';
--Act
l_actual := ut3.ut_annotation_parser.parse_object_annotations(l_source);
l_actual := ut3.ut_annotation_parser.parse_object_annotations(l_source,'PACKAGE');
--Assert
ut.expect(anydata.convertCollection(l_actual)).to_be_empty();
end;
Expand Down