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
Show all changes
24 commits
Select commit Hold shift + click to select a range
36a061c
Removed parsing of annotation text (params) from ut_annotations as an…
jgebal Oct 6, 2017
a29cabe
Removed duplicate `old_tests` for ut_annotations - the functionality …
jgebal Oct 6, 2017
58c6293
Renamed `ut_annotations` to `ut_annotation_parser` and moved to annot…
jgebal Oct 7, 2017
375a7ff
Removed ``ut_annotations` from uninstall script.
jgebal Oct 7, 2017
13703fa
Fixed failing old tests after refactoring.
jgebal Oct 7, 2017
ac23f15
Refactored ut_annotation_parser API to use `ut_annotations` collectio…
jgebal Oct 7, 2017
df2c763
Added cache mechanism to `ut_annotation_parser`.
jgebal Oct 8, 2017
6088c81
Added ability to get annotations for single object.
jgebal Oct 9, 2017
4ec9eb5
Reworking annotation cache - not to use cast(Collect()) on dba_source.
jgebal Oct 13, 2017
dbf2538
Fixed failing test and test for Wrapped package.
jgebal Oct 14, 2017
ca31e98
Added missing annotation manager.
jgebal Oct 14, 2017
289f006
Removed dbms_output from code.
jgebal Oct 14, 2017
8e26ed0
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 14, 2017
239abde
Add grant ut_annotation_manager to public
pesse Oct 16, 2017
6acd2ad
Add grant ut_annotation_manager to ut3_user
pesse Oct 16, 2017
e114aae
Merge branch 'develop' into feature/annotations_restructuring
jgebal Oct 17, 2017
b83e142
Fixed hardcoded schema-name
jgebal Oct 18, 2017
6dcaae9
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 18, 2017
aafca84
Refactored annotation cache.
jgebal Oct 22, 2017
cd394c7
Fixed test execution on 12.1.
jgebal Oct 23, 2017
73c15a2
Merge remote-tracking branch 'upstream/develop' into feature/annotati…
jgebal Oct 23, 2017
5967a3a
Fixed test execution on 12.1.
jgebal Oct 23, 2017
1438753
Merge branch 'develop' into feature/annotations_restructuring
jgebal Oct 24, 2017
4f5d870
Merge conflicts cleanup
jgebal Oct 24, 2017
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 failing test and test for Wrapped package.
To test wrapped package we need to have an annotation-like text in it.
This way the exception handler `when ex_package_is_wrapped` gets tested after adding source filters
  • Loading branch information
jgebal committed Oct 14, 2017
commit dbf25380b3f5dd4df0964fb0db27ad3dd4cf824a
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set echo off
declare
l_suites ut_suite_items;
begin
l_suites := ut_suite_manager.configure_execution_by_path(USER||'.TST_PKG_HUGE');
l_suites := ut_suite_manager.configure_execution_by_path(ut_varchar2_list(USER||'.TST_PKG_HUGE'));
end;
/

Expand Down
2 changes: 2 additions & 0 deletions old_tests/RunAll.sql
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ begin
'source/api/ut_runner.pks',
'source/core/coverage',
'source/core/types',
'source/core/annotations/ut_annotation_manager.pkb',
'source/core/annotations/ut_annotation_manager.pks',
'source/core/annotations/ut_annotation_parser.pkb',
'source/core/annotations/ut_annotation_parser.pks',
'source/core/annotations/ut_annotation_cache_manager.pkb',
Expand Down
213 changes: 24 additions & 189 deletions source/core/annotations/ut_annotation_parser.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -194,113 +194,6 @@ create or replace package body ut_annotation_parser as
return l_comments;
end extract_and_replace_comments;

function parse_object_annotations(a_source_lines in out nocopy dbms_preprocessor.source_lines_t) return ut_annotations is
l_processed_lines dbms_preprocessor.source_lines_t;
l_source clob;
l_annotations ut_annotations := ut_annotations();
ex_package_is_wrapped exception;
pragma exception_init(ex_package_is_wrapped, -24241);

begin
if a_source_lines.count > 0 then
--convert to post-processed source clob
begin
--get post-processed source
l_processed_lines := sys.dbms_preprocessor.get_post_processed_source(a_source_lines);
--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)));
end loop;
--parse annotations
l_annotations := parse_object_annotations(l_source);
dbms_lob.freetemporary(l_source);
exception
when ex_package_is_wrapped then
null;
end;
end if;
a_source_lines.delete;
return l_annotations;
end;

function get_annotated_objects_cursor(a_object_owner varchar2, a_object_type varchar2, a_object_name varchar2) return sys_refcursor is
l_result sys_refcursor;
l_ut_owner varchar2(250) := ut_utils.ut_owner;
l_objects_view varchar2(200) := ut_metadata.get_dba_view('dba_objects');
l_cursor_text long;
begin
l_cursor_text :=
q'[select ]'||l_ut_owner||q'[.ut_annotation_cached_object(
object_owner => o.owner,
object_name => o.object_name,
object_type => o.object_type,
needs_refresh => case when o.last_ddl_time < i.parse_time then 'N' else 'Y' end,
cache_id => i.cache_id
)
from ]'||l_objects_view||q'[ o
left join ut3.ut_annotation_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 = :a_object_owner
and o.object_type = :a_object_type
and o.status = 'VALID'
and :a_object_name ]'|| case when a_object_name is not null then '= o.object_name' else 'is null' end;
open l_result for l_cursor_text using a_object_owner, a_object_type, a_object_name;
return l_result;
end;

function get_sources_for_annotations(a_object_owner varchar2, a_object_type varchar2, a_object_name varchar2) return sys_refcursor is
l_result sys_refcursor;
l_sources_view varchar2(200) := ut_metadata.get_dba_view('dba_source');
begin
open l_result for
q'[select s.name, s.text
from ]'||l_sources_view||q'[ s
where s.type = :a_object_type
and s.owner = :a_object_owner
and s.name
in (select x.name
from ]'||l_sources_view||q'[ x
where x.type = :a_object_type
and x.owner = :a_object_owner
and x.text like '%--%\%%' escape '\'
and :a_object_name ]'|| case when a_object_name is not null then '= x.name' else 'is null' end || q'[
)
order by name, line]'
using a_object_type, a_object_owner, a_object_type, a_object_owner, a_object_name;

return l_result;
end;

function get_sources_for_annotations(a_object_owner varchar2, a_object_type varchar2, a_objects_to_refresh ut_annotation_cached_objects) return sys_refcursor is
l_result sys_refcursor;
l_sources_view varchar2(200) := ut_metadata.get_dba_view('dba_source');
l_card natural;
begin
l_card := ut_utils.scale_cardinality(cardinality(a_objects_to_refresh));
open l_result for
q'[select /*+ cardinality( r ]'||l_card||q'[ )*/
s.name, s.text
from table(:a_objects_to_refresh) r
join ]'||l_sources_view||q'[ s
on s.name = r.object_name
where s.type = :a_object_type
and s.owner = :a_object_owner
and s.name
in (select /*+ cardinality( x ]'||l_card||q'[ )*/
x.name
from table(:a_objects_to_refresh) t
join ]'||l_sources_view||q'[ x
on x.name = t.object_name
where x.type = :a_object_type
and x.owner = :a_object_owner
and x.text like '%--%\%%' escape '\'
)
order by name, line]'
using a_objects_to_refresh, a_object_type, a_object_owner, a_objects_to_refresh, a_object_type, a_object_owner;

return l_result;
end;

------------------------------------------------------------
--public definitions
------------------------------------------------------------
Expand Down Expand Up @@ -339,91 +232,33 @@ create or replace package body ut_annotation_parser as
return l_result;
end parse_object_annotations;

function get_annotated_objects(a_object_owner varchar2, a_object_type varchar2, a_object_name varchar2 := null) return ut_annotated_objects pipelined is
l_info_rows ut_annotation_cached_objects;
l_in_cache ut_annotation_cached_objects;
l_to_parse ut_annotation_cached_objects := ut_annotation_cached_objects();
l_cursor sys_refcursor;
l_results ut_annotated_objects;
l_result ut_annotated_object;
c_object_fetch_limit constant integer := 10;
c_lines_fetch_limit constant integer := 1000;
l_lines dbms_preprocessor.source_lines_t;
l_names dbms_preprocessor.source_lines_t;
l_name varchar2(250) := '''';
l_object_lines dbms_preprocessor.source_lines_t;
begin
--get information about cached objects
l_cursor := get_annotated_objects_cursor(a_object_owner, a_object_type, a_object_name);
fetch l_cursor bulk collect into l_info_rows;
close l_cursor;

--get list of objects in cache
select value(x) bulk collect into l_in_cache from table(l_info_rows) x where x.needs_refresh = 'N';

--if not all in cache, get list of objects to refresh
if l_in_cache.count <= l_info_rows.count then
select value(x) bulk collect into l_to_parse from table(l_info_rows) x where x.needs_refresh = 'Y';
end if;

--pipe annotations from cache
if l_in_cache.count > 0 then
l_cursor := ut_annotation_cache_manager.get_annotations_for_objects(l_in_cache);
loop
fetch l_cursor bulk collect into l_results limit c_object_fetch_limit;
for i in 1 .. l_results.count loop
pipe row (l_results(i));
end loop;
exit when l_cursor%notfound;
end loop;
close l_cursor;
end if;

--if some source needs parsing
if l_to_parse.count > 0 then
--do we need to parse all of sources
if l_in_cache.count = 0 then
l_cursor := get_sources_for_annotations(a_object_owner, a_object_type, a_object_name);
else
-- sources need to be filtered by objects to parse
l_cursor := get_sources_for_annotations(a_object_owner, a_object_type, l_to_parse);
end if;

--remove cached annotations data for objects that will be refreshed
ut_annotation_cache_manager.cleanup_cache(l_to_parse);

loop
fetch l_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_result := ut_annotated_object(a_object_owner, l_name, a_object_type, parse_object_annotations(l_object_lines));
ut_annotation_cache_manager.update_cache(l_result);
if l_result.annotations.count > 0 then
pipe row (l_result);
end if;
end if;

l_name := l_names(i);
l_object_lines(l_object_lines.count+1) := l_lines(i);
function parse_object_annotations(a_source_lines dbms_preprocessor.source_lines_t) return ut_annotations is
l_processed_lines dbms_preprocessor.source_lines_t;
l_source clob;
l_annotations ut_annotations := ut_annotations();
ex_package_is_wrapped exception;
pragma exception_init(ex_package_is_wrapped, -24241);

begin
if a_source_lines.count > 0 then
--convert to post-processed source clob
begin
--get post-processed source
l_processed_lines := sys.dbms_preprocessor.get_post_processed_source(a_source_lines);
--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)));
end loop;
exit when l_cursor%notfound;

end loop;

if l_name is not null then
l_result := ut_annotated_object(a_object_owner, l_name, a_object_type, parse_object_annotations(l_object_lines));
ut_annotation_cache_manager.update_cache(l_result);
if l_result.annotations.count > 0 then
pipe row (l_result);
end if;
end if;

close l_cursor;
dbms_output.put_line(l_source);
--parse annotations
l_annotations := parse_object_annotations(l_source);
dbms_lob.freetemporary(l_source);
exception
when ex_package_is_wrapped then
null;
end;
end if;

return l_annotations;
end;

end ut_annotation_parser;
Expand Down
24 changes: 13 additions & 11 deletions source/core/annotations/ut_annotation_parser.pks
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,28 @@ create or replace package ut_annotation_parser authid current_user as
*/

/**
* Reads database source code, parses it and returns annotations
* Parses the source passed as input parameter and returns annotations
*/

/**
* Parses source code and converts it to annotations
* Runs the source lines through dbms_preprocessor to remove lines that were not compiled (conditional compilation)
* Parses the processed source code and converts it to annotations
*
* @param a_source clob containing source code to be parsed
* @param a_source_lines ordered lines of source code to be parsed
* @return array containing annotations
*/
function parse_object_annotations(a_source clob) return ut_annotations;
function parse_object_annotations(a_source_lines dbms_preprocessor.source_lines_t) return ut_annotations;


/**
* Parses an object or all objects of a specified type for database schema.
* Pesults are returned in a form of a pipelined function.
* @param a_object_owner schema name to be parsed
* @param a_object_type type of object to be parsed
* @param a_object_name name of object to be parsed - optional
* @return array containing annotated objects along with annotations for each object (nested)
*
* @private
* Parses source code and converts it to annotations
*
* @param a_source_lines ordered lines of source code to be parsed
* @return array containing annotations
*/
function get_annotated_objects(a_object_owner varchar2, a_object_type varchar2, a_object_name varchar2 := null) return ut_annotated_objects pipelined;
function parse_object_annotations(a_source clob) return ut_annotations;

end ut_annotation_parser;
/
2 changes: 1 addition & 1 deletion source/core/ut_suite_manager.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ create or replace package body ut_suite_manager is
execute immediate
q'[select value(x)
from table(
]'||ut_utils.ut_owner||q'[.ut_annotation_parser.get_annotated_objects(:a_owner_name, 'PACKAGE')
]'||ut_utils.ut_owner||q'[.ut_annotation_manager.get_annotated_objects(:a_owner_name, 'PACKAGE')
)x ]'
bulk collect into l_annotated_objects using a_owner_name;
for i in 1 .. l_annotated_objects.count loop
Expand Down
2 changes: 2 additions & 0 deletions source/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ alter session set plsql_warnings = 'ENABLE:ALL', 'DISABLE:(5004,5018,6000,6001,6
@@install_component.sql 'core/annotations/ut_annotation_cache_manager.pkb'
@@install_component.sql 'core/annotations/ut_annotation_parser.pks'
@@install_component.sql 'core/annotations/ut_annotation_parser.pkb'
@@install_component.sql 'core/annotations/ut_annotation_manager.pks'
@@install_component.sql 'core/annotations/ut_annotation_manager.pkb'

--suite manager
@@install_component.sql 'core/ut_suite_manager.pks'
Expand Down
2 changes: 2 additions & 0 deletions source/uninstall.sql
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ drop type ut_data_value force;

drop table ut_cursor_data;

drop package ut_annotation_manager;

drop package ut_annotation_parser;

drop package ut_annotation_cache_manager;
Expand Down
Loading