@@ -194,113 +194,6 @@ create or replace package body ut_annotation_parser as
194194 return l_comments;
195195 end extract_and_replace_comments;
196196
197- function parse_object_annotations(a_source_lines in out nocopy dbms_preprocessor.source_lines_t) return ut_annotations is
198- l_processed_lines dbms_preprocessor.source_lines_t;
199- l_source clob;
200- l_annotations ut_annotations := ut_annotations();
201- ex_package_is_wrapped exception;
202- pragma exception_init(ex_package_is_wrapped, -24241);
203-
204- begin
205- if a_source_lines.count > 0 then
206- --convert to post-processed source clob
207- begin
208- --get post-processed source
209- l_processed_lines := sys.dbms_preprocessor.get_post_processed_source(a_source_lines);
210- --convert to clob
211- for i in 1..l_processed_lines.count loop
212- ut_utils.append_to_clob(l_source, replace(l_processed_lines(i), chr(13)||chr(10), chr(10)));
213- end loop;
214- --parse annotations
215- l_annotations := parse_object_annotations(l_source);
216- dbms_lob.freetemporary(l_source);
217- exception
218- when ex_package_is_wrapped then
219- null;
220- end;
221- end if;
222- a_source_lines.delete;
223- return l_annotations;
224- end;
225-
226- function get_annotated_objects_cursor(a_object_owner varchar2, a_object_type varchar2, a_object_name varchar2) return sys_refcursor is
227- l_result sys_refcursor;
228- l_ut_owner varchar2(250) := ut_utils.ut_owner;
229- l_objects_view varchar2(200) := ut_metadata.get_dba_view('dba_objects');
230- l_cursor_text long;
231- begin
232- l_cursor_text :=
233- q'[select ]'||l_ut_owner||q'[.ut_annotation_cached_object(
234- object_owner => o.owner,
235- object_name => o.object_name,
236- object_type => o.object_type,
237- needs_refresh => case when o.last_ddl_time < i.parse_time then 'N' else 'Y' end,
238- cache_id => i.cache_id
239- )
240- from ]'||l_objects_view||q'[ o
241- left join ut3.ut_annotation_cache_info i
242- on o.owner = i.object_owner and o.object_name = i.object_name and o.object_type = i.object_type
243- where o.owner = :a_object_owner
244- and o.object_type = :a_object_type
245- and o.status = 'VALID'
246- and :a_object_name ]'|| case when a_object_name is not null then '= o.object_name' else 'is null' end;
247- open l_result for l_cursor_text using a_object_owner, a_object_type, a_object_name;
248- return l_result;
249- end;
250-
251- function get_sources_for_annotations(a_object_owner varchar2, a_object_type varchar2, a_object_name varchar2) return sys_refcursor is
252- l_result sys_refcursor;
253- l_sources_view varchar2(200) := ut_metadata.get_dba_view('dba_source');
254- begin
255- open l_result for
256- q'[select s.name, s.text
257- from ]'||l_sources_view||q'[ s
258- where s.type = :a_object_type
259- and s.owner = :a_object_owner
260- and s.name
261- in (select x.name
262- from ]'||l_sources_view||q'[ x
263- where x.type = :a_object_type
264- and x.owner = :a_object_owner
265- and x.text like '%--%\%%' escape '\'
266- and :a_object_name ]'|| case when a_object_name is not null then '= x.name' else 'is null' end || q'[
267- )
268- order by name, line]'
269- using a_object_type, a_object_owner, a_object_type, a_object_owner, a_object_name;
270-
271- return l_result;
272- end;
273-
274- 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
275- l_result sys_refcursor;
276- l_sources_view varchar2(200) := ut_metadata.get_dba_view('dba_source');
277- l_card natural;
278- begin
279- l_card := ut_utils.scale_cardinality(cardinality(a_objects_to_refresh));
280- open l_result for
281- q'[select /*+ cardinality( r ]'||l_card||q'[ )*/
282- s.name, s.text
283- from table(:a_objects_to_refresh) r
284- join ]'||l_sources_view||q'[ s
285- on s.name = r.object_name
286- where s.type = :a_object_type
287- and s.owner = :a_object_owner
288- and s.name
289- in (select /*+ cardinality( x ]'||l_card||q'[ )*/
290- x.name
291- from table(:a_objects_to_refresh) t
292- join ]'||l_sources_view||q'[ x
293- on x.name = t.object_name
294- where x.type = :a_object_type
295- and x.owner = :a_object_owner
296- and x.text like '%--%\%%' escape '\'
297- )
298- order by name, line]'
299- using a_objects_to_refresh, a_object_type, a_object_owner, a_objects_to_refresh, a_object_type, a_object_owner;
300-
301- return l_result;
302- end;
303-
304197 ------------------------------------------------------------
305198 --public definitions
306199 ------------------------------------------------------------
@@ -339,91 +232,33 @@ create or replace package body ut_annotation_parser as
339232 return l_result;
340233 end parse_object_annotations;
341234
342- function get_annotated_objects(a_object_owner varchar2, a_object_type varchar2, a_object_name varchar2 := null) return ut_annotated_objects pipelined is
343- l_info_rows ut_annotation_cached_objects;
344- l_in_cache ut_annotation_cached_objects;
345- l_to_parse ut_annotation_cached_objects := ut_annotation_cached_objects();
346- l_cursor sys_refcursor;
347- l_results ut_annotated_objects;
348- l_result ut_annotated_object;
349- c_object_fetch_limit constant integer := 10;
350- c_lines_fetch_limit constant integer := 1000;
351- l_lines dbms_preprocessor.source_lines_t;
352- l_names dbms_preprocessor.source_lines_t;
353- l_name varchar2(250) := '''';
354- l_object_lines dbms_preprocessor.source_lines_t;
355- begin
356- --get information about cached objects
357- l_cursor := get_annotated_objects_cursor(a_object_owner, a_object_type, a_object_name);
358- fetch l_cursor bulk collect into l_info_rows;
359- close l_cursor;
360-
361- --get list of objects in cache
362- select value(x) bulk collect into l_in_cache from table(l_info_rows) x where x.needs_refresh = 'N';
363-
364- --if not all in cache, get list of objects to refresh
365- if l_in_cache.count <= l_info_rows.count then
366- select value(x) bulk collect into l_to_parse from table(l_info_rows) x where x.needs_refresh = 'Y';
367- end if;
368-
369- --pipe annotations from cache
370- if l_in_cache.count > 0 then
371- l_cursor := ut_annotation_cache_manager.get_annotations_for_objects(l_in_cache);
372- loop
373- fetch l_cursor bulk collect into l_results limit c_object_fetch_limit;
374- for i in 1 .. l_results.count loop
375- pipe row (l_results(i));
376- end loop;
377- exit when l_cursor%notfound;
378- end loop;
379- close l_cursor;
380- end if;
381-
382- --if some source needs parsing
383- if l_to_parse.count > 0 then
384- --do we need to parse all of sources
385- if l_in_cache.count = 0 then
386- l_cursor := get_sources_for_annotations(a_object_owner, a_object_type, a_object_name);
387- else
388- -- sources need to be filtered by objects to parse
389- l_cursor := get_sources_for_annotations(a_object_owner, a_object_type, l_to_parse);
390- end if;
391-
392- --remove cached annotations data for objects that will be refreshed
393- ut_annotation_cache_manager.cleanup_cache(l_to_parse);
394-
395- loop
396- fetch l_cursor bulk collect into l_names, l_lines limit c_lines_fetch_limit;
397-
398- for i in 1 .. l_names.count loop
399-
400- if l_names(i) != l_name then
401- l_result := ut_annotated_object(a_object_owner, l_name, a_object_type, parse_object_annotations(l_object_lines));
402- ut_annotation_cache_manager.update_cache(l_result);
403- if l_result.annotations.count > 0 then
404- pipe row (l_result);
405- end if;
406- end if;
407-
408- l_name := l_names(i);
409- l_object_lines(l_object_lines.count+1) := l_lines(i);
235+ function parse_object_annotations(a_source_lines dbms_preprocessor.source_lines_t) return ut_annotations is
236+ l_processed_lines dbms_preprocessor.source_lines_t;
237+ l_source clob;
238+ l_annotations ut_annotations := ut_annotations();
239+ ex_package_is_wrapped exception;
240+ pragma exception_init(ex_package_is_wrapped, -24241);
410241
242+ begin
243+ if a_source_lines.count > 0 then
244+ --convert to post-processed source clob
245+ begin
246+ --get post-processed source
247+ l_processed_lines := sys.dbms_preprocessor.get_post_processed_source(a_source_lines);
248+ --convert to clob
249+ for i in 1..l_processed_lines.count loop
250+ ut_utils.append_to_clob(l_source, replace(l_processed_lines(i), chr(13)||chr(10), chr(10)));
411251 end loop;
412- exit when l_cursor%notfound;
413-
414- end loop;
415-
416- if l_name is not null then
417- l_result := ut_annotated_object(a_object_owner, l_name, a_object_type, parse_object_annotations(l_object_lines));
418- ut_annotation_cache_manager.update_cache(l_result);
419- if l_result.annotations.count > 0 then
420- pipe row (l_result);
421- end if;
422- end if;
423-
424- close l_cursor;
252+ dbms_output.put_line(l_source);
253+ --parse annotations
254+ l_annotations := parse_object_annotations(l_source);
255+ dbms_lob.freetemporary(l_source);
256+ exception
257+ when ex_package_is_wrapped then
258+ null;
259+ end;
425260 end if;
426-
261+ return l_annotations;
427262 end;
428263
429264end ut_annotation_parser;
0 commit comments