@@ -17,40 +17,42 @@ create or replace package body ut_annotation_cache_manager as
17
17
*/
18
18
19
19
procedure update_cache(a_object ut_annotated_object) is
20
- l_cache_id integer;
21
- l_new_objects_count integer := 0 ;
20
+ l_cache_id integer;
21
+ l_timestamp timestamp := systimestamp ;
22
22
pragma autonomous_transaction;
23
23
begin
24
+ update ut_annotation_cache_schema s
25
+ set s.max_parse_time = l_timestamp
26
+ where s.object_type = a_object.object_type and s.object_owner = a_object.object_owner;
27
+
28
+ if sql%rowcount = 0 then
29
+ insert into ut_annotation_cache_schema s
30
+ (object_owner, object_type, max_parse_time)
31
+ values (a_object.object_owner, a_object.object_type, l_timestamp);
32
+ end if;
33
+
24
34
-- if not in trigger, or object has annotations
25
35
if ora_sysevent is null or a_object.annotations is not null and a_object.annotations.count > 0 then
26
36
27
37
update ut_annotation_cache_info i
28
- set i.parse_time = systimestamp
38
+ set i.parse_time = l_timestamp,
39
+ i.is_annotated = case when a_object.annotations is not empty then 'Y' else 'N' end
29
40
where (i.object_owner, i.object_name, i.object_type)
30
41
in ((a_object.object_owner, a_object.object_name, a_object.object_type))
31
42
returning cache_id into l_cache_id;
32
43
33
44
if sql%rowcount = 0 then
34
45
35
46
insert into ut_annotation_cache_info
36
- (cache_id, object_owner, object_name, object_type, parse_time)
37
- values (ut_annotation_cache_seq.nextval, a_object.object_owner, a_object.object_name, a_object.object_type, systimestamp)
47
+ (cache_id, object_owner, object_name, object_type, parse_time, is_annotated)
48
+ values (ut_annotation_cache_seq.nextval, a_object.object_owner, a_object.object_name, a_object.object_type, l_timestamp,
49
+ case when a_object.annotations is not empty then 'Y' else 'N' end
50
+ )
38
51
returning cache_id into l_cache_id;
39
- l_new_objects_count := 1;
40
52
end if;
41
53
42
54
end if;
43
55
44
- update ut_annotation_cache_schema s
45
- set s.object_count = s.object_count + l_new_objects_count, s.max_parse_time = systimestamp
46
- where s.object_type = a_object.object_type and s.object_owner = a_object.object_owner;
47
-
48
- if sql%rowcount = 0 then
49
- insert into ut_annotation_cache_schema s
50
- (object_owner, object_type, object_count, max_parse_time)
51
- values (a_object.object_owner, a_object.object_type, l_new_objects_count, systimestamp);
52
- end if;
53
-
54
56
delete from ut_annotation_cache c where cache_id = l_cache_id;
55
57
56
58
if a_object.annotations is not null and a_object.annotations.count > 0 then
@@ -63,7 +65,8 @@ create or replace package body ut_annotation_cache_manager as
63
65
end;
64
66
65
67
66
- procedure cleanup_cache(a_objects ut_annotation_objs_cache_info) is
68
+ procedure reset_objects_cache(a_objects ut_annotation_objs_cache_info) is
69
+ l_timestamp timestamp := systimestamp;
67
70
pragma autonomous_transaction;
68
71
begin
69
72
@@ -77,21 +80,39 @@ create or replace package body ut_annotation_cache_manager as
77
80
and o.object_owner = i.object_owner
78
81
);
79
82
83
+ update ut_annotation_cache_schema s
84
+ set s.max_parse_time = l_timestamp
85
+ where (s.object_owner, s.object_type)
86
+ in (
87
+ select o.object_owner, o.object_type
88
+ from table(a_objects) o
89
+ );
90
+
91
+ if sql%rowcount = 0 then
92
+ insert into ut_annotation_cache_schema s
93
+ (object_owner, object_type, max_parse_time)
94
+ select distinct o.object_owner, o.object_type, l_timestamp
95
+ from table(a_objects) o;
96
+ end if;
97
+
80
98
merge into ut_annotation_cache_info i
81
99
using (select o.object_name, o.object_type, o.object_owner
82
100
from table(a_objects) o ) o
83
101
on (o.object_name = i.object_name
84
102
and o.object_type = i.object_type
85
103
and o.object_owner = i.object_owner)
86
- when matched then update set parse_time = systimestamp
104
+ when matched then
105
+ update
106
+ set parse_time = l_timestamp,
107
+ is_annotated = 'N'
87
108
when not matched then insert
88
- (cache_id, object_owner, object_name, object_type, parse_time)
89
- values (ut_annotation_cache_seq.nextval, o.object_owner, o.object_name, o.object_type, systimestamp );
109
+ (cache_id, object_owner, object_name, object_type, parse_time, is_annotated )
110
+ values (ut_annotation_cache_seq.nextval, o.object_owner, o.object_name, o.object_type, l_timestamp, 'N' );
90
111
91
112
commit;
92
113
end;
93
114
94
- function get_annotations_objects_info (a_object_owner varchar2, a_object_type varchar2) return ut_annotation_objs_cache_info is
115
+ function get_cached_objects_list (a_object_owner varchar2, a_object_type varchar2, a_parsed_after timestamp := null ) return ut_annotation_objs_cache_info is
95
116
l_result ut_annotation_objs_cache_info;
96
117
begin
97
118
select ut_annotation_obj_cache_info(
@@ -104,7 +125,8 @@ create or replace package body ut_annotation_cache_manager as
104
125
bulk collect into l_result
105
126
from ut_annotation_cache_info i
106
127
where i.object_owner = a_object_owner
107
- and i.object_type = a_object_type;
128
+ and i.object_type = a_object_type
129
+ and (i.parse_time > a_parsed_after or a_parsed_after is null);
108
130
return l_result;
109
131
end;
110
132
@@ -123,6 +145,16 @@ create or replace package body ut_annotation_cache_manager as
123
145
return l_result;
124
146
end;
125
147
148
+ procedure set_fully_refreshed(a_object_owner varchar2, a_object_type varchar2) is
149
+ pragma autonomous_transaction;
150
+ begin
151
+ update ut_annotation_cache_schema s
152
+ set s.full_refresh_time = s.max_parse_time
153
+ where s.object_owner = a_object_owner
154
+ and s.object_type = a_object_type;
155
+ commit;
156
+ end;
157
+
126
158
procedure remove_from_cache(a_objects ut_annotation_objs_cache_info) is
127
159
pragma autonomous_transaction;
128
160
begin
@@ -138,10 +170,10 @@ create or replace package body ut_annotation_cache_manager as
138
170
commit;
139
171
end;
140
172
141
- function get_annotations_for_objects(a_cached_objects ut_annotation_objs_cache_info, a_parse_time timestamp) return sys_refcursor is
142
- l_results sys_refcursor;
173
+ function get_annotations_parsed_since(a_object_owner varchar2, a_object_type varchar2, a_parsed_after timestamp) return sys_refcursor is
174
+ l_results sys_refcursor;
143
175
begin
144
- open l_results for q'[
176
+ open l_results for
145
177
select ut_annotated_object(
146
178
i.object_owner, i.object_name, i.object_type, i.parse_time,
147
179
cast(
@@ -151,14 +183,12 @@ create or replace package body ut_annotation_cache_manager as
151
183
) order by c.annotation_position
152
184
) as ut_annotations
153
185
)
154
- )
155
- from table(:a_cached_objects) o
156
- join ut_annotation_cache_info i
157
- on o.object_owner = i.object_owner and o.object_name = i.object_name and o.object_type = i.object_type
186
+ ) as annotated_object
187
+ from ut_annotation_cache_info i
158
188
join ut_annotation_cache c on i.cache_id = c.cache_id
159
- where ]'|| case when a_parse_time is null then ':a_parse_date is null' else 'i.parse_time > :a_parse_time' end ||q'[
160
- group by i.object_owner, i.object_name, i.object_type, i.parse_time]'
161
- using a_cached_objects, a_parse_time ;
189
+ where i.object_owner = a_object_owner and i.object_type = a_object_type
190
+ and (i.parse_time > a_parsed_after or a_parsed_after is null)
191
+ group by i.object_owner, i.object_type, i.object_name, i.parse_time ;
162
192
return l_results;
163
193
end;
164
194
@@ -168,35 +198,24 @@ create or replace package body ut_annotation_cache_manager as
168
198
pragma autonomous_transaction;
169
199
begin
170
200
if a_object_owner is null and a_object_type is null then
171
- l_cache_filter := ':a_object_owner is null and :a_object_type is null';
172
- l_filter := l_cache_filter ;
201
+ l_filter := ':a_object_owner is null and :a_object_type is null';
202
+ l_cache_filter := l_filter ;
173
203
else
174
- l_filter :=
175
- case when a_object_owner is null then ':a_object_owner is null' else 'object_owner = :a_object_owner' end || '
176
- and '||case when a_object_type is null then ':a_object_type is null' else 'object_type = :a_object_type' end;
177
- l_cache_filter := ' c.cache_id
178
- in (select i.cache_id
179
- from ut_annotation_cache_info i
180
- where '|| l_filter || '
181
- )';
204
+ l_filter := case when a_object_owner is null then ':a_object_owner is null' else 'object_owner = :a_object_owner' end;
205
+ l_filter := l_filter || ' and ' || case when a_object_type is null then ':a_object_type is null' else 'object_type = :a_object_type' end;
206
+ l_cache_filter := ' c.cache_id in (select i.cache_id from ut_annotation_cache_info i where ' || l_filter || ' )';
182
207
end if;
183
- execute immediate '
184
- delete from ut_annotation_cache c
185
- where '||l_cache_filter
208
+ execute immediate 'delete from ut_annotation_cache c where ' || l_cache_filter
186
209
using a_object_owner, a_object_type;
187
210
188
- execute immediate '
189
- delete from ut_annotation_cache_info i
190
- where ' || l_filter
211
+ execute immediate ' delete from ut_annotation_cache_info i where ' || l_filter
191
212
using a_object_owner, a_object_type;
192
213
193
- execute immediate '
194
- delete from ut_annotation_cache_schema s
195
- where ' || l_filter
214
+ execute immediate ' delete from ut_annotation_cache_schema s where ' || l_filter
196
215
using a_object_owner, a_object_type;
197
216
198
217
commit;
199
218
end;
200
219
201
- end ut_annotation_cache_manager ;
220
+ end;
202
221
/
0 commit comments