DBA Data[Home] [Help]
Skip to content

PROCEDURE: CTXSYS.VALIDATE_INDEX_METADATA

Source


1 procedure validate_index_metadata
2 is
3   tmp         varchar2(500);
4   pos         binary_integer;
5   sec_id      binary_integer;
6   sec_oat_id  binary_integer;
7   sec_name    varchar2(30);
8   sec_tag     varchar2(256);
9   sec_fid     number;
10   sec_visible varchar2(1);
11   sec_dtype   number;
12   sec_opt     varchar2(4);
13   l_objid     binary_integer;
14   l_acnt      binary_integer;
15   l_oat_id    binary_integer;
16   l_noat_id   binary_integer;
17   l_toat_id   binary_integer;
18   rcnt        number;
19 begin
20   for c1 in (select ixv_idx_id, ixv_value, ixv_oat_id, oat_name, driv.rowid
21                from dr$index_value driv, dr$object_attribute
22               where ixv_oat_id = oat_id
23                 and oat_cla_id = DRIOBJ.CLASS_SECTION_GROUP
24                 and ixv_value like '%:%:%') loop
25 
26     -- c1.ixv_value = SECNAME:TAG:FID:VISIBLE[T<datatype>]
27     pos := instr(c1.ixv_value, ':');
28     sec_name := substr(c1.ixv_value, 1, pos - 1);
29     tmp := substr(c1.ixv_value, pos + 1);
30 
31     pos := instr(tmp, ':', -1);
32     sec_opt := substr(tmp, pos + 1);
33     -- sec_opt = VISIBLE[T<datatype>]
34     sec_visible := substr(sec_opt, 1, 1);
35     sec_opt := substr(sec_opt, 2);
36 
37     if ((sec_opt is not null) and (substr(sec_opt,1,1) = 'T')) then
38       sec_opt := substr(sec_opt, 2);
39       if (sec_opt is not null) then
40         sec_dtype := to_number(sec_opt);
41       else
42         sec_dtype := NULL;
43       end if;
44     else
45       sec_dtype := NULL;
46     end if;
47     tmp := substr(tmp, 1, pos -1);
48 
49     -- tmp = TAG:FID
50     pos := instr(tmp, ':', -1);
51     sec_fid := to_number(substr(tmp, pos + 1));
52     tmp := substr(tmp, 1, pos -1);
53 
54     sec_tag := tmp;
55 
56     drixmd.GetIndexObject(c1.ixv_idx_id, DRIOBJ.CLASS_SECTION_GROUP,
57                           l_objid, l_acnt);
58     l_oat_id := dripref.get_oat_id(DRIOBJ.CLASS_SECTION_GROUP, l_objid,
59                                  'SECTION_ATTRIBUTE');
60 
61     l_noat_id := dripref.get_oat_id(DRIOBJ.CLASS_SECTION,
62                                   DRIOBJ.OBJ_BASIC_SECTION, 'SECTION_NAME');
63     l_toat_id := dripref.get_oat_id(DRIOBJ.CLASS_SECTION,
64                                   DRIOBJ.OBJ_BASIC_SECTION, 'TAG');
65     -- If this row is already split into individual attributes
66     -- delete and re-insert to be sure.
67     -- Get section id from name and tag
68     sec_id := 0;
69     for c2 in (select driv1.ixv_sub_group
70                 from dr$index_value driv1, dr$index_value driv2
71                where driv1.ixv_idx_id = c1.ixv_idx_id
72                  and driv1.ixv_idx_id = driv2.ixv_idx_id
73                  and driv1.ixv_oat_id = l_oat_id
74                  and driv1.ixv_oat_id = driv2.ixv_oat_id
75                  and driv1.ixv_sub_oat_id = l_noat_id
76                  and driv2.ixv_sub_oat_id = l_toat_id
77                  and driv1.ixv_value = sec_name
78                  and driv2.ixv_value = sec_tag
79                  and driv1.ixv_sub_group = driv2.ixv_sub_group) loop
80       sec_id := to_number(c2.ixv_sub_group);
81       -- delete section attributes for sec_id
82       delete from dr$index_value where ixv_idx_id = c1.ixv_idx_id
83         and ixv_oat_id = l_oat_id
84         and ixv_sub_group = sec_id;
85       rcnt := sql%rowcount;
86       -- delete section id row for sec_id
87       delete from dr$index_value where ixv_idx_id = c1.ixv_idx_id
88         and ixv_oat_id = c1.ixv_oat_id
89         and ixv_value = to_char(sec_id);
90       -- update ixo_acnt in dr$index_object for section group class
91       update dr$index_object
92          set ixo_acnt = ixo_acnt - rcnt
93        where ixo_cla_id = DRIOBJ.CLASS_SECTION_GROUP
94          and ixo_idx_id = c1.ixv_idx_id;
95     end loop;
96 
97     if (sec_id = 0) then
98       begin
99         select s.sec_id into sec_id from dr$section s
100           where s.sec_name = sec_name and
101                 s.sec_tag = sec_tag and
102                 s.sec_fid = sec_fid;
103       exception
104       --  when no_data_found then
105         when others then
106           sec_id := driutl.genid;
107       end;
108     end if;
109 
110 
111     sec_oat_id := dripref.get_oat_id(DRIOBJ.CLASS_SECTION_GROUP, l_objid,
112                                      upper(c1.oat_name));
113 
114     -- insert section id row
115     insert into dr$index_value
116                            (ixv_idx_id,
117                             ixv_oat_id,
118                             ixv_value)
119                         values
120                            (c1.ixv_idx_id,
121                             sec_oat_id,
122                             sec_id);
123 
124     -- insert section attributes
125     drisgp.IndexSetSectionAttribute(c1.ixv_idx_id, null, sec_id,
126                                     'SECTION_NAME', sec_name);
127     drisgp.IndexSetSectionAttribute(c1.ixv_idx_id, null, sec_id,
128                                     'TAG', sec_tag);
129     drisgp.IndexSetSectionAttribute(c1.ixv_idx_id, null, sec_id,
130                                     'TOKEN_TYPE', sec_fid);
131     drisgp.IndexSetSectionAttribute(c1.ixv_idx_id, null, sec_id,
132                                     'VISIBLE', sec_visible);
133     if (sec_dtype is not null) then
134       drisgp.IndexSetSectionAttribute(c1.ixv_idx_id, null, sec_id,
135                                       'DATATYPE', sec_dtype);
136     end if;
137     -- delete the colon separated row
138     delete from dr$index_value where rowid = c1.rowid;
139   end loop;
140   commit;
141 exception
142   when dr_def.textile_error then
143     drue.raise;
144   when others then
145     drue.text_on_stack(sqlerrm, 'validate_index_metadata');
146     drue.raise;
147 end;