@@ -58,26 +58,39 @@ create or replace package body ut_annotation_manager as
5858 l_cursor_text varchar2(32767);
5959 l_result ut_annotation_objs_cache_info;
6060 begin
61- l_cursor_text :=
62- q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
63- object_owner => o.owner,
64- object_name => o.object_name,
65- object_type => o.object_type,
66- needs_refresh => case when o.last_ddl_time < cast(i.parse_time as date) then 'N' else 'Y' end
67- )
68- from ]'||l_objects_view||q'[ o
69- left join ]'||l_ut_owner||q'[.ut_annotation_cache_info i
70- on o.owner = i.object_owner
71- and o.object_name = i.object_name
72- and o.object_type = i.object_type
73- where o.owner = ']'||a_object_owner||q'['
74- and o.object_type = ']'||a_object_type||q'['
75- and ]'
76- || case
77- when a_parse_date is null
78- then ':a_parse_date is null'
79- else 'o.last_ddl_time >= cast(:a_parse_date as date)'
80- end;
61+ if ut_trigger_check.is_alive() then
62+ l_cursor_text :=
63+ q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
64+ object_owner => i.object_owner,
65+ object_name => i.object_name,
66+ object_type => i.object_type,
67+ needs_refresh => 'N'
68+ )
69+ from ]'||l_ut_owner||q'[.ut_annotation_cache_info i
70+ where i.object_owner = :a_object_owner
71+ and i.object_type = :a_object_type]';
72+ else
73+ l_cursor_text :=
74+ q'[select ]'||l_ut_owner||q'[.ut_annotation_obj_cache_info(
75+ object_owner => o.owner,
76+ object_name => o.object_name,
77+ object_type => o.object_type,
78+ needs_refresh => case when o.last_ddl_time < cast(i.parse_time as date) then 'N' else 'Y' end
79+ )
80+ from ]'||l_objects_view||q'[ o
81+ left join ]'||l_ut_owner||q'[.ut_annotation_cache_info i
82+ on o.owner = i.object_owner
83+ and o.object_name = i.object_name
84+ and o.object_type = i.object_type
85+ where o.owner = ']'||a_object_owner||q'['
86+ and o.object_type = ']'||a_object_type||q'['
87+ and ]'
88+ || case
89+ when a_parse_date is null
90+ then ':a_parse_date is null'
91+ else 'o.last_ddl_time >= cast(:a_parse_date as date)'
92+ end;
93+ end if;
8194 open l_rows for l_cursor_text using a_parse_date;
8295 fetch l_rows bulk collect into l_result limit 1000000;
8396 close l_rows;
@@ -222,11 +235,55 @@ create or replace package body ut_annotation_manager as
222235 );
223236 end;
224237
238+ procedure trigger_obj_annotation_rebuild is
239+ l_sql_text ora_name_list_t;
240+ l_parts binary_integer;
241+ l_object_to_parse ut_annotation_obj_cache_info;
242+
243+ 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
244+ l_sql_clob clob;
245+ l_sql_lines ut_varchar2_rows := ut_varchar2_rows();
246+ l_result sys_refcursor;
247+ l_sql_text ora_name_list_t := a_sql_text;
248+ begin
249+ if a_parts > 0 then
250+ l_sql_text(1) := regexp_replace(l_sql_text(1),'^\s*create(\s+or\s+replace)?\s+', modifier => 'i');
251+ for i in 1..a_parts loop
252+ ut_utils.append_to_clob(l_sql_clob, l_sql_text(i));
253+ end loop;
254+ l_sql_lines := ut_utils.convert_collection( ut_utils.clob_to_table(l_sql_clob) );
255+ end if;
256+ open l_result for
257+ select a_object_name as name, column_value||chr(10) as text from table(l_sql_lines);
258+ return l_result;
259+ end;
260+ begin
261+ ut_trigger_check.is_alive();
262+
263+ if ora_dict_obj_type = 'PACKAGE' then
264+
265+ l_object_to_parse := ut_annotation_obj_cache_info(ora_dict_obj_owner, ora_dict_obj_name, ora_dict_obj_type, 'Y');
266+
267+ if ora_sysevent = 'CREATE' then
268+ l_parts := ORA_SQL_TXT(l_sql_text);
269+ build_annot_cache_for_sources(
270+ ora_dict_obj_owner, ora_dict_obj_type,
271+ get_source_from_sql_text(ora_dict_obj_name, l_sql_text, l_parts)
272+ );
273+ elsif ora_sysevent = 'ALTER' then
274+ null;
275+ --update parse_time
276+ elsif ora_sysevent = 'DROP' then
277+ ut_annotation_cache_manager.remove_from_cache(ut_annotation_objs_cache_info(l_object_to_parse));
278+ end if;
279+ end if;
280+ end;
281+
225282 function get_annotated_objects(a_object_owner varchar2, a_object_type varchar2, a_parse_date timestamp := null) return ut_annotated_objects pipelined is
226283 l_info_rows ut_annotation_objs_cache_info;
227284 l_cursor sys_refcursor;
228285 l_results ut_annotated_objects;
229- c_object_fetch_limit constant integer := 10;
286+ c_object_fetch_limit constant integer := 10;
230287 begin
231288
232289 l_info_rows := get_annotation_objs_info(a_object_owner, a_object_type, a_parse_date);
0 commit comments