@@ -19,6 +19,38 @@ create or replace package body ut_annotation_manager as
1919 ------------------------------
2020 --private definitions
2121
22+ -- function get_missing_objects(a_object_owner varchar2, a_object_type varchar2) return ut_annotation_objs_cache_info is
23+ -- l_rows sys_refcursor;
24+ -- l_ut_owner varchar2(250) := ut_utils.ut_owner;
25+ -- l_objects_view varchar2(200) := ut_metadata.get_dba_view('dba_objects');
26+ -- l_cursor_text varchar2(32767);
27+ -- l_result ut_annotation_objs_cache_info;
28+ -- begin
29+ -- l_cursor_text :=
30+ -- q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
31+ -- object_owner => i.object_owner,
32+ -- object_name => i.object_name,
33+ -- object_type => i.object_type,
34+ -- needs_refresh => null
35+ -- )
36+ -- from ]'||l_ut_owner||q'[.ut_annotation_cache_info i
37+ -- where
38+ -- not exists (
39+ -- select 1 from ]'||l_objects_view||q'[ o
40+ -- where o.owner = i.object_owner
41+ -- and o.object_name = i.object_name
42+ -- and o.object_type = i.object_type
43+ -- and o.owner = :a_object_owner
44+ -- and o.object_type = :a_object_type
45+ -- )
46+ -- and i.object_owner = :a_object_owner
47+ -- and i.object_type = :a_object_type]';
48+ -- open l_rows for l_cursor_text using a_object_owner, a_object_type, a_object_owner, a_object_type;
49+ -- fetch l_rows bulk collect into l_result limit 1000000;
50+ -- close l_rows;
51+ -- return l_result;
52+ -- end;
53+
2254 function get_annotation_objs_info(a_object_owner varchar2, a_object_type varchar2, a_parse_date timestamp := null) return ut_annotation_objs_cache_info is
2355 l_rows sys_refcursor;
2456 l_ut_owner varchar2(250) := ut_utils.ut_owner;
@@ -28,25 +60,36 @@ create or replace package body ut_annotation_manager as
2860 begin
2961 l_cursor_text :=
3062 q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
31- object_owner => o.owner,
32- object_name => o.object_name,
33- object_type => o.object_type,
34- needs_refresh => case when o.last_ddl_time < cast(i.parse_time as date) then 'N' else 'Y' end
63+ object_owner => nvl( o.owner, i.object_owner ),
64+ object_name => nvl( o.object_name, i.object_name ),
65+ object_type => nvl( o.object_type, i.object_type ),
66+ needs_refresh =>
67+ case
68+ when o.last_ddl_time < cast(i.parse_time as date) then 'N'
69+ when o.owner is null then null
70+ else 'Y'
71+ end
3572 )
36- from ]'||l_objects_view||q'[ o
37- left join ]'||l_ut_owner||q'[.ut_annotation_cache_info i
73+ from (
74+ select * from ]'||l_objects_view||q'[ o
75+ where o.owner = :a_object_owner
76+ and o.object_type = :a_object_type
77+ ) o
78+ full outer join (
79+ select * from ]'||l_ut_owner||q'[.ut_annotation_cache_info i
80+ where i.object_owner = :a_object_owner
81+ and i.object_type = :a_object_type
82+ ) i
3883 on o.owner = i.object_owner
3984 and o.object_name = i.object_name
4085 and o.object_type = i.object_type
41- where o.owner = :a_object_owner
42- and o.object_type = :a_object_type
43- and ]'
86+ where ]'
4487 || case
4588 when a_parse_date is null
4689 then ':a_parse_date is null'
47- else 'o.last_ddl_time >= cast(:a_parse_date as date)'
90+ else 'o.last_ddl_time >= cast(:a_parse_date as date) or o.last_ddl_time is null '
4891 end;
49- open l_rows for l_cursor_text using a_object_owner, a_object_type, a_parse_date;
92+ open l_rows for l_cursor_text using a_object_owner, a_object_type, a_object_owner, a_object_type, a_parse_date;
5093 fetch l_rows bulk collect into l_result limit 1000000;
5194 close l_rows;
5295 return l_result;
@@ -106,8 +149,9 @@ create or replace package body ut_annotation_manager as
106149 end;
107150
108151 procedure build_annot_cache_for_sources(
109- a_object_owner varchar2, a_object_type varchar2, a_sources_cursor sys_refcursor,
110- a_schema_objects ut_annotation_objs_cache_info
152+ a_object_owner varchar2,
153+ a_object_type varchar2,
154+ a_sources_cursor sys_refcursor
111155 ) is
112156 l_annotations ut_annotations;
113157 c_lines_fetch_limit constant integer := 1000;
@@ -118,7 +162,6 @@ create or replace package body ut_annotation_manager as
118162 l_parse_time date := sysdate;
119163 pragma autonomous_transaction;
120164 begin
121- ut_annotation_cache_manager.cleanup_cache(a_schema_objects);
122165 loop
123166 fetch a_sources_cursor bulk collect into l_names, l_lines limit c_lines_fetch_limit;
124167 for i in 1 .. l_names.count loop
@@ -148,17 +191,37 @@ create or replace package body ut_annotation_manager as
148191 end;
149192
150193
151- procedure rebuild_annotation_cache( a_object_owner varchar2, a_object_type varchar2, a_info_rows ut_annotation_objs_cache_info) is
152- l_objects_to_parse ut_annotation_objs_cache_info := ut_annotation_objs_cache_info();
194+ procedure rebuild_annotation_cache(
195+ a_object_owner varchar2,
196+ a_object_type varchar2,
197+ a_info_rows ut_annotation_objs_cache_info
198+ ) is
199+ l_objects_to_parse ut_annotation_objs_cache_info;
200+ l_objects_to_remove ut_annotation_objs_cache_info;
153201 begin
154- select value(x)bulk collect into l_objects_to_parse from table(a_info_rows) x where x.needs_refresh = 'Y';
202+ select value(x)bulk collect into l_objects_to_parse
203+ from table(a_info_rows) x where x.needs_refresh = 'Y';
204+
205+ ut_annotation_cache_manager.cleanup_cache(l_objects_to_parse);
206+
207+ if sys_context('userenv','current_schema') = a_object_owner
208+ or ut_metadata.is_object_visible('ut3.ut_utils')
209+ or ut_metadata.is_object_visible('dba_objects')
210+ then
211+ select value(x)bulk collect into l_objects_to_remove
212+ from table(a_info_rows) x where x.needs_refresh is null;
213+
214+ ut_annotation_cache_manager.remove_from_cache(l_objects_to_remove);
215+ -- ut_annotation_cache_manager.remove_from_cache(
216+ -- get_missing_objects(a_object_owner, a_object_type)
217+ -- );
218+ end if;
155219
156220 --if some source needs parsing and putting into cache
157221 if l_objects_to_parse.count > 0 then
158222 build_annot_cache_for_sources(
159223 a_object_owner, a_object_type,
160- get_sources_to_annotate(a_object_owner, a_object_type, l_objects_to_parse),
161- l_objects_to_parse
224+ get_sources_to_annotate(a_object_owner, a_object_type, l_objects_to_parse)
162225 );
163226 end if;
164227 end;
0 commit comments