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

Skip to content

Commit 890c1d2

Browse files
committed
Refactoring to simplify code
1 parent 7577a95 commit 890c1d2

3 files changed

Lines changed: 20 additions & 37 deletions

File tree

source/expectations/data_values/ut_data_value_refcursor.tpb

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -210,51 +210,40 @@ create or replace type body ut_data_value_refcursor as
210210
return l_result_string;
211211
end;
212212

213-
overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer is
214-
l_result integer := 0;
215-
l_other ut_data_value_refcursor;
216-
begin
217-
if not a_other is of (ut_data_value_refcursor) then
218-
raise value_error;
219-
end if;
220-
221-
l_other := treat(a_other as ut_data_value_refcursor);
222-
--if column names/types are not equal - build a diff of column names and types
223-
if ut_compound_data_helper.columns_hash( self, a_exclude_xpath, a_include_xpath )
224-
!= ut_compound_data_helper.columns_hash( l_other, a_exclude_xpath, a_include_xpath )
225-
then
226-
l_result := 1;
227-
end if;
228-
l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath);
229-
return l_result;
230-
end;
231-
232213
overriding member function compare_implementation (a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean) return integer is
233214
l_result integer := 0;
234215
l_other ut_data_value_refcursor;
235-
l_missing_pk ut_compound_data_helper.tt_missing_pk := ut_compound_data_helper.tt_missing_pk();
216+
function is_pk_missing (a_pk_missing_tab ut_compound_data_helper.tt_missing_pk) return integer is
217+
begin
218+
return case when a_pk_missing_tab.count > 0 then 1 else 0 end;
219+
end;
236220
begin
237221
if not a_other is of (ut_data_value_refcursor) then
238222
raise value_error;
239223
end if;
240224

241225
l_other := treat(a_other as ut_data_value_refcursor);
242226

243-
l_missing_pk := ut_compound_data_helper.is_pk_exists(self.key_info, l_other.key_info, a_exclude_xpath, a_include_xpath,a_join_by_xpath);
244227
--if we join by key and key is missing fail and report error
245-
if a_join_by_xpath is not null and l_missing_pk.count > 0 then
246-
l_result := 1;
247-
return l_result;
228+
if a_join_by_xpath is not null then
229+
l_result := is_pk_missing(ut_compound_data_helper.is_pk_exists(self.key_info, l_other.key_info, a_exclude_xpath, a_include_xpath,a_join_by_xpath));
248230
end if;
249231

250-
--if column names/types are not equal - build a diff of column names and types
251-
if ut_compound_data_helper.columns_hash( self, a_exclude_xpath, a_include_xpath )
252-
!= ut_compound_data_helper.columns_hash( l_other, a_exclude_xpath, a_include_xpath )
253-
then
254-
l_result := 1;
232+
if l_result = 0 then
233+
--if column names/types are not equal - build a diff of column names and types
234+
if ut_compound_data_helper.columns_hash( self, a_exclude_xpath, a_include_xpath )
235+
!= ut_compound_data_helper.columns_hash( l_other, a_exclude_xpath, a_include_xpath )
236+
then
237+
l_result := 1;
238+
end if;
239+
240+
if a_unordered then
241+
l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered);
242+
else
243+
l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath);
244+
end if;
255245
end if;
256246

257-
l_result := l_result + (self as ut_compound_data_value).compare_implementation(a_other, a_exclude_xpath, a_include_xpath, a_join_by_xpath, a_unordered);
258247
return l_result;
259248
end;
260249

source/expectations/data_values/ut_data_value_refcursor.tps

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ create or replace type ut_data_value_refcursor under ut_compound_data_value(
3939
member procedure init(self in out nocopy ut_data_value_refcursor, a_value sys_refcursor),
4040
overriding member function to_string return varchar2,
4141
overriding member function diff( a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean := false ) return varchar2,
42-
overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2) return integer,
4342
overriding member function compare_implementation(a_other ut_data_value, a_exclude_xpath varchar2, a_include_xpath varchar2, a_join_by_xpath varchar2, a_unordered boolean) return integer
44-
4543
)
4644
/

source/expectations/matchers/ut_equal.tpb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,7 @@ create or replace type body ut_equal as
233233
if self.expected is of (ut_data_value_anydata) then
234234
l_result := 0 = treat(self.expected as ut_data_value_anydata).compare_implementation(a_actual, get_exclude_xpath(), get_include_xpath());
235235
elsif self.expected is of (ut_data_value_refcursor) then
236-
if get_unordered then
237-
l_result := 0 = treat(self.expected as ut_data_value_refcursor).compare_implementation(a_actual, get_exclude_xpath(), get_include_xpath(), get_join_by_xpath(), get_unordered());
238-
else
239-
l_result := 0 = treat(self.expected as ut_data_value_refcursor).compare_implementation(a_actual, get_exclude_xpath(), get_include_xpath());
240-
end if;
236+
l_result := 0 = treat(self.expected as ut_data_value_refcursor).compare_implementation(a_actual, get_exclude_xpath(), get_include_xpath(), get_join_by_xpath(), get_unordered());
241237
else
242238
l_result := equal_with_nulls((self.expected = a_actual), a_actual);
243239
end if;

0 commit comments

Comments
 (0)