Skip to content

Commit a658cdf

Browse files
authored
Merge pull request #1180 from utPLSQL/feature/1177_trigger_not_removing_annotation
Adding option to remove a cache for annotations on existing packag
2 parents f28ae62 + bc6da98 commit a658cdf

File tree

3 files changed

+119
-6
lines changed

3 files changed

+119
-6
lines changed

source/core/annotations/ut_annotation_cache_manager.pkb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ create or replace package body ut_annotation_cache_manager as
3232
end if;
3333

3434
-- if not in trigger, or object has annotations
35-
if ora_sysevent is null or a_object.annotations is not null and a_object.annotations.count > 0 then
35+
if a_object.annotations is not null and a_object.annotations.count > 0 then
3636

3737
update /*+ no_parallel */ ut_annotation_cache_info i
3838
set i.parse_time = l_timestamp
@@ -47,16 +47,19 @@ create or replace package body ut_annotation_cache_manager as
4747
values (ut_annotation_cache_seq.nextval, a_object.object_owner, a_object.object_name, a_object.object_type, l_timestamp)
4848
returning cache_id into l_cache_id;
4949
end if;
50+
51+
delete /*+ no_parallel */ from ut_annotation_cache c where cache_id = l_cache_id;
5052

51-
end if;
52-
53-
delete /*+ no_parallel */ from ut_annotation_cache c where cache_id = l_cache_id;
54-
55-
if a_object.annotations is not null and a_object.annotations.count > 0 then
5653
insert /*+ no_parallel */ into ut_annotation_cache
5754
(cache_id, annotation_position, annotation_name, annotation_text, subobject_name)
5855
select /*+ no_parallel */ l_cache_id, a.position, a.name, a.text, a.subobject_name
5956
from table(a_object.annotations) a;
57+
elsif a_object.annotations is null or a_object.annotations.count = 0 then
58+
ut_annotation_cache_manager.remove_from_cache(
59+
ut_annotation_objs_cache_info(
60+
ut_annotation_obj_cache_info(a_object.object_owner, a_object.object_name, a_object.object_type, 'Y', null)
61+
)
62+
);
6063
end if;
6164
commit;
6265
end;

test/ut3_tester/core/test_suite_manager.pkb

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,5 +1466,99 @@ end;]';
14661466
ut.expect(SQLCODE).to_equal(ut3_develop.ut_utils.gc_value_too_large);
14671467
end;
14681468

1469+
procedure setup_remove_annot_test is
1470+
pragma autonomous_transaction;
1471+
begin
1472+
execute immediate q'[create or replace package test_removing_annotation as
1473+
--%suite
1474+
1475+
--%test
1476+
procedure test1;
1477+
1478+
--%test
1479+
procedure test2;
1480+
1481+
end;]';
1482+
end;
1483+
1484+
procedure remove_annot_from_test is
1485+
pragma autonomous_transaction;
1486+
begin
1487+
execute immediate q'[create or replace package test_removing_annotation as
1488+
1489+
procedure test1;
1490+
1491+
procedure test2;
1492+
1493+
end;]';
1494+
end;
1495+
1496+
procedure rem_one_annot_test is
1497+
pragma autonomous_transaction;
1498+
begin
1499+
execute immediate q'[create or replace package test_removing_annotation as
1500+
--%suite
1501+
1502+
procedure test1;
1503+
1504+
--%test
1505+
procedure test2;
1506+
1507+
end;]';
1508+
execute immediate q'[create or replace package body test_removing_annotation as
1509+
1510+
procedure test1 is
1511+
begin
1512+
ut.expect(1).to_equal(1);
1513+
end;
1514+
1515+
procedure test2 is
1516+
begin
1517+
ut.expect(1).to_equal(1);
1518+
end;
1519+
1520+
end;]';
1521+
end;
1522+
1523+
procedure clean_remove_annot_test is
1524+
pragma autonomous_transaction;
1525+
begin
1526+
execute immediate 'drop package test_removing_annotation';
1527+
end;
1528+
1529+
procedure test_rem_cache_on_create is
1530+
l_test_report ut3_develop.ut_varchar2_list;
1531+
begin
1532+
1533+
select * bulk collect into l_test_report from table(ut3_develop.ut.run(sys_context('USERENV', 'CURRENT_USER')||'.test_removing_annotation'));
1534+
1535+
-- drop all tests
1536+
remove_annot_from_test;
1537+
1538+
begin
1539+
select * bulk collect into l_test_report from table(ut3_develop.ut.run(sys_context('USERENV', 'CURRENT_USER') || '.test_removing_annotation'));
1540+
exception
1541+
when others then
1542+
ut.expect(sqlerrm).to_be_like('%ORA-20204: Suite package ut3_tester.test_removing_annotation does not exist%');
1543+
end;
1544+
1545+
end;
1546+
1547+
procedure test_rem_cache_on_crt_anno is
1548+
l_test_report ut3_develop.ut_varchar2_list;
1549+
l_results clob;
1550+
begin
1551+
1552+
select * bulk collect into l_test_report from table(ut3_develop.ut.run(sys_context('USERENV', 'CURRENT_USER')||'.test_removing_annotation'));
1553+
1554+
-- drop single test
1555+
rem_one_annot_test;
1556+
ut3_develop.ut.run(sys_context('USERENV', 'CURRENT_USER')|| '.test_removing_annotation',a_reporter => ut3_develop.ut_documentation_reporter() );
1557+
l_results := ut3_tester_helper.main_helper.get_dbms_output_as_clob();
1558+
--Assert
1559+
ut.expect( l_results ).to_be_like( '%1 tests, 0 failed, 0 errored, 0 disabled, 0 warning(s)%' );
1560+
1561+
end;
1562+
14691563
end test_suite_manager;
14701564
/

test/ut3_tester/core/test_suite_manager.pks

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,21 @@ create or replace package test_suite_manager is
170170
procedure create_dummy_long_test_package;
171171
procedure drop_dummy_long_test_package;
172172

173+
174+
procedure setup_remove_annot_test;
175+
procedure clean_remove_annot_test;
176+
177+
--%test(Remove cache on package create or replace when all annotations removed)
178+
--%beforetest(setup_remove_annot_test)
179+
--%aftertest(clean_remove_annot_test)
180+
procedure test_rem_cache_on_create;
181+
182+
183+
--%test(Remove cache on package create or replace when single annotation removed)
184+
--%beforetest(setup_remove_annot_test)
185+
--%aftertest(clean_remove_annot_test)
186+
procedure test_rem_cache_on_crt_anno;
187+
188+
173189
end test_suite_manager;
174190
/

0 commit comments

Comments
 (0)