Skip to content

Commit

Permalink
Merge pull request #935 from utPLSQL/feature/fix_output_buffer_cleanup
Browse files Browse the repository at this point in the history
Fixed output_buffer purging error.
  • Loading branch information
PhilippSalvisberg committed Jun 12, 2019
2 parents 75d2053 + 5f07682 commit bd14e43
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 344 deletions.
2 changes: 1 addition & 1 deletion source/core/coverage/ut_coverage_helper.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ create or replace package body ut_coverage_helper is
pragma autonomous_transaction;
begin
null;
execute immediate 'truncate table ut_coverage_sources_tmp$';
execute immediate 'truncate table ut_coverage_sources_tmp';
commit;
end;

Expand Down
47 changes: 3 additions & 44 deletions source/core/coverage/ut_coverage_sources_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create global temporary table ut_coverage_sources_tmp$(
create global temporary table ut_coverage_sources_tmp(
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Expand All @@ -21,46 +21,5 @@ create global temporary table ut_coverage_sources_tmp$(
constraint ut_coverage_sources_tmp_pk primary key (owner,name,line)
) on commit preserve rows;

create unique index ut_coverage_sources_tmp_uk on ut_coverage_sources_tmp$ (owner,name,to_be_skipped, line);

declare
ex_nonedition_user exception;
ex_view_doesnt_exist exception;
pragma exception_init(ex_nonedition_user,-42314);
pragma exception_init(ex_view_doesnt_exist,-942);
v_view_source varchar2(32767);
begin
begin
execute immediate 'drop view ut_coverage_sources_tmp';
exception
when ex_view_doesnt_exist then
null;
end;
v_view_source := ' ut_coverage_sources_tmp as
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
select full_name
,owner
,name
,line
,to_be_skipped
,text
from ut_coverage_sources_tmp$';

execute immediate 'create or replace editioning view '||v_view_source;
exception
when ex_nonedition_user then
execute immediate 'create or replace view '||v_view_source;
end;
/
--is this needed?
--create unique index ut_coverage_sources_tmp_uk on ut_coverage_sources_tmp$ (owner,name,to_be_skipped, line);
76 changes: 76 additions & 0 deletions source/core/output_buffers/ut_output_buffer_base.tpb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
create or replace type body ut_output_buffer_base is
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project

Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

member procedure init(self in out nocopy ut_output_buffer_base, a_output_id raw := null, a_self_type varchar2 := null) is
pragma autonomous_transaction;
l_exists int;
begin
cleanup_buffer();
self.self_type := coalesce(a_self_type,self.self_type);
self.output_id := coalesce(a_output_id, self.output_id, sys_guid());
self.start_date := coalesce(self.start_date, sysdate);
self.last_message_id := 0;
select count(*) into l_exists from ut_output_buffer_info_tmp where output_id = self.output_id;
if ( l_exists > 0 ) then
update ut_output_buffer_info_tmp set start_date = self.start_date where output_id = self.output_id;
else
insert into ut_output_buffer_info_tmp(output_id, start_date) values (self.output_id, self.start_date);
end if;
commit;
self.is_closed := 0;
end;

member function get_lines_cursor(a_initial_timeout natural := null, a_timeout_sec natural := null) return sys_refcursor is
l_lines sys_refcursor;
begin
open l_lines for
select text, item_type
from table(self.get_lines(a_initial_timeout, a_timeout_sec));
return l_lines;
end;

member procedure lines_to_dbms_output(self in ut_output_buffer_base, a_initial_timeout natural := null, a_timeout_sec natural := null) is
l_data sys_refcursor;
l_clob clob;
l_item_type varchar2(32767);
l_lines ut_varchar2_list;
begin
l_data := self.get_lines_cursor(a_initial_timeout, a_timeout_sec);
loop
fetch l_data into l_clob, l_item_type;
exit when l_data%notfound;
l_lines := ut_utils.clob_to_table(l_clob);
for i in 1 .. l_lines.count loop
dbms_output.put_line(l_lines(i));
end loop;
end loop;
close l_data;
end;

member procedure cleanup_buffer(self in ut_output_buffer_base, a_retention_time_sec natural := null) is
gc_buffer_retention_sec constant naturaln := coalesce(a_retention_time_sec, 60 * 60 * 24); -- 24 hours
l_retention_days number := gc_buffer_retention_sec / (60 * 60 * 24);
l_max_retention_date date := sysdate - l_retention_days;
pragma autonomous_transaction;
begin
delete from ut_output_buffer_info_tmp i where i.start_date <= l_max_retention_date;
commit;
end;

end;
/
15 changes: 10 additions & 5 deletions source/core/output_buffers/ut_output_buffer_base.tps
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create or replace type ut_output_buffer_base authid definer as object(
create or replace type ut_output_buffer_base force authid definer as object(
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Expand All @@ -17,13 +17,18 @@ create or replace type ut_output_buffer_base authid definer as object(
*/

output_id raw(32),
member procedure init(self in out nocopy ut_output_buffer_base),
is_closed number(1,0),
start_date date,
last_message_id number(38,0),
self_type varchar2(250 byte),
member procedure init(self in out nocopy ut_output_buffer_base, a_output_id raw := null, a_self_type varchar2 := null),
member function get_lines_cursor(a_initial_timeout natural := null, a_timeout_sec natural := null) return sys_refcursor,
member procedure lines_to_dbms_output(self in ut_output_buffer_base, a_initial_timeout natural := null, a_timeout_sec natural := null),
member procedure cleanup_buffer(self in ut_output_buffer_base, a_retention_time_sec natural := null),
not instantiable member procedure close(self in out nocopy ut_output_buffer_base),
not instantiable member procedure send_line(self in out nocopy ut_output_buffer_base, a_text varchar2, a_item_type varchar2 := null),
not instantiable member procedure send_lines(self in out nocopy ut_output_buffer_base, a_text_list ut_varchar2_rows, a_item_type varchar2 := null),
not instantiable member procedure send_clob(self in out nocopy ut_output_buffer_base, a_text clob, a_item_type varchar2 := null),
not instantiable member function get_lines(a_initial_timeout natural := null, a_timeout_sec natural := null) return ut_output_data_rows pipelined,
not instantiable member function get_lines_cursor(a_initial_timeout natural := null, a_timeout_sec natural := null) return sys_refcursor,
not instantiable member procedure lines_to_dbms_output(self in ut_output_buffer_base, a_initial_timeout natural := null, a_timeout_sec natural := null)
not instantiable member function get_lines(a_initial_timeout natural := null, a_timeout_sec natural := null) return ut_output_data_rows pipelined
) not final not instantiable
/
40 changes: 1 addition & 39 deletions source/core/output_buffers/ut_output_buffer_info_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create table ut_output_buffer_info_tmp$(
create table ut_output_buffer_info_tmp(
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Expand All @@ -23,41 +23,3 @@ create table ut_output_buffer_info_tmp$(
) organization index nologging initrans 10
;

-- This is needed to be EBR ready as editioning view can only be created by edition enabled user
declare
ex_nonedition_user exception;
ex_view_doesnt_exist exception;
pragma exception_init(ex_nonedition_user,-42314);
pragma exception_init(ex_view_doesnt_exist,-942);
v_view_source varchar2(32767);
begin
begin
execute immediate 'drop view ut_output_buffer_info_tmp';
exception
when ex_view_doesnt_exist then
null;
end;
v_view_source := ' ut_output_buffer_info_tmp as
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
select output_id
,start_date
from ut_output_buffer_info_tmp$';

execute immediate 'create or replace editioning view '||v_view_source;
exception
when ex_nonedition_user then
execute immediate 'create or replace view '||v_view_source;
end;
/
56 changes: 3 additions & 53 deletions source/core/output_buffers/ut_output_buffer_tmp.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
declare
v_table_sql varchar2(32767);
e_non_assm exception;
pragma exception_init(e_non_assm, -43853);
begin
v_table_sql := 'create table ut_output_buffer_tmp$(
create table ut_output_buffer_tmp(
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Expand Down Expand Up @@ -31,52 +26,7 @@ begin
constraint ut_output_buffer_tmp_ck check(
is_finished = 0 and (text is not null or item_type is not null )
or is_finished = 1 and text is null and item_type is null ),
constraint ut_output_buffer_fk1 foreign key (output_id) references ut_output_buffer_info_tmp$(output_id)
constraint ut_output_buffer_fk foreign key (output_id) references ut_output_buffer_info_tmp(output_id) on delete cascade
) organization index nologging initrans 100
overflow nologging initrans 100
';
execute immediate v_table_sql;
end;
/
overflow nologging initrans 100;

-- This is needed to be EBR ready as editioning view can only be created by edition enabled user
declare
ex_nonedition_user exception;
ex_view_doesnt_exist exception;
pragma exception_init(ex_nonedition_user,-42314);
pragma exception_init(ex_view_doesnt_exist,-942);
v_view_source varchar2(32767);
begin
begin
execute immediate 'drop view ut_output_buffer_tmp';
exception
when ex_view_doesnt_exist then
null;
end;
v_view_source := ' ut_output_buffer_tmp as
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
select output_id
,message_id
,text
,item_type
,is_finished
from ut_output_buffer_tmp$';

execute immediate 'create or replace editioning view '||v_view_source;
exception
when ex_nonedition_user then
execute immediate 'create or replace view '||v_view_source;
end;
/
46 changes: 2 additions & 44 deletions source/core/output_buffers/ut_output_clob_buffer_tmp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare
e_non_assm exception;
pragma exception_init(e_non_assm, -43853);
begin
v_table_sql := 'create table ut_output_clob_buffer_tmp$(
v_table_sql := 'create table ut_output_clob_buffer_tmp(
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Expand Down Expand Up @@ -31,7 +31,7 @@ begin
constraint ut_output_clob_buffer_tmp_ck check(
is_finished = 0 and (text is not null or item_type is not null )
or is_finished = 1 and text is null and item_type is null ),
constraint ut_output_clob_buffer_tmp_fk1 foreign key (output_id) references ut_output_buffer_info_tmp$(output_id)
constraint ut_output_clob_buffer_tmp_fk foreign key (output_id) references ut_output_buffer_info_tmp(output_id) on delete cascade
) nologging initrans 100
';
begin
Expand All @@ -45,45 +45,3 @@ begin
end;
end;
/

-- This is needed to be EBR ready as editioning view can only be created by edition enabled user
declare
ex_nonedition_user exception;
ex_view_doesnt_exist exception;
pragma exception_init(ex_nonedition_user,-42314);
pragma exception_init(ex_view_doesnt_exist,-942);
v_view_source varchar2(32767);
begin
begin
execute immediate 'drop view ut_output_clob_buffer_tmp';
exception
when ex_view_doesnt_exist then
null;
end;
v_view_source := ' ut_output_clob_buffer_tmp as
/*
utPLSQL - Version 3
Copyright 2016 - 2018 utPLSQL Project
Licensed under the Apache License, Version 2.0 (the "License"):
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
select output_id
,message_id
,text
,item_type
,is_finished
from ut_output_clob_buffer_tmp$';

execute immediate 'create or replace editioning view '||v_view_source;
exception
when ex_nonedition_user then
execute immediate 'create or replace view '||v_view_source;
end;
/
Loading

0 comments on commit bd14e43

Please sign in to comment.