Skip to content

Commit 86d4d0a

Browse files
committed
Initial check-in.
There is still no error handling.
1 parent 8e54e91 commit 86d4d0a

File tree

8 files changed

+354
-63
lines changed

8 files changed

+354
-63
lines changed

source/core/types/ut_path_item.tpb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
create or replace type body ut_path_item as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2021 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+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2) return self as result is
19+
begin
20+
self.schema_name := schema_name;
21+
self.object_name := object_name;
22+
self.procedure_name := procedure_name;
23+
return;
24+
end;
25+
26+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2,suite_path varchar2) return self as result is
27+
begin
28+
self.schema_name := schema_name;
29+
self.suite_path := suite_path;
30+
return;
31+
end;
32+
33+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2,suite_path varchar2) return self as result is
34+
begin
35+
self.schema_name := schema_name;
36+
self.object_name := object_name;
37+
self.procedure_name := procedure_name;
38+
self.suite_path := suite_path;
39+
return;
40+
end;
41+
end;
42+
/

source/core/types/ut_path_item.tps

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
create or replace type ut_path_item as object (
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2021 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+
schema_name varchar2(4000),
19+
object_name varchar2(250),
20+
procedure_name varchar2(250),
21+
suite_path varchar2(4000),
22+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2) return self as result,
23+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2,suite_path varchar2) return self as result,
24+
constructor function ut_path_item(self in out nocopy ut_path_item, schema_name varchar2, object_name varchar2,procedure_name varchar2,suite_path varchar2) return self as result
25+
)
26+
/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
create or replace type ut_path_items as
2+
/*
3+
utPLSQL - Version 3
4+
Copyright 2016 - 2021 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_path_item
19+
/

source/core/ut_suite_cache_manager.pkb

Lines changed: 181 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ create or replace package body ut_suite_cache_manager is
2020
* Private code
2121
*/
2222

23-
gc_get_cache_suite_sql constant varchar2(32767) :=
23+
gc_get_cache_suite_sql constant varchar2(32767) :=
2424
q'[with
2525
suite_items as (
2626
select /*+ cardinality(c 500) */ value(c) as obj
@@ -83,6 +83,87 @@ create or replace package body ut_suite_cache_manager is
8383
from items c
8484
order by c.obj.object_owner,{:random_seed:}]';
8585

86+
87+
gc_get_bulk_cache_suite_sql constant varchar2(32767) :=
88+
q'[with
89+
suite_paths_tabs as (
90+
select schema_name,object_name,procedure_name,suite_path
91+
from table(:l_schema_paths)
92+
),
93+
suite_items as (
94+
select /*+ cardinality(c 500) */ value(c) as obj
95+
from ut_suite_cache c,
96+
suite_paths_tabs sp
97+
where c.object_owner = upper(sp.schema_name)
98+
and sp.suite_path is not null
99+
and (
100+
sp.suite_path||'.' like c.path||'.%' /*all parents and self*/
101+
or
102+
(
103+
c.path||'.' like sp.suite_path||'.%' /*all children and self*/
104+
and c.object_name like nvl(upper(sp.object_name),c.object_name)
105+
and c.name like nvl(upper(sp.procedure_name),c.name)
106+
)
107+
)
108+
union all
109+
select /*+ cardinality(c 500) */ value(c) as obj
110+
from ut_suite_cache c,
111+
suite_paths_tabs sp
112+
where c.object_owner = upper(sp.schema_name)
113+
and sp.suite_path is null
114+
and c.object_name like nvl(upper(replace(sp.object_name,'*','%')),c.object_name)
115+
and c.name like nvl(upper(replace(sp.procedure_name,'*','%')),c.name)
116+
),
117+
{:tags:}
118+
suitepaths as (
119+
select distinct substr(c.obj.path,1,instr(c.obj.path,'.',-1)-1) as suitepath,
120+
c.obj.path as path,
121+
c.obj.object_owner as object_owner
122+
from {:suite_item_name:} c
123+
where c.obj.self_type = 'UT_SUITE'
124+
),
125+
gen as (
126+
select rownum as pos
127+
from xmltable('1 to 20')
128+
),
129+
suitepath_part AS (
130+
select distinct
131+
substr(b.suitepath, 1, instr(b.suitepath || '.', '.', 1, g.pos) -1) as path,
132+
object_owner
133+
from suitepaths b
134+
join gen g
135+
on g.pos <= regexp_count(b.suitepath, '\w+')
136+
),
137+
logical_suite_data as (
138+
select 'UT_LOGICAL_SUITE' as self_type, p.path, p.object_owner,
139+
upper( substr(p.path, instr( p.path, '.', -1 ) + 1 ) ) as object_name,
140+
cast(null as ut_executables) as x,
141+
cast(null as ut_varchar2_rows) as y,
142+
cast(null as ut_executable_test) as z
143+
from suitepath_part p
144+
where p.path
145+
not in (select s.path from suitepaths s)
146+
),
147+
logical_suites as (
148+
select ut_suite_cache_row(
149+
null,
150+
s.self_type, s.path, s.object_owner, s.object_name,
151+
s.object_name, null, null, null, null, 0,null,
152+
ut_varchar2_rows(),
153+
s.x, s.x, s.x, s.x, s.x, s.x,
154+
s.y, null, s.z
155+
) as obj
156+
from logical_suite_data s
157+
),
158+
items as (
159+
select obj from {:suite_item_name:}
160+
union all
161+
select obj from logical_suites
162+
)
163+
select /*+ no_parallel */ c.obj
164+
from items c
165+
order by c.obj.object_owner,{:random_seed:}]';
166+
86167
function get_missing_cache_objects(a_object_owner varchar2) return ut_varchar2_rows is
87168
l_result ut_varchar2_rows;
88169
l_data ut_annotation_objs_cache_info;
@@ -190,6 +271,29 @@ create or replace package body ut_suite_cache_manager is
190271
) desc nulls last'
191272
end;
192273
end;
274+
275+
--Possible move logic to type
276+
function group_paths_by_schema(a_paths ut_varchar2_list) return ut_path_items is
277+
c_package_path_regex constant varchar2(100) := '^([A-Za-z0-9$#_]+)(\.([A-Za-z0-9$#_\*]+))?(\.([A-Za-z0-9$#_\*]+))?$';
278+
l_results ut_path_items := ut_path_items();
279+
l_path_item ut_path_item;
280+
begin
281+
for i in 1 .. a_paths.count loop
282+
l_results.extend;
283+
if a_paths(i) like '%:%' then
284+
l_path_item := ut_path_item(upper(regexp_substr(a_paths(i),'^[^.:]+')),
285+
ltrim(regexp_substr(a_paths(i),'[.:].*$'),':'));
286+
l_results(l_results.last) := l_path_item;
287+
else
288+
l_path_item := ut_path_item(regexp_substr(a_paths(i), c_package_path_regex, subexpression => 1),
289+
regexp_substr(a_paths(i), c_package_path_regex, subexpression => 3),
290+
regexp_substr(a_paths(i), c_package_path_regex, subexpression => 5));
291+
l_results(l_results.last) := l_path_item;
292+
end if;
293+
end loop;
294+
295+
return l_results;
296+
end;
193297

194298

195299

@@ -254,6 +358,82 @@ create or replace package body ut_suite_cache_manager is
254358
using upper(l_object_owner), l_path, l_path, upper(a_object_name), upper(a_procedure_name), l_include_tags, l_include_tags, l_exclude_tags, a_random_seed;
255359
return l_results;
256360
end;
361+
362+
function expand_paths(a_schema_paths ut_path_items) return ut_path_items is
363+
l_schema_paths ut_path_items:= ut_path_items();
364+
begin
365+
with paths_to_expand as (
366+
select /*+ no_parallel */ min(path) as suite_path,sp.schema_name as schema_name,nvl(sp.object_name,c.object_name) as object_name,sp.procedure_name as procedure_name
367+
from ut_suite_cache c,
368+
table(a_schema_paths) sp
369+
where c.object_owner = upper(sp.schema_name)
370+
and c.object_name like nvl(replace(upper(sp.object_name),'*','%'),c.object_name)
371+
and c.name like nvl(replace(upper(sp.procedure_name),'*','%'), c.name)
372+
and sp.suite_path is null
373+
group by sp.schema_name,nvl(sp.object_name,c.object_name),sp.procedure_name
374+
union all
375+
select /*+ no_parallel */ c.path as suite_path,sp.schema_name,sp.object_name,sp.procedure_name as procedure_name
376+
from
377+
ut_suite_cache c,
378+
table(a_schema_paths) sp
379+
where c.object_owner = upper(sp.schema_name)
380+
and sp.suite_path is not null
381+
and instr(sp.suite_path,'*') > 0
382+
and c.path like replace(sp.suite_path,'*','%')
383+
union all
384+
select /*+ no_parallel */ sp.suite_path as suite_path,sp.schema_name,sp.object_name,sp.procedure_name as procedure_name
385+
from table(a_schema_paths) sp
386+
where sp.suite_path is not null
387+
and instr(sp.suite_path,'*') = 0
388+
)
389+
select ut_path_item(schema_name,object_name,procedure_name,suite_path)
390+
bulk collect into l_schema_paths
391+
from paths_to_expand;
392+
return l_schema_paths;
393+
end;
394+
395+
function get_cached_suite_rows(
396+
a_paths ut_varchar2_list,
397+
a_random_seed positive := null,
398+
a_tags ut_varchar2_rows := null
399+
) return ut_suite_cache_rows is
400+
l_results ut_suite_cache_rows := ut_suite_cache_rows();
401+
l_schema_paths ut_path_items;
402+
l_tags ut_varchar2_rows := coalesce(a_tags,ut_varchar2_rows());
403+
l_include_tags ut_varchar2_rows;
404+
l_exclude_tags ut_varchar2_rows;
405+
l_suite_item_name varchar2(20);
406+
l_paths ut_varchar2_rows;
407+
l_schema varchar2(4000);
408+
l_sql varchar2(32767);
409+
begin
410+
select /*+ no_parallel */ column_value
411+
bulk collect into l_include_tags
412+
from table(l_tags)
413+
where column_value not like '-%';
414+
415+
select /*+ no_parallel */ ltrim(column_value,'-')
416+
bulk collect into l_exclude_tags
417+
from table(l_tags)
418+
where column_value like '-%';
419+
420+
l_schema_paths := expand_paths(group_paths_by_schema(a_paths));
421+
--We still need to turn this into qualified SQL name....maybe as part of results ?
422+
l_suite_item_name := case when l_tags.count > 0 then 'suite_items_tags' else 'suite_items' end;
423+
424+
l_sql := gc_get_bulk_cache_suite_sql;
425+
l_sql := replace(l_sql,'{:suite_item_name:}',l_suite_item_name);
426+
l_sql := replace(l_sql,'{:tags:}',get_tags_sql(l_tags.count));
427+
l_sql := replace(l_sql,'{:random_seed:}',get_random_seed_sql(a_random_seed));
428+
ut_event_manager.trigger_event(ut_event_manager.gc_debug, ut_key_anyvalues().put('l_sql',l_sql) );
429+
430+
execute immediate l_sql
431+
bulk collect into l_results
432+
using l_schema_paths, l_include_tags, l_include_tags, l_exclude_tags, a_random_seed;
433+
return l_results;
434+
end;
435+
436+
257437

258438
function get_schema_parse_time(a_schema_name varchar2) return timestamp result_cache is
259439
l_cache_parse_time timestamp;

source/core/ut_suite_cache_manager.pks

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ create or replace package ut_suite_cache_manager authid definer is
5353
a_random_seed positive := null,
5454
a_tags ut_varchar2_rows := null
5555
) return ut_suite_cache_rows;
56+
57+
function get_cached_suite_rows(
58+
a_paths ut_varchar2_list,
59+
a_random_seed positive := null,
60+
a_tags ut_varchar2_rows := null
61+
) return ut_suite_cache_rows;
5662

5763
/*
5864
* Retrieves suite item info rows from cache.

0 commit comments

Comments
 (0)