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

Skip to content

Commit 4ec9eb5

Browse files
committed
Reworking annotation cache - not to use cast(Collect()) on dba_source.
Added filtering of dba_source by test containing annotations. Added cardinality hint with scaling. Removed public procedure `config_package` - used only for one unit test. Fixed naming of procedures. Performance improvements on collections.
1 parent 6088c81 commit 4ec9eb5

28 files changed

Lines changed: 671 additions & 491 deletions

development/cleanup.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ drop user ${UT3_USER} cascade;
1515
begin
1616
for i in (
1717
select decode(owner,'PUBLIC','drop public synonym "','drop synonym "'||owner||'"."')|| synonym_name ||'"' drop_orphaned_synonym from dba_synonyms a
18-
where not exists (select null from dba_objects b where a.table_name=b.object_name and a.table_owner=b.owner )
19-
and a.table_owner <> 'SYS'
18+
where not exists (select 1 from dba_objects b where (a.table_name=b.object_name and a.table_owner=b.owner or b.owner='SYS' and a.table_owner=b.object_name) )
19+
and a.table_owner not in ('SYS','SYSTEM')
2020
) loop
21+
dbms_output.put_line(i.drop_orphaned_synonym);
2122
execute immediate i.drop_orphaned_synonym;
2223
end loop;
2324
end;

examples/demo_of_expectations/demo_equal_matcher.sql

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ create or replace package demo_equal_matcher as
3636
-- %displayname(Gives success when comparing null actual to a null expected)
3737
procedure object_compare_null_both_ok;
3838

39-
-- %test
40-
-- %displayname(Gives failure when comparing null actual to a null expected, setting null equal to false)
41-
procedure object_compare_null_both_fail;
42-
4339
-- %test
4440
-- %displayname(Gives failure when comparing identical objects containing different data)
4541
procedure object_compare_different_data;
@@ -94,14 +90,6 @@ create or replace package body demo_equal_matcher as
9490
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected));
9591
end;
9692

97-
procedure object_compare_null_both_fail is
98-
l_expected demo_department;
99-
l_actual demo_department;
100-
begin
101-
ut.expect(anydata.convertObject(l_actual)).to_equal(anydata.convertObject(l_expected),false);
102-
end;
103-
104-
10593
procedure object_compare_different_data is
10694
l_expected demo_department;
10795
l_actual demo_department;

examples/developer_examples/RunExampleTestAnnotationsParsingTimeHugePackage.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ set echo off
66
@@tst_pkg_huge.pks
77

88
declare
9-
l_suite ut_logical_suite;
9+
l_suites ut_suite_items;
1010
begin
11-
l_suite := ut_suite_manager.config_package(a_owner_name => USER,a_object_name => 'TST_PKG_HUGE');
11+
l_suites := ut_suite_manager.configure_execution_by_path(USER||'.TST_PKG_HUGE');
1212
end;
1313
/
1414

old_tests/RunAll.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ begin
328328
'source/core/types',
329329
'source/core/annotations/ut_annotation_parser.pkb',
330330
'source/core/annotations/ut_annotation_parser.pks',
331+
'source/core/annotations/ut_annotation_cache_manager.pkb',
332+
'source/core/annotations/ut_annotation_cache_manager.pks',
331333
'source/core/ut_expectation_processor.pkb',
332334
'source/core/ut_expectation_processor.pks',
333335
'source/core/ut_file_mapper.pkb',

source/core/annotations/ut_annotated_object.tps

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
create type ut_annotated_object as object(
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
218
object_owner varchar2(250),
319
object_name varchar2(250),
420
object_type varchar2(50),
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
create type ut_annotated_objects as table of ut_annotated_object
1+
create type ut_annotated_objects as
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
table of ut_annotated_object
219
/
320

source/core/annotations/ut_annotation.tps

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
create type ut_annotation as object(
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
218
position number(5,0),
319
name varchar2(1000),
420
text varchar2(4000),

source/core/annotations/ut_annotation_cache.sql

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
create table ut_annotation_cache (
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
Licensed under the Apache License, Version 2.0 (the "License"):
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
215
cache_id number(20,0) not null,
316
annotation_position number(5,0) not null,
417
annotation_name varchar2(1000) not null,
518
annotation_text varchar2(4000),
619
subobject_name varchar2(250),
7-
-- subobject_name_not_null varchar2(250) generated always as (nvl(subobject_name,'null')) not null,
820
constraint ut_annotation_cache_pk primary key(cache_id, annotation_position),
9-
-- constraint ut_annotation_cache_pk primary key(cache_id, annotation_position, subobject_name_not_null),
1021
constraint ut_annotation_cache_fk foreign key(cache_id) references ut_annotation_cache_info(cache_id) on delete cascade
1122
);
1223

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
create table ut_annotation_cache_info (
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
Licensed under the Apache License, Version 2.0 (the "License"):
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
215
cache_id number(20,0) not null,
316
object_owner varchar2(250) not null,
417
object_name varchar2(250) not null,
518
object_type varchar2(250) not null,
619
parse_time date not null,
7-
is_annotated varchar2(1) not null,
820
constraint ut_annotation_cache_info_pk primary key(cache_id),
9-
constraint ut_annotation_cache_info_uk unique (object_owner, object_name, object_type),
10-
constraint ut_annotation_cache_info_ck1 check (is_annotated in ('Y','N'))
21+
constraint ut_annotation_cache_info_uk unique (object_owner, object_name, object_type)
1122
) organization index;
1223

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
create or replace package body ut_annotation_cache_manager as
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
25

3-
procedure update_cache(a_object ut_annotated_object, a_cache_id integer) is
4-
l_is_annotated varchar2(1);
5-
v_cache_id integer := a_cache_id;
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
procedure update_cache(a_object ut_annotated_object) is
20+
v_cache_id integer;
621
l_current_schema varchar2(250) := ut_utils.ut_owner;
722
pragma autonomous_transaction;
823
begin
9-
if a_object.annotations is not null and a_object.annotations.count > 0 then
10-
l_is_annotated := 'Y';
11-
else
12-
l_is_annotated := 'N';
13-
end if;
14-
15-
if v_cache_id is not null then
16-
update ut_annotation_cache_info i
17-
set i.parse_time = sysdate,
18-
i.is_annotated = l_is_annotated
19-
where i.cache_id = v_cache_id;
20-
else
24+
update ut_annotation_cache_info i
25+
set i.parse_time = sysdate
26+
where (i.object_owner, i.object_name, i.object_type)
27+
in ((a_object.object_owner, a_object.object_name, a_object.object_type))
28+
returning cache_id into v_cache_id;
29+
if sql%rowcount = 0 then
2130
insert into ut_annotation_cache_info
22-
(cache_id, object_owner, object_name, object_type, parse_time, is_annotated)
23-
values (ut_annotation_cache_seq.nextval, a_object.object_owner, a_object.object_name, a_object.object_type, sysdate, l_is_annotated)
31+
(cache_id, object_owner, object_name, object_type, parse_time)
32+
values (ut_annotation_cache_seq.nextval, a_object.object_owner, a_object.object_name, a_object.object_type, sysdate)
2433
returning cache_id into v_cache_id;
2534
end if;
2635

2736
delete from ut_annotation_cache c
2837
where cache_id = v_cache_id;
2938

30-
if l_is_annotated = 'Y' then
39+
if a_object.annotations is not null and a_object.annotations.count > 0 then
3140
-- begin
3241
insert into ut_annotation_cache
3342
(cache_id, annotation_position, annotation_name, annotation_text, subobject_name)
@@ -43,5 +52,51 @@ create or replace package body ut_annotation_cache_manager as
4352
commit;
4453
end;
4554

46-
end;
55+
56+
procedure cleanup_cache(a_objects ut_annotation_cached_objects) is
57+
pragma autonomous_transaction;
58+
begin
59+
60+
delete from ut_annotation_cache c
61+
where c.cache_id
62+
in (select i.cache_id
63+
from ut_annotation_cache_info i
64+
join table (a_objects) o
65+
using (object_name, object_type, object_owner)
66+
);
67+
68+
merge into ut_annotation_cache_info i
69+
using (select o.object_name, o.object_type, o.object_owner
70+
from table(a_objects) o ) o
71+
on (o.object_name = i.object_name
72+
and o.object_type = i.object_type
73+
and o.object_owner = i.object_owner)
74+
when matched then update set parse_time = sysdate
75+
when not matched then insert
76+
(cache_id, object_owner, object_name, object_type, parse_time)
77+
values (ut_annotation_cache_seq.nextval, o.object_owner, o.object_name, o.object_type, sysdate);
78+
79+
commit;
80+
end;
81+
82+
function get_annotations_for_objects(a_cached_objects ut_annotation_cached_objects) return sys_refcursor is
83+
l_results sys_refcursor;
84+
begin
85+
open l_results for
86+
select ut_annotated_object(
87+
o.object_owner, o.object_name, o.object_type,
88+
cast(
89+
collect(
90+
ut_annotation(
91+
c.annotation_position, c.annotation_name, c.annotation_text, c.subobject_name
92+
) order by c.annotation_position
93+
) as ut_annotations
94+
)
95+
)
96+
from table(a_cached_objects) o
97+
join ut_annotation_cache c on o.cache_id = c.cache_id
98+
group by o.object_owner, o.object_name, o.object_type;
99+
return l_results;
100+
end;
101+
end ut_annotation_cache_manager;
47102
/

0 commit comments

Comments
 (0)