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

Skip to content

Commit 0213cdc

Browse files
committed
Adding cache for source lines (if exceptions found)
1 parent 547de6e commit 0213cdc

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

source/core/ut_metadata.pkb

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ create or replace package body ut_metadata as
1616
limitations under the License.
1717
*/
1818

19+
type t_cache is table of all_source.text%type;
20+
g_source_cache t_cache;
21+
g_cached_object varchar2(500);
1922
------------------------------
2023
--public definitions
2124

@@ -130,20 +133,29 @@ create or replace package body ut_metadata as
130133
end;
131134

132135
function get_source_definition_line(a_owner varchar2, a_object_name varchar2, a_line_no integer) return varchar2 is
133-
l_line varchar2(4000);
134136
l_cursor sys_refcursor;
135137
l_view_name varchar2(128) := get_dba_view('dba_source');
138+
l_line all_source.text%type;
139+
c_key constant varchar2(500) := a_owner || '.' || a_object_name;
136140
begin
137-
open l_cursor for 'select text from '||l_view_name||q'[ s
138-
where s.owner = :a_owner and s.name = :a_object_name and s.line = :a_line_no
139-
-- skip the declarations, consider only definitions
140-
and s.type not in ('PACKAGE','TYPE')]' using a_owner, a_object_name, a_line_no;
141-
fetch l_cursor into l_line;
142-
close l_cursor;
143-
return ltrim(rtrim( l_line, chr(10) ));
144-
exception
145-
when no_data_found then
146-
return null;
141+
if not nvl(c_key = g_cached_object, false) then
142+
g_cached_object := c_key;
143+
execute immediate
144+
'select trim(text) text
145+
from '||l_view_name||q'[ s
146+
where s.owner = :a_owner
147+
and s.name = :a_object_name
148+
/*skip the declarations, consider only definitions*/
149+
and s.type not in ('PACKAGE', 'TYPE')
150+
order by line]'
151+
bulk collect into g_source_cache
152+
using a_owner, a_object_name;
153+
end if;
154+
155+
if g_source_cache.exists(a_line_no) then
156+
l_line := g_source_cache(a_line_no);
157+
end if;
158+
return l_line;
147159
end;
148160

149161
function get_dba_view(a_view_name varchar2) return varchar2 is

0 commit comments

Comments
 (0)