@@ -149,7 +149,7 @@ create or replace package body ut_suite_manager is
149149 return l_results;
150150 end;
151151
152- procedure copy_list_reverse_order (
152+ procedure reverse_list_order (
153153 a_list in out nocopy ut_suite_items
154154 ) is
155155 l_start_idx pls_integer;
@@ -277,9 +277,14 @@ create or replace package body ut_suite_manager is
277277 end loop;
278278 exit when l_rows.count < c_bulk_limit;
279279 end loop;
280- copy_list_reverse_order( a_suites );
280+
281+ reverse_list_order( a_suites );
282+
283+ for i in 1 .. a_suites.count loop
284+ a_suites( i ).set_rollback_type( a_suites( i ).get_rollback_type );
285+ end loop;
281286 close a_suite_data_cursor;
282- end;
287+ end reconstruct_from_cache ;
283288
284289 function get_missing_objects(a_object_owner varchar2) return ut_varchar2_rows is
285290 l_rows sys_refcursor;
@@ -338,7 +343,7 @@ create or replace package body ut_suite_manager is
338343 ( select 1
339344 from all_objects a
340345 where a.object_name = c.object_name
341- and a.object_owner = ']'||upper(a_object_owner)||q'['
346+ and a.owner = ']'||upper(a_object_owner)||q'['
342347 and a.owner = c.object_owner
343348 and a.object_type = 'PACKAGE'
344349 )]' end ||q'[
@@ -417,44 +422,91 @@ create or replace package body ut_suite_manager is
417422 return l_result;
418423 end;
419424
420- function build_schema_suites(
421- a_owner_name varchar2,
422- a_path varchar2 := null,
423- a_object_name varchar2 := null,
424- a_procedure_name varchar2 := null
425- ) return ut_suite_items is
425+ function can_skip_all_objects_scan(
426+ a_owner_name varchar2
427+ ) return boolean is
428+ begin
429+ return sys_context( 'userenv', 'current_schema' ) = a_owner_name or ut_metadata.is_object_visible( ut_utils.ut_owner ||'.ut_utils' );
430+ end;
431+
432+ procedure build_and_cache_suites(
433+ a_owner_name varchar2,
434+ a_annotated_objects sys_refcursor
435+ ) is
436+ l_annotated_objects ut_annotated_objects;
437+ l_suite_items ut_suite_items;
438+ begin
439+ loop
440+ fetch a_annotated_objects bulk collect into l_annotated_objects limit 10;
441+
442+ for i in 1 .. l_annotated_objects.count loop
443+ ut_suite_builder.create_suite_item_list( l_annotated_objects( i ), l_suite_items );
444+ ut_suite_cache_manager.save_object_cache(
445+ a_owner_name,
446+ l_annotated_objects( i ).object_name,
447+ l_annotated_objects( i ).parse_time,
448+ l_suite_items
449+ );
450+ end loop;
451+ exit when a_annotated_objects%notfound;
452+ end loop;
453+ close a_annotated_objects;
454+
455+ end;
456+
457+ procedure refresh_cache(
458+ a_owner_name varchar2,
459+ a_annotations_cursor sys_refcursor := null
460+ ) is
426461 l_annotations_cursor sys_refcursor;
427462 l_suite_cache_time timestamp;
428- l_skip_all_objects_scan boolean := false;
429463 begin
430464 l_suite_cache_time := ut_suite_cache_manager.get_schema_parse_time(a_owner_name);
431- open l_annotations_cursor for
432- q'[select value(x)
433- from table(
434- ]' || ut_utils.ut_owner || q'[.ut_annotation_manager.get_annotated_objects(:a_owner_name, 'PACKAGE', :a_suite_cache_parse_time)
435- )x ]'
436- using a_owner_name, l_suite_cache_time;
437-
438- -- if current user is the onwer or current user has execute any procedure privilege
439- if sys_context('userenv','current_schema') = a_owner_name
440- or ut_metadata.is_object_visible('ut3.ut_utils')
441- then
442- l_skip_all_objects_scan := true;
465+ if a_annotations_cursor is not null then
466+ l_annotations_cursor := a_annotations_cursor;
467+ else
468+ open l_annotations_cursor for
469+ q'[select value(x)
470+ from table(
471+ ]' || ut_utils.ut_owner || q'[.ut_annotation_manager.get_annotated_objects(
472+ :a_owner_name, 'PACKAGE', :a_suite_cache_parse_time
473+ )
474+ )x ]'
475+ using a_owner_name, l_suite_cache_time;
443476 end if;
444- if l_skip_all_objects_scan or ut_metadata.is_object_visible('dba_objects') then
477+
478+ build_and_cache_suites(a_owner_name, l_annotations_cursor);
479+
480+ if can_skip_all_objects_scan(a_owner_name) or ut_metadata.is_object_visible( 'dba_objects') then
445481 ut_suite_cache_manager.remove_from_cache( a_owner_name, get_missing_objects(a_owner_name) );
446482 end if;
447483
448- return build_suites_from_annotations(
449- a_owner_name,
450- l_annotations_cursor,
451- a_path,
452- a_object_name,
453- a_procedure_name,
454- l_skip_all_objects_scan
455- );
456484 end;
457485
486+ function get_suites_for_path(
487+ a_owner_name varchar2,
488+ a_path varchar2 := null,
489+ a_object_name varchar2 := null,
490+ a_procedure_name varchar2 := null
491+ ) return ut_suite_items is
492+ l_suites ut_suite_items;
493+ begin
494+ refresh_cache(a_owner_name);
495+
496+ reconstruct_from_cache(
497+ l_suites,
498+ get_cached_suite_data(
499+ a_owner_name,
500+ a_path,
501+ a_object_name,
502+ a_procedure_name,
503+ can_skip_all_objects_scan(a_owner_name)
504+ )
505+ );
506+ return l_suites;
507+
508+ end get_suites_for_path;
509+
458510 -----------------------------------------------
459511 -----------------------------------------------
460512 ------------- Public definitions -------------
@@ -468,24 +520,8 @@ create or replace package body ut_suite_manager is
468520 a_skip_all_objects boolean := false
469521 ) return ut_suite_items is
470522 l_suites ut_suite_items;
471- l_annotated_objects ut_annotated_objects;
472- l_suite_items ut_suite_items;
473523 begin
474- loop
475- fetch a_annotated_objects bulk collect into l_annotated_objects limit 10;
476-
477- for i in 1 .. l_annotated_objects.count loop
478- ut_suite_builder.create_suite_item_list( l_annotated_objects( i ), l_suite_items );
479- ut_suite_cache_manager.save_object_cache(
480- a_owner_name,
481- l_annotated_objects( i ).object_name,
482- l_annotated_objects( i ).parse_time,
483- l_suite_items
484- );
485- end loop;
486- exit when a_annotated_objects%notfound;
487- end loop;
488- close a_annotated_objects;
524+ build_and_cache_suites(a_owner_name, a_annotated_objects);
489525
490526 reconstruct_from_cache(
491527 l_suites,
@@ -497,9 +533,6 @@ create or replace package body ut_suite_manager is
497533 a_skip_all_objects
498534 )
499535 );
500- for i in 1 .. l_suites.count loop
501- l_suites( i ).set_rollback_type( l_suites( i ).get_rollback_type );
502- end loop;
503536 return l_suites;
504537 end;
505538
@@ -566,7 +599,7 @@ create or replace package body ut_suite_manager is
566599 l_path_items := l_schema_paths(l_schema);
567600 for i in 1 .. l_path_items.count loop
568601 l_path_item := l_path_items(i);
569- l_suites := build_schema_suites (
602+ l_suites := get_suites_for_path (
570603 upper(l_schema),
571604 l_path_item.suite_path,
572605 l_path_item.object_name,
@@ -599,5 +632,81 @@ create or replace package body ut_suite_manager is
599632 return l_objects_to_run;
600633 end configure_execution_by_path;
601634
635+ function get_suites_info(a_owner_name varchar2) return tt_suite_items pipelined is
636+ l_cursor sys_refcursor;
637+ l_ut_owner varchar2(250) := ut_utils.ut_owner;
638+ c_bulk_limit constant integer := 100;
639+ l_results tt_suite_items;
640+ begin
641+ refresh_cache(a_owner_name);
642+
643+ open l_cursor for
644+ q'[with
645+ suite_items as (
646+ select /*+ cardinality(c 100) */ c.*
647+ from ]'||l_ut_owner||q'[.ut_suite_cache c
648+ where 1 = 1 ]'||case when can_skip_all_objects_scan(a_owner_name) then q'[
649+ and exists
650+ ( select 1
651+ from all_objects a
652+ where a.object_name = c.object_name
653+ and a.owner = ']'||upper(a_owner_name)||q'['
654+ and a.owner = c.object_owner
655+ and a.object_type = 'PACKAGE'
656+ )]' end ||q'[
657+ and c.object_owner = ']'||upper(a_owner_name)||q'['
658+ ),
659+ suitepaths as (
660+ select distinct
661+ substr(path,1,instr(path,'.',-1)-1) as suitepath,
662+ path,
663+ object_owner
664+ from suite_items
665+ where self_type = 'UT_SUITE'
666+ ),
667+ gen as (
668+ select rownum as pos
669+ from xmltable('1 to 20')
670+ ),
671+ suitepath_part AS (
672+ select distinct
673+ substr(b.suitepath, 1, instr(b.suitepath || '.', '.', 1, g.pos) -1) as path,
674+ object_owner
675+ from suitepaths b
676+ join gen g
677+ on g.pos <= regexp_count(b.suitepath, '\w+')
678+ ),
679+ logical_suites as (
680+ select 'UT_LOGICAL_SUITE' as item_type,
681+ p.path, p.object_owner,
682+ upper( substr(p.path, instr( p.path, '.', -1 ) + 1 ) ) as object_name
683+ from suitepath_part p
684+ where p.path
685+ not in (select s.path from suitepaths s)
686+ ),
687+ items as (
688+ select object_owner, object_name, name as item_name,
689+ description as item_description, self_type as item_type, line_no as item_line_no,
690+ path, disabled_flag
691+ from suite_items
692+ union all
693+ select object_owner, object_name, object_name as item_name,
694+ null as item_description, item_type, null as item_line_no,
695+ s.path, 0 as disabled_flag
696+ from logical_suites s
697+ )
698+ select c.*
699+ from items c]';
700+ loop
701+ fetch l_cursor bulk collect into l_results limit c_bulk_limit;
702+ for i in 1 .. l_results.count loop
703+ pipe row (l_results(i));
704+ end loop;
705+ exit when l_cursor%notfound;
706+ end loop;
707+ close l_cursor;
708+
709+ end;
710+
602711end ut_suite_manager;
603712/
0 commit comments