@@ -15,51 +15,16 @@ create or replace type body ut_data_value_anydata as
1515 See the License for the specific language governing permissions and
1616 limitations under the License.
1717 */
18-
19- member function is_null(a_value in anydata) return number is
20- l_result integer := 0;
21- l_anydata_sql varchar2(4000);
22- begin
23- if a_value is not null and self.compound_type = 'object' then
24- l_anydata_sql := '
25- declare
26- l_data '||self.data_type||';
27- l_value anydata := :a_value;
28- l_status integer;
29- begin
30- l_status := l_value.get'||self.compound_type||'(l_data);
31- :l_data_is_null := case when l_data is null then 1 else 0 end;
32- end;';
33- execute immediate l_anydata_sql using in a_value, out l_result;
34- --TODO : Refactor
35- elsif a_value is not null and self.compound_type = 'collection' then
36- l_anydata_sql := '
37- declare
38- l_data '||self.data_type||';
39- l_value anydata := :a_value;
40- l_status integer;
41- begin
42- l_status := l_value.get'||self.compound_type||'(l_data);
43- :l_data_is_null := case
44- when l_data is null then 1
45- when l_data is empty then 1
46- else 0 end;
47- end;';
48- execute immediate l_anydata_sql using in a_value, out l_result;
49- else
50- l_result := 1;
51- end if;
52- return l_result;
53- end;
5418
5519 overriding member function get_object_info return varchar2 is
5620 begin
5721 return self.data_type || case when self.compound_type = 'collection' then ' [ count = '||self.elements_count||' ]' else null end;
5822 end;
59-
23+
6024 member procedure get_cursor_from_anydata(a_value in anydata, a_refcursor out sys_refcursor) is
6125 l_anydata_sql varchar2(4000);
62-
26+ l_cursor_sql varchar2(2000);
27+
6328 function resolve_name(a_object_name in varchar2) return varchar2 is
6429 l_schema varchar(250);
6530 l_object varchar(250);
@@ -79,7 +44,7 @@ create or replace type body ut_data_value_anydata as
7944 return resolve_name(a_datatype);
8045 end;
8146
82- begin
47+ begin
8348 l_anydata_sql := '
8449 declare
8550 l_data '||self.data_type||';
@@ -98,7 +63,22 @@ create or replace type body ut_data_value_anydata as
9863 end;';
9964 execute immediate l_anydata_sql using in a_value, out a_refcursor;
10065 end;
101-
66+
67+ member function get_extract_path(a_data_value anydata) return varchar2 is
68+ l_path varchar2(10);
69+ begin
70+ if self.compound_type = 'object' then
71+ l_path := '/*/*';
72+ else
73+ case when ut_metadata.has_collection_members(a_data_value) then
74+ l_path := '/*/*';
75+ else
76+ l_path := '/*';
77+ end case;
78+ end if;
79+ return l_path;
80+ end;
81+
10282 member procedure init(self in out nocopy ut_data_value_anydata, a_value anydata) is
10383 l_refcursor sys_refcursor;
10484 l_ctx number;
@@ -107,20 +87,18 @@ create or replace type body ut_data_value_anydata as
10787 l_cursor_number number;
10888
10989 begin
110- self.data_type := case when a_value is not null then lower(a_value.gettypename()) else 'undefined' end ;
90+ self.data_type := ut_metadata.get_anydata_typename(a_value) ;
11191 self.compound_type := get_instance(a_value);
112- self.extract_path := '/*/*' ;
92+ self.is_data_null := ut_metadata.is_anytype_null(a_value,self.compound_type) ;
11393 self.data_id := sys_guid();
11494 self.self_type := $$plsql_unit;
11595 self.cursor_details := ut_cursor_details();
116- self.is_data_null := is_null(a_value);
117- self.elements_count := 0;
118- if not self.is_null() then
119- get_cursor_from_anydata(a_value,l_refcursor);
120- end if;
12196
12297 ut_compound_data_helper.cleanup_diff;
98+
12399 if not self.is_null() then
100+ self.extract_path := get_extract_path(a_value);
101+ get_cursor_from_anydata(a_value,l_refcursor);
124102 if l_refcursor%isopen then
125103 self.elements_count := self.extract_cursor(l_refcursor);
126104 l_cursor_number := dbms_sql.to_cursor_number(l_refcursor);
@@ -174,6 +152,14 @@ create or replace type body ut_data_value_anydata as
174152 l_result := l_result + (self as ut_data_value_refcursor).compare_implementation(a_other,a_match_options,a_inclusion_compare,a_is_negated);
175153 return l_result;
176154 end;
177-
155+
156+ overriding member function is_empty return boolean is
157+ begin
158+ if self.compound_type = 'collection' then
159+ return self.elements_count = 0;
160+ else
161+ raise value_error;
162+ end if;
163+ end;
178164end;
179165/
0 commit comments