Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6f04558

Browse files
authored
Merge pull request #620 from utPLSQL/feature/improve_cache_purging
Improved annotation cache purging and updated documentation
2 parents bd9a201 + 9ac345a commit 6f04558

5 files changed

Lines changed: 36 additions & 16 deletions

File tree

development/cleanup.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ git rev-parse && cd "$(git rev-parse --show-cdup)"
77

88
"${SQLCLI}" sys/${ORACLE_PWD}@//${CONNECTION_STR} AS SYSDBA <<-SQL
99
set echo on
10+
begin
11+
for x in (
12+
select * from dba_objects
13+
where owner in ( upper('${UT3_RELEASE_VERSION_SCHEMA}'), upper('${UT3_OWNER}') )
14+
and object_name like 'SYS_PLSQL%')
15+
loop
16+
execute immediate 'drop type '||x.owner||'.'||x.object_name||' force';
17+
end loop;
18+
end;
19+
/
20+
1021
drop user ${UT3_OWNER} cascade;
1122
drop user ${UT3_RELEASE_VERSION_SCHEMA} cascade;
1223
drop user ${UT3_TESTER} cascade;

docs/userguide/annotations.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ Example:
269269
exec ut_runner.rebuild_annotation_cache('HR');
270270
```
271271

272-
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner)`.
272+
To purge the annotation cache call `ut_runner.purge_cache(a_object_owner, a_object_type)`.
273+
Both parameters are optional and if not provided, all owners/object_types will be purged.
273274
Example:
274275
```sql
275276
exec ut_runner.purge_cache('HR', 'PACKAGE');

source/api/ut_runner.pkb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ create or replace package body ut_runner is
113113
ut_annotation_manager.rebuild_annotation_cache(a_object_owner, coalesce(a_object_type,'PACKAGE'));
114114
end;
115115

116-
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2 := null) is
116+
procedure purge_cache(a_object_owner varchar2 := null, a_object_type varchar2 := null) is
117117
begin
118-
ut_annotation_manager.purge_cache(a_object_owner, coalesce(a_object_type,'PACKAGE'));
118+
ut_annotation_manager.purge_cache(a_object_owner, a_object_type);
119119
end;
120120

121121
function get_unit_test_info(a_owner varchar2, a_package_name varchar2 := null) return tt_annotations pipelined is

source/api/ut_runner.pks

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ create or replace package ut_runner authid current_user is
7474
/**
7575
* Removes cached information about annotations for objects of specified type and specified owner
7676
*
77-
* @param a_object_owner owner of objects to purge annotations for
78-
* @param a_object_type optional type of objects to purge annotations for (defaults to 'PACKAGE')
77+
* @param a_object_owner optional - owner of objects to purge annotations for. If null (default) then all schemas are purged
78+
* @param a_object_type optional - type of objects to purge annotations for. If null (default) then cache for all object types is purged
7979
*/
80-
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2 := null);
80+
procedure purge_cache(a_object_owner varchar2 := null, a_object_type varchar2 := null);
8181

8282

8383
type t_annotation_rec is record (

source/core/annotations/ut_annotation_cache_manager.pkb

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,31 @@ create or replace package body ut_annotation_cache_manager as
104104
end;
105105

106106
procedure purge_cache(a_object_owner varchar2, a_object_type varchar2) is
107+
l_filter varchar2(32767);
108+
l_cache_filter varchar2(32767);
107109
pragma autonomous_transaction;
108110
begin
111+
if a_object_owner is null and a_object_type is null then
112+
l_cache_filter := ':a_object_owner is null and :a_object_type is null';
113+
l_filter := l_cache_filter;
114+
else
115+
l_filter :=
116+
case when a_object_owner is null then ':a_object_owner is null' else 'object_owner = :a_object_owner' end || '
117+
and '||case when a_object_type is null then ':a_object_type is null' else 'object_type = :a_object_type' end;
118+
l_cache_filter := ' c.cache_id
119+
in (select i.cache_id
120+
from ut_annotation_cache_info i
121+
where '|| l_filter || '
122+
)';
123+
end if;
109124
execute immediate '
110125
delete from ut_annotation_cache c
111-
where c.cache_id
112-
in (select i.cache_id
113-
from ut_annotation_cache_info i
114-
where 1 = 1
115-
and '||case when a_object_owner is null then ':a_object_owner is null' else 'object_owner = :a_object_owner' end || '
116-
and '||case when a_object_type is null then ':a_object_type is null' else 'object_type = :a_object_type' end || '
117-
)'
126+
where '||l_cache_filter
118127
using a_object_owner, a_object_type;
128+
119129
execute immediate '
120130
delete from ut_annotation_cache_info i
121-
where 1 = 1
122-
and '||case when a_object_owner is null then ':a_object_owner is null' else 'object_owner = :a_object_owner' end || '
123-
and '||case when a_object_type is null then ':a_object_type is null' else 'object_type = :a_object_type' end
131+
where ' || l_filter
124132
using a_object_owner, a_object_type;
125133
commit;
126134
end;

0 commit comments

Comments
 (0)