Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ] 

001 -- Hello emacs, please make this buffer -*- sql -*-
002 -- Andre DOS ANJOS <Andre.dos.Anjos@cern.ch>
003 
004 -- $Author: stelzer $
005 -- $Revision: 1.4 $
006 -- $Date: 2006/10/17 10:03:07 $
007 
008 -- Creates a set of stored procedures that help us to introduce new lines in
009 -- HLT schema, by looking to all the necessary constraints of the operational
010 -- model. 
011 -- WARNING: The user must have the CREATE/ALTER/CALL ROUTINE permissions to 
012 -- create, manage and execute these.
013 
014 -- Oracle annotations (may be very incomplete):
015 -- 1. The drop statement does not have an IF EXISTS clause associated to it in 
016 -- Oracle, you must use something like CREATE OR ALTER FUNCTION...
017 
018 -- 2. Oracle requires the keyword 'in' between the input parameter declaration 
019 -- and the type. For MySQL that is not accepted.
020 
021 -- 3. In the end of the function declaration, Oracle uses 'RETURN' instead of
022 -- 'RETURNS' as used by MySQL
023 
024 -- 4. Oracle needs a 'AS' keyword before the 'BEGIN' keyword starting a
025 -- function body
026 
027 -- 5. Oracle terminates function declarations with the character '/'. So, to
028 -- make MySQL more Oracle friendly we choose the same delimiter. For an Oracle
029 -- insertion you have to comment out the following line, probably.
030 
031 -- 6. If you remove the delimiter clause, remember to reset the occurrences of
032 -- the delimiters along the code
033 
034 -- 7. It is not clear how to declare temporary variables in Oracle. A hint is
035 -- to use the keyword DECLARE to declare all variables in one shot. E.g.:
036 -- DECLARE
037 --   RETVAL number(10) default NULL;
038 --   VERSION number(11,5);
039 -- According to the manual, this has to come before 'BEGIN' keyword.
040 
041 -- 8. WHILE loops should not be ended by END WHILE, but by END LOOP. This
042 -- happens because the correct syntax for while loops in Oracle should be
043 -- something like WHILE <condition> LOOP statements; END LOOP;
044 
045 -- 9. The stopping condition for cursors in Oracle is a bit different then that
046 -- in MySQL. A sentence like 'exit when cursor%NOTFOUND' should be sufficient to
047 -- do the trick in Oracle. MySQL needs a bit more.
048 
049 -- ##########################################################################
050 -- Start of the code
051 -- ##########################################################################
052 
053 -- Makes MySQL ignore the ';' as an end of statement, so we can input
054 -- multi-statement constructions like functions and procedures.
055 -- delimiter /
056 
057 
058 drop table TMP_PAR;
059 drop table TMP_COMP;
060 drop table TMP_FORCE_DLL;
061 drop table TMP_PROP;
062 drop table TMP_SOURCE;
063 drop table TMP_DLL;
064 
065 create table TMP_PAR (
066   ID INTEGER       not null,
067   constraint TMPPAR_ID_PK primary key (ID)
068 );
069 
070 create table TMP_COMP (
071    ID INTEGER       not null,
072    constraint TMPCOMP_ID_PK primary key (ID)
073 );
074 
075 create table TMP_FORCE_DLL (
076   NAME VARCHAR2(50) not null,
077   constraint NAME_PK primary key (NAME)
078 );
079 
080 create table TMP_PROP (
081   ID NUMBER(10) not null,
082   constraint TMPPROP_ID_PK primary key (ID)
083 );
084 
085 create table TMP_SOURCE (
086   ID NUMBER(10) not null,
087   constraint TMPSOURCE_ID_PK primary key (ID)
088 );
089 
090 create table TMP_DLL (
091   ID NUMBER(10) not null,
092   constraint TMPDLL_ID_PK primary key (ID)
093 );
094 
095 
096 -- #####################################
097 -- Stored procedures for job insertion #
098 -- #####################################
099 
100 
101 -- Creates a set of temporary tables needed for the job insertion
102 create or replace procedure HLT_BOOT_SETUP
103 as
104 begin
105     execute immediate 'truncate table TMP_PAR';
106     execute immediate 'truncate table TMP_COMP';
107     execute immediate 'truncate table TMP_FORCE_DLL';
108 end;
109 /
110 
111 -- Destroyes the set of temporary tables needed for the job insertion
112 create or replace procedure HLT_SHUTDOWN_SETUP
113 as
114 begin
115     execute immediate 'truncate table TMP_PAR';
116     execute immediate 'truncate table TMP_COMP';
117     execute immediate 'truncate table TMP_FORCE_DLL';
118 end;
119 /
120 
121 
122 -- Allows the user to insert a property in the HLT_PARAMETER table. This
123 -- function will respect the uniqueness constraint on this table, searching if
124 -- there are no other properties already inserted with the same values for all
125 -- attributes. If the search is successful (there is already a value with 
126 -- *exactly* the same properties) the insertion is cancelled and the identifier
127 -- of such an entry is returned. On the contrary case, a new version of the 
128 -- property is inserted and the identifier of that column is returned instead.
129 create or replace function HLT_INSERT_PARAMETER
130   (NAME in VARCHAR2, OP in VARCHAR2, VALUE in VARCHAR2
131   )
132   return int
133 as
134   RETVAL int default NULL;
135 begin
136   select HPA_ID into RETVAL from HLT_PARAMETER where HPA_NAME = NAME and HPA_OP = OP and HPA_VALUE = VALUE;
137 
138   if RETVAL is null then 
139      insert into HLT_PARAMETER 
140        (HPA_NAME, HPA_OP, HPA_VALUE) values (NAME, OP, VALUE);
141      select HPA_ID into RETVAL from HLT_PARAMETER where 
142        HPA_NAME = NAME and HPA_OP = OP and HPA_VALUE = VALUE;
143   end if;
144   execute immediate 'insert into TMP_PAR (ID) values (RETVAL)';
145   return RETVAL;
146 end;
147 /
148 
149 
150 create or replace function HLT_INSERT_PARAMETER
151   (NAME in VARCHAR2, OP in VARCHAR2, VALUE in VARCHAR2
152   )
153   return INTEGER
154 is
155   RETVAL INTEGER default NULL;
156 begin
157   select HPA_ID into RETVAL from HLT_PARAMETER where HPA_NAME = NAME and HPA_OP = OP and HPA_VALUE = VALUE;
158 
159   if RETVAL is null then 
160     insert into HLT_PARAMETER 
161       (HPA_NAME, HPA_OP, HPA_VALUE) values (NAME, OP, VALUE);
162     select HPA_ID into RETVAL from HLT_PARAMETER where 
163       HPA_NAME = NAME and HPA_OP = OP and HPA_VALUE = VALUE;
164   end if;
165   execute immediate 'insert into TMP_PAR (ID) values (RETVAL)';
166   return(RETVAL);
167 end;
168 /
169 
170 
171 -- Resets the temporary parameter table
172 create or replace procedure HLT_RESET_PARAMETER
173 as
174 begin
175   execute immediate 'truncate table TMP_PAR';
176 end;
177 /
178 
179 
180 
181 
182 -- Returns 0 if I find at least one line in the HLT_CP_TO_PA table that
183 -- contains both identifiers or 1 if not.
184 create or replace function HLT_SEEK_CP2PA (
185   COMP_ID in INTEGER,
186   PAR_ID  in INTEGER
187   ) return INTEGER
188 as
189   TEST INTEGER(10);
190 begin
191   select max(HLT_CP_TO_PA.HCP2PA_ID) into TEST 
192     from HLT_CP_TO_PA where COMP_ID = HLT_CP_TO_PA.HCP2PA_COMPONENT_ID and
193                             HLT_CP_TO_PA.HCP2PA_PARAMETER_ID = PAR_ID;
194   if TEST is not null then 
195     return(1); -- found something
196   end if;
197   return(0); -- didn't find a match
198 end;
199 /              
200 
201 -- Returns the number of parameters a given registered component has.
202 create or replace function HLT_COUNT_CP2PA (COMP_ID INTEGER)
203   return INTEGER
204 as
205   TEST INTEGER(10);
206 begin
207   select count(HLT_CP_TO_PA.HCP2PA_ID) into TEST
208     from HLT_CP_TO_PA where COMP_ID = HLT_CP_TO_PA.HCP2PA_COMPONENT_ID;
209   return(TEST);
210 end;
211 /
212 
213               
214 -- Returns the identifier of a HLT_COMPONENT row that contains the required
215 -- component entry. This entry corresponds to either a newly created entry in
216 -- the table or to one that matches all the required values for the component
217 -- that one wishes to insert, w.r.t. the relationship between the component and
218 -- its properties. This is how it works:
219 -- 1) You insert the properties that you want to have on your component in the
220 -- HLT_PARAMETER table using the HLT_INSERT_PARAMETER function and store, for
221 -- each entry, the row ID returned by that function into a temporary table
222 -- named TMP_PAR that contains a single column named ID that defines all the
223 -- parameter identifiers you have inserted. The single column should also be
224 -- the primary key of this table.
225 -- 2) I'll scan this table to see if I can find an component that already has
226 -- the same relationships, and has the same name/alias. If that is the case,
227 -- I'll not insert the new component, but return its unique ID. Otherwise, I'll
228 -- insert a new component/alias in the HLT_COMPONENT table and build the
229 -- relationships with the required parameters.
230 -- 3) Upon return, this function will truncate the table TMP_PAR so you can
231 -- re-use it immediately
232 create or replace function HLT_INSERT_COMPONENT (NAME VARCHAR2,
233                                       ALIAS VARCHAR2,
234                                       TOPALG INTEGER)
235   return INTEGER
236 as
237   TEST    INTEGER(10) DEFAULT 0;
238   NPAR    INTEGER(10);
239   COMP_ID INTEGER(10);
240   PAR_ID  INTEGER(10);
241   VERSION decimal(11,5);
242 begin
243   execute immediate 'select count(TMP_PAR.ID) into NPAR from TMP_PAR';
244   -- for every version of the given name/alias pair; go backwards
245   -- since it is potentially faster.
246   select max(HLT_COMPONENT.HCP_ID) into COMP_ID from HLT_COMPONENT
247     where HLT_COMPONENT.HCP_NAME = NAME and
248           HLT_COMPONENT.HCP_ALIAS = ALIAS and
249           HLT_COMPONENT.HCP_TOPALG = TOPALG;
250   while COMP_ID is not null
251   loop
252     -- for all rows of TMP_PAR, check if we have a match, accumulates in TEST
253     TEST := 0;
254     execute immediate 'select min(TMP_PAR.ID) into PAR_ID from TMP_PAR';
255     while PAR_ID is not null
256     loop
257       TEST := TEST + HLT_SEEK_CP2PA(COMP_ID,PAR_ID);
258       execute immediate 'select min(TMP_PAR.ID) into PAR_ID from TMP_PAR where TMP_PAR.ID > PAR_ID';
259     end loop;
260     -- if TEST is NPAR and the total number is the same, we get a match
261     if TEST = NPAR and HLT_COUNT_CP2PA(COMP_ID) = NPAR then
262       execute immediate 'delete from TMP_PAR'; -- cleanup
263       execute immediate 'insert into TMP_COMP (ID) values (COMP_ID)';
264       return COMP_ID;
265     end if;
266     -- in the case you get here, you have to continue testing
267     select max(HLT_COMPONENT.HCP_ID) into COMP_ID from HLT_COMPONENT
268       where HLT_COMPONENT.HCP_NAME = NAME and
269             HLT_COMPONENT.HCP_ALIAS = ALIAS and
270             HLT_COMPONENT.HCP_TOPALG = TOPALG and
271             HLT_COMPONENT.HCP_ID < COMP_ID;
272   end loop;
273 
274   -- in the case we get here, all tests have failed and you don't have a
275   -- component that have all the matches you need. Now we proceed like for
276   -- a parameter in HLT_INSERT_PARAMETER() and insert a brand new component
277   -- with all the parameters defined at the TMP_PAR table
278   select max(HLT_COMPONENT.HCP_VERSION) into VERSION from HLT_COMPONENT
279     where HLT_COMPONENT.HCP_NAME = NAME and
280           HLT_COMPONENT.HCP_ALIAS = ALIAS;
281   if VERSION is null then
282     VERSION := 1.0;
283   else
284     VERSION := floor(VERSION) + 1.0;
285   end if;
286   execute immediate 'insert into HLT_COMPONENT (HCP_NAME, HCP_VERSION, HCP_ALIAS, HCP_TOPALG) values
287       (NAME, VERSION, ALIAS, TOPALG)';
288   select max(HCP_ID) into COMP_ID from HLT_COMPONENT where 
289       HCP_VERSION = VERSION and HCP_ALIAS = ALIAS; -- UNIQUE CONSTRAINT
290 
291   -- now we just create all the links in the HLT_CP_TO_PA table
292   execute immediate 'select min(TMP_PAR.ID) into PAR_ID from TMP_PAR';
293   while PAR_ID is not null
294   loop
295     insert into HLT_CP_TO_PA (HCP2PA_COMPONENT_ID, HCP2PA_PARAMETER_ID) values (COMP_ID, PAR_ID);
296     execute immediate 'select min(TMP_PAR.ID) into PAR_ID from TMP_PAR where TMP_PAR.ID > PAR_ID';
297   end loop;
298 
299   -- and return gracefully
300   execute immediate 'delete from TMP_PAR'; -- cleanup
301   execute immediate 'insert into TMP_COMP (ID) values (COMP_ID)';
302   return(COMP_ID);
303 end;
304 /
305 
306 
307 -- Resets the temporary component table
308 create or replace procedure HLT_RESET_COMPONENT
309 is
310 begin
311   delete from TMP_COMP;
312 end;
313 /
314 
315 -- Allows the insertion of DLLs that are supposed to be forced into a setup,
316 -- hidding from the user the names of the temporary tables needed to do that.
317 create or replace procedure HLT_NEW_FORCE_DLL (NAME in VARCHAR2)
318 as
319   RETVAL INTEGER(10);
320 begin
321   insert into TMP_FORCE_DLL (NAME) values (NAME);
322 end;
323 /
324 
325 
326 -- Resets the temporary parameter table
327 create or replace procedure HLT_RESET_FORCE_DLL
328 as
329 begin
330   delete from TMP_FORCE_DLL;
331 end;
332 /
333 
334 -- Returns 0 if I find at least one line in the HLT_ST_TO_CP table that
335 -- contains both identifiers or 1 if not.
336 create or replace function HLT_SEEK_ST2CP (
337   SETUP_ID INTEGER,
338   COMP_ID INTEGER) 
339   return INTEGER
340 as
341   TEST INTEGER(10);
342 begin
343   select max(HLT_ST_TO_CP.HST2CP_ID) into TEST 
344     from HLT_ST_TO_CP where COMP_ID = HLT_ST_TO_CP.HST2CP_COMPONENT_ID and
345                             HLT_ST_TO_CP.HST2CP_SETUP_ID = SETUP_ID;
346   if TEST is not null then 
347     return(1); -- found something
348   end if;
349   return(0); -- didn't find a match
350 end;
351 /
352 
353 -- Returns the number of components in a given setup
354 create or replace function HLT_COUNT_ST2CP (SETUP_ID int)
355   return int
356 as
357   TEST int(10);
358 begin
359   select count(HLT_ST_TO_CP.HST2CP_ID) into TEST 
360     from HLT_ST_TO_CP where HLT_ST_TO_CP.HST2CP_SETUP_ID = SETUP_ID;
361   return(TEST);
362 end;
363 /
364 
365 -- Returns 0 if I find at least one line in the HLT_FORCE_DLL table that 
366 -- points to the setup defined by the first parameter. Returns 1 otherwise.
367 create or replace function HLT_SEEK_ST2FD (
368     SETUP_ID INTEGER,
369     FDLL VARCHAR2)
370   return INTEGER
371 as
372   TEST int(10);
373 begin
374   select max(HLT_FORCE_DLL.HFD_ID) into TEST
375     from HLT_FORCE_DLL where FDLL = HLT_FORCE_DLL.HFD_DLL_NAME and
376                              SETUP_ID = HLT_FORCE_DLL.HFD_SETUP_ID;
377   if TEST is not null then
378     return(1);
379   end if;
380   return(0);
381 end;
382 /
383 
384 -- Counts the number of forced DLLs in a setup
385 create or replace function HLT_COUNT_ST2FD (SETUP_ID INTEGER)
386   return INTEGER
387 as
388   TEST int(10);
389 begin
390   select count(HLT_FORCE_DLL.HFD_ID) into TEST
391     from HLT_FORCE_DLL where SETUP_ID = HLT_FORCE_DLL.HFD_SETUP_ID;
392   return(TEST);
393 end;
394 /
395 
396 -- Returns the identifier of a HLT_SETUP row that contains the required
397 -- setup entry. This entry corresponds to either a newly created entry in
398 -- the table or to one that matches all the required values for the setup
399 -- that one wishes to insert, w.r.t. the relationship between the setup, 
400 -- its components and forced DLL's. This is how it works:
401 -- 1) You insert the components that you want to have on your setup in the
402 -- HLT_COMPONENT table using the HLT_INSERT_COMPONENT function and store, for
403 -- each entry, the row ID returned by that function into a temporary table
404 -- named TMP_COMP that contains a single column named ID that defines all the
405 -- component identifiers you have inserted. The single column should also be
406 -- the primary key of this table. Also, create a temporary table holding the
407 -- names of the forced DLLs you want to have in this setup, in a single
408 -- column. Call it TMP_FORCE_DLL.
409 -- 2) I'll scan these tables to see if I can find a setup that already has
410 -- the same relationships, and has the same name. If that is the case,
411 -- I'll not insert the new setup, but return its unique ID. Otherwise, I'll
412 -- insert a new setup in the HLT_SETUP table and build the relationships
413 -- between this table and its components and equally insert new entries in the
414 -- HLT_FORCE_DLL table pointing to the current setup.
415 -- 3) Upon return, this function will truncate tables TMP_FORCE_DLL and
416 -- TMP_COMP so you can re-use them immediately
417 --
418 -- To-do: For future upgrades one may consider that the TMP_FORCE_DLL table
419 -- does not contain a unique list of DLLs that have to forced, but a complete
420 -- DLL list as removed from the original job. In this scenario, before
421 -- inserting the entries in HLT_FORCE_DLL table, one would have to calculate
422 -- which of those DLLs would not get automatically inserted into the job by the
423 -- usage of the components in the setup. The list of DLLs that would go into the
424 -- HLT_FORCE_DLL table would be the ones in TMP_FORCE_DLL subtracted from the
425 -- ones brought in automatically by the components in the setup.
426 create or replace function HLT_INSERT_SETUP (NAME VARCHAR2) 
427   return int
428 as
429  TEST_COMP int(20) DEFAULT 0;
430  TEST_FDLL int(20) DEFAULT 0;
431  NCOMP     int(10);
432  NFDLL     int(10);
433  SETUP_ID  int(10);
434  COMP_ID   int(10);
435  FDLL      VARCHAR2(50);
436  VERSION   decimal(11,5);
437 begin
438   select count(TMP_COMP.ID) into NCOMP from TMP_COMP;
439   select count(TMP_FORCE_DLL.NAME) into NFDLL from TMP_FORCE_DLL;
440 
441   -- for every version of the given name; go backwards
442   -- since it is potentially faster.
443   select max(HLT_SETUP.HST_ID) into SETUP_ID from HLT_SETUP
444     where HLT_SETUP.HST_NAME = NAME;
445   while SETUP_ID is not null
446   loop
447     -- for all rows of TMP_COMP, check if we have a match, accumulates in TEST
448     TEST_COMP := 0;
449     select min(TMP_COMP.ID) into COMP_ID from TMP_COMP;
450     while COMP_ID is not null
451     loop
452       TEST_COMP := TEST_COMP + HLT_SEEK_ST2CP(SETUP_ID,COMP_ID);
453       select min(TMP_COMP.ID) into COMP_ID from TMP_COMP 
454         where TMP_COMP.ID > COMP_ID;
455     end loop;
456     -- for all rows of TMP_FORCE_DLL, check if we have a match
457     TEST_FDLL := 0;
458     select min(TMP_FORCE_DLL.NAME) into FDLL from TMP_FORCE_DLL;
459     while FDLL is not null
460     loop
461       TEST_FDLL := TEST_FDLL + HLT_SEEK_ST2FD(SETUP_ID,FDLL);
462       select min(TMP_FORCE_DLL.NAME) into FDLL from TMP_FORCE_DLL
463         where TMP_FORCE_DLL.NAME > FDLL;
464     end loop;
465 
466     -- if TESTs fit and the countings are correct, we get a match!, return
467     -- this ID 
468     if NCOMP = TEST_COMP and 
469        NFDLL = TEST_FDLL and 
470        NCOMP = HLT_COUNT_ST2CP(SETUP_ID) and
471        NFDLL = HLT_COUNT_ST2FD(SETUP_ID) then
472       delete from TMP_COMP; -- cleanup
473       delete from TMP_FORCE_DLL; -- cleanup
474       return SETUP_ID;
475     end if;
476 
477     -- in the case you get here, you have to continue testing
478     select max(HLT_SETUP.HST_ID) into SETUP_ID from HLT_SETUP
479       where HLT_SETUP.HST_NAME = NAME and 
480             HLT_SETUP.HST_ID < SETUP_ID; -- get the previous one
481   end loop;
482 
483   -- in the case we get here, all tests have failed and you don't have a
484   -- component that have all the matches you need. Now we proceed like for
485   -- a component in HLT_INSERT_COMPONENT() and insert a brand new setup
486   -- with all the components and forced DLLs defined at the temporary tables
487   select max(HLT_SETUP.HST_VERSION) into VERSION from HLT_SETUP
488     where HLT_SETUP.HST_NAME = NAME;
489 
490   if VERSION is null then
491     VERSION := 1.0;
492   else
493     VERSION := floor(VERSION) + 1.0;
494   end if;
495   insert into HLT_SETUP (HST_NAME, HST_VERSION) values (NAME, VERSION);
496   select max(HST_ID) into SETUP_ID from HLT_SETUP where 
497     HST_VERSION = VERSION and HST_NAME = NAME; -- UNIQUE CONSTRAINT
498 
499   -- now we just create all the links in the HLT_ST_TO_CP table
500   select min(TMP_COMP.ID) into COMP_ID from TMP_COMP;
501   while COMP_ID is not null
502   loop
503     insert into HLT_ST_TO_CP (HST2CP_SETUP_ID, HST2CP_COMPONENT_ID)
504       values (SETUP_ID, COMP_ID);
505     select min(TMP_COMP.ID) into COMP_ID from TMP_COMP 
506       where TMP_COMP.ID > COMP_ID;
507   end loop;
508 
509 
510   -- and the entries in the HLT_FORCE_DLL table.
511   select min(TMP_FORCE_DLL.NAME) into FDLL from TMP_FORCE_DLL;
512   while FDLL is not null
513   loop
514     insert into HLT_FORCE_DLL (HFD_DLL_NAME, HFD_SETUP_ID) values
515       (FDLL, SETUP_ID);
516     select min(TMP_FORCE_DLL.NAME) into FDLL from TMP_FORCE_DLL
517       where TMP_FORCE_DLL.NAME > FDLL;
518   end loop;
519 
520 
521 
522   -- and return gracefully
523   delete from TMP_COMP; -- cleanup
524   delete from TMP_FORCE_DLL; -- cleanup
525   return(SETUP_ID);
526 end;
527 /
528 
529 -- #########################################
530 -- Stored procedures for release insertion #
531 -- #########################################
532 
533 -- Creates a set of temporary tables needed for the release insertion
534 create or replace procedure HLT_BOOT_RELEASE
535 as
536 begin
537   execute immediate 'truncate table TMP_PROP';
538   execute immediate 'truncate table TMP_SOURCE';
539   execute immediate 'truncate table TMP_DLL';
540 
541 end;
542 /
543 
544 -- Destroyes the set of temporary tables needed for the release insertion
545 create or replace procedure HLT_SHUTDOWN_RELEASE
546 as
547 begin
548   execute immediate 'truncate table TMP_PROP';
549   execute immediate 'truncate table TMP_SOURCE';
550   execute immediate 'truncate table TMP_DLL';
551 end;
552 /
553 
554 
555 -- Allows the user to insert a property in the HLT_PROPERTY table. This
556 -- function will respect the uniqueness constraint on this table, searching if
557 -- there are no other properties already inserted with the same values for all
558 -- attributes. If the search is successful (there is already a value with 
559 -- *exactly* the same properties) the insertion is cancelled and the identifier
560 -- of such an entry is returned. On the contrary case, a new version of the 
561 -- property is inserted and the identifier of that column is returned instead.
562 create or replace function HLT_INSERT_PROPERTY (
563     NAME      IN VARCHAR2,
564     PROP_TYPE IN VARCHAR2,
565     VALUE     IN VARCHAR2)
566   return INTEGER
567 as
568   RETVAL  int(10) default NULL;
569   VERSION decimal(11,5);
570 begin
571   select HPY_ID into RETVAL from HLT_PROPERTY where 
572     HPY_NAME = NAME and HPY_TYPE = PROP_TYPE and HPY_VALUE = VALUE;
573 
574   if RETVAL is null then 
575     insert into HLT_PROPERTY 
576       (HPY_NAME, HPY_TYPE, HPY_VALUE) values (NAME, PROP_TYPE, VALUE);
577     select max(HPY_ID) into RETVAL from HLT_PROPERTY where 
578       HPY_NAME = NAME and HPY_TYPE = PROP_TYPE and HPY_VALUE = VALUE;
579   end if;
580   insert into TMP_PROP (ID) values (RETVAL);
581   return(RETVAL);
582 end;
583 /
584 
585 -- Resets the temporary property table
586 create or replace procedure HLT_RESET_PROPERTY
587 as
588 begin
589   execute immediate 'truncate table TMP_PROP';
590 end;
591 /
592 
593 -- Returns 0 if I find at least one line in the HLT_SO_TO_PY table that
594 -- contains both identifiers or 1 if not.
595 create or replace function HLT_SEEK_SO2PY (
596     SOURCE_ID   IN INTEGER,
597     PROPERTY_ID IN INTEGER) 
598   return int
599 as
600   TEST int(10);
601 begin
602   select max(HLT_SO_TO_PY.HSO2PY_ID) into TEST 
603     from HLT_SO_TO_PY where SOURCE_ID = HLT_SO_TO_PY.HSO2PY_SOURCE_ID and
604                             HLT_SO_TO_PY.HSO2PY_PROPERTY_ID = PROPERTY_ID;
605   if TEST is not null then 
606     return(1); -- found something
607   end if;
608   return(0); -- didn't find a match
609 end;
610 /
611 
612 -- Returns the number of properties a given registered source has.
613 create or replace function HLT_COUNT_SO2PY (SOURCE_ID IN INTEGER) 
614   return INTEGER
615 as
616   TEST int(10);
617 begin
618   select count(HLT_SO_TO_PY.HSO2PY_ID) into TEST
619     from HLT_SO_TO_PY where SOURCE_ID = HLT_SO_TO_PY.HSO2PY_SOURCE_ID;
620   return(TEST);
621 end;
622 /
623 
624 -- Returns the identifier of a HLT_SOURCE row that contains the required
625 -- component entry. This entry corresponds to either a newly created entry in
626 -- the table or to one that matches all the required values for the source
627 -- that one wishes to insert, w.r.t. the relationship between the source and
628 -- its properties. This is how it works similarly to HLT_INSERT_COMPONENT()
629 create or replace function HLT_INSERT_SOURCE (
630     NAME VARCHAR2,
631     GAUDI_TYPE VARCHAR2)
632   return INTEGER
633 as
634   TEST      int(10) DEFAULT 0;
635   NPROP     int(10);
636   SOURCE_ID int(10);
637   PROP_ID   int(10);
638 begin
639 
640   execute immediate 'select count(TMP_PROP.ID) into NPROP from TMP_PROP';
641   -- for every version of the given name/alias pair; go backwards
642   -- since it is potentially faster.
643   select max(HLT_SOURCE.HSO_ID) into SOURCE_ID from HLT_SOURCE
644     where HLT_SOURCE.HSO_NAME = NAME and
645           HLT_SOURCE.HSO_GAUDI_TYPE = GAUDI_TYPE;
646   while SOURCE_ID is not null
647   loop
648     -- for all rows of TMP_PROP, check if we have a match, accumulates in TEST
649     TEST := 0;
650     execute immediate 'select min(TMP_PROP.ID) into PROP_ID from TMP_PROP';
651     while PROP_ID is not null
652     loop
653       TEST := TEST + HLT_SEEK_SO2PY(SOURCE_ID,PROP_ID);
654       select min(TMP_PROP.ID) into PROP_ID from TMP_PROP 
655         where TMP_PROP.ID > PROP_ID;
656     end loop;
657     -- if TEST is NPROP and the total number is the same, we get a match
658     if TEST = NPROP and HLT_COUNT_SO2PY(SOURCE_ID) = NPROP then
659       delete from TMP_PROP; -- cleanup
660       insert into TMP_SOURCE (ID) values (SOURCE_ID);
661       return SOURCE_ID;
662     end if;
663     -- in the case you get here, you have to continue testing
664     select max(HLT_SOURCE.HSO_ID) into SOURCE_ID from HLT_SOURCE
665       where HLT_SOURCE.HSO_NAME = NAME and
666             HLT_SOURCE.HSO_GAUDI_TYPE = GAUDI_TYPE and
667             HLT_SOURCE.HSO_ID < SOURCE_ID;
668   end loop;
669 
670   -- in the case we get here, all tests have failed and you don't have a
671   -- source that have all the matches you need. Now we proceed like for
672   -- a property in HLT_INSERT_PROPERTY() and insert a brand new source
673   -- with all the parameters defined at the TMP_PROP table
674   insert into HLT_SOURCE (HSO_NAME, HSO_GAUDI_TYPE) values (NAME, GAUDI_TYPE);
675   select max(HSO_ID) into SOURCE_ID from HLT_SOURCE where 
676     HSO_NAME = NAME and HSO_GAUDI_TYPE = GAUDI_TYPE;
677 
678   -- now we just create all the links in the HLT_SO_TO_PY table
679   select min(TMP_PROP.ID) into PROP_ID from TMP_PROP;
680   while PROP_ID is not null
681   loop
682     insert into HLT_SO_TO_PY (HSO2PY_SOURCE_ID, HSO2PY_PROPERTY_ID)
683       values (SOURCE_ID, PROP_ID);
684     select min(TMP_PROP.ID) into PROP_ID from TMP_PROP 
685       where TMP_PROP.ID > PROP_ID;
686   end loop;
687 
688   -- and return gracefully
689   delete from TMP_PROP; -- cleanup
690   insert into TMP_SOURCE (ID) values (SOURCE_ID);
691   return(SOURCE_ID);
692 end;
693 /
694 
695 -- Resets the temporary source table
696 create or replace procedure HLT_RESET_SOURCE
697 as
698 begin
699   delete from TMP_SOURCE;
700 end;
701 /
702 
703 -- Returns 0 if I find at least one line in the HLT_SO_TO_DL table that
704 -- contains both identifiers or 1 if not.
705 create or replace function HLT_SEEK_SO2DL (
706     DLL_ID    IN INTEGER,
707     SOURCE_ID IN INTEGER)
708   return INTEGER
709 as
710   TEST int(10);
711 begin
712   select max(HLT_SO_TO_DL.HSO2DL_ID) into TEST 
713     from HLT_SO_TO_DL where DLL_ID = HLT_SO_TO_DL.HSO2DL_DLL_ID and
714                             HLT_SO_TO_DL.HSO2DL_SOURCE_ID = SOURCE_ID;
715   if TEST is not null then 
716     return(1); -- found something
717   end if;
718   return(0); -- didn't find a match
719 end;
720 /
721 
722 -- Returns the number of sources a given registered dll has.
723 create or replace function HLT_COUNT_SO2DL (
724     DLL_ID INTEGER) 
725   return INTEGER
726 as
727   TEST int(10);
728 begin
729   select count(HLT_SO_TO_DL.HSO2DL_ID) into TEST
730     from HLT_SO_TO_DL where DLL_ID = HLT_SO_TO_DL.HSO2DL_DLL_ID;
731   return(TEST);
732 end;
733 /
734 
735 -- Returns the identifier of a HLT_DLL row that contains the required
736 -- component entry. This entry corresponds to either a newly created entry in
737 -- the table or to one that matches all the required values for the dll
738 -- that one wishes to insert, w.r.t. the relationship between the dll and
739 -- its properties. This is works similarly to HLT_INSERT_SOURCE().
740 create or replace function HLT_INSERT_DLL (
741     NAME VARCHAR2,
742     PACKAGE VARCHAR2,
743     CMT_VERSION VARCHAR2)
744   return INTEGER
745 as
746   TEST      int(10) DEFAULT 0;
747   NSOURCE   int(10);
748   DLL_ID    int(10);
749   SOURCE_ID int(10);
750 begin
751   select count(TMP_SOURCE.ID) into NSOURCE from TMP_SOURCE;
752 
753   -- the following respects an uniqueness condition, so no loop required!
754   select HLT_DLL.HDL_ID into DLL_ID from HLT_DLL where 
755     HDL_NAME = NAME and HDL_PACKAGE = PACKAGE and HDL_CMT_VERSION = CMT_VERSION;
756   if DLL_ID is not null then
757     -- for all rows of TMP_SOURCE, check if we have a match, accumulates 
758     TEST := 0;
759     select min(TMP_SOURCE.ID) into SOURCE_ID from TMP_SOURCE;
760     while SOURCE_ID is not null
761     loop
762       TEST := TEST + HLT_SEEK_SO2DL(DLL_ID,SOURCE_ID);
763       select min(TMP_SOURCE.ID) into SOURCE_ID from TMP_SOURCE
764         where TMP_SOURCE.ID > SOURCE_ID;
765     end loop;
766     -- if TEST is NSOURCE and the total number is the same, we get a match
767     if TEST = NSOURCE and HLT_COUNT_SO2DL(DLL_ID) = NSOURCE then
768       delete from TMP_SOURCE; -- cleanup
769       insert into TMP_DLL (ID) values (DLL_ID);
770       return DLL_ID;
771     end if;
772   end if;
773 
774   -- in the case we get here, all tests have failed and you don't have a
775   -- dll that have all the matches you need. Now we proceed like for
776   -- a source in HLT_INSERT_SOURCE() and insert a brand new dll
777   -- with all the sources defined at the TMP_SOURCE table
778   insert into HLT_DLL (HDL_NAME, HDL_PACKAGE, HDL_CMT_VERSION)
779     values (NAME, PACKAGE, CMT_VERSION);
780   select HDL_ID into DLL_ID from HLT_DLL where 
781     HDL_NAME = NAME and HDL_PACKAGE = PACKAGE and HDL_CMT_VERSION = CMT_VERSION;
782 
783   -- now we just create all the links in the HLT_SO_TO_DL table
784   select min(TMP_SOURCE.ID) into SOURCE_ID from TMP_SOURCE;
785   while SOURCE_ID is not null
786   loop
787     insert into HLT_SO_TO_DL (HSO2DL_DLL_ID, HSO2DL_SOURCE_ID)
788       values (DLL_ID, SOURCE_ID);
789     select min(TMP_SOURCE.ID) into SOURCE_ID from TMP_SOURCE 
790       where TMP_SOURCE.ID > SOURCE_ID;
791   end loop;
792 
793   -- and return gracefully
794   delete from TMP_SOURCE; -- cleanup
795   insert into TMP_DLL (ID) values (DLL_ID);
796   return(DLL_ID);
797 end;
798 /
799 
800 -- Resets the temporary dll table
801 create or replace procedure HLT_RESET_DLL
802 as
803 begin
804   delete from TMP_DLL;
805 end;
806 /
807 
808 -- Returns 0 if I find at least one line in the HLT_RE_TO_DL table that
809 -- contains both identifiers or 1 if not.
810 create or replace function HLT_SEEK_RE2DL (
811     RELEASE_ID INTEGER,
812     DLL_ID     INTEGER) 
813   return INTEGER
814 as
815   TEST int(10);
816 begin
817   select max(HLT_RE_TO_DL.HRE2DL_ID) into TEST 
818     from HLT_RE_TO_DL where RELEASE_ID = HLT_RE_TO_DL.HRE2DL_RELEASE_ID and
819                             HLT_RE_TO_DL.HRE2DL_DLL_ID = DLL_ID;
820   if TEST is not null then 
821     return(1); -- found something
822   end if;
823   return(0); -- didn't find a match
824 end;
825 /
826 
827 -- Returns the number of dlls a given registered release has.
828 create or replace function HLT_COUNT_RE2DL (RELEASE_ID IN INTEGER)
829   return INTEGER
830 as
831   TEST int(10);
832 begin
833   select count(HLT_RE_TO_DL.HRE2DL_ID) into TEST
834     from HLT_RE_TO_DL where RELEASE_ID = HLT_RE_TO_DL.HRE2DL_RELEASE_ID;
835   return(TEST);
836 end;
837 /
838 
839 -- Returns the identifier of a HLT_RELEASE row that contains the required
840 -- dll entries. This entry corresponds to either a newly created entry in
841 -- the table or to one that matches all the required values for the release
842 -- that one wishes to insert, w.r.t. the relationship between the release and
843 -- its properties. This is works similarly to HLT_INSERT_DLL().
844 create or replace function HLT_INSERT_RELEASE (
845     NAME    IN VARCHAR2,
846     VERSION IN VARCHAR2)
847   return INTEGER
848 as
849   TEST       int(10) DEFAULT 0;
850   NDLL       int(10);
851   RELEASE_ID int(10);
852   DLL_ID     int(10);
853 begin
854   select count(TMP_DLL.ID) into NDLL from TMP_DLL;
855 
856   -- the following respects an uniqueness condition, so no loop required!
857   select HLT_RELEASE.HRE_ID into RELEASE_ID from HLT_RELEASE
858     where HLT_RELEASE.HRE_NAME = NAME and HLT_RELEASE.HRE_VERSION = VERSION;
859 
860   if RELEASE_ID is not null then
861     -- for all rows of TMP_DLL, check if we have a match, accumulates
862     TEST := 0;
863     select min(TMP_DLL.ID) into DLL_ID from TMP_DLL;
864     while DLL_ID is not null
865     loop
866       TEST := TEST + HLT_SEEK_RE2DL(RELEASE_ID,DLL_ID);
867       select min(TMP_DLL.ID) into DLL_ID from TMP_DLL
868         where TMP_DLL.ID > DLL_ID;
869     end loop;
870     -- if TEST is NDLL and the total number is the same, we get a match
871     if TEST = NDLL and HLT_COUNT_RE2DL(RELEASE_ID) = NDLL then
872       delete from TMP_DLL; -- cleanup
873       return RELEASE_ID;
874     end if;
875   end if;
876 
877   -- in the case we get here, all tests have failed and you don't have a
878   -- release that have all the matches you need. Now we proceed like for
879   -- a dll in HLT_INSERT_DLL() and insert a brand new release
880   -- with all the dlls defined at the TMP_DLL table
881   insert into HLT_RELEASE (HRE_NAME, HRE_VERSION) values (NAME, VERSION);
882   select HRE_ID into RELEASE_ID from HLT_RELEASE where 
883     HRE_NAME = NAME and HRE_VERSION = VERSION;
884 
885   -- now we just create all the links in the HLT_RE_TO_DL table
886   select min(TMP_DLL.ID) into DLL_ID from TMP_DLL;
887   while DLL_ID is not null
888   loop
889     insert into HLT_RE_TO_DL (HRE2DL_RELEASE_ID, HRE2DL_DLL_ID)
890       values (RELEASE_ID, DLL_ID);
891     select min(TMP_DLL.ID) into DLL_ID from TMP_DLL 
892       where TMP_DLL.ID > DLL_ID;
893   end loop;
894 
895   -- and return gracefully
896   delete from TMP_DLL; -- cleanup
897   return(RELEASE_ID);
898 end;
899 /
900 
901 --      -- ##########################################
902 --      -- Stored procedures for easeing production #
903 --      -- ##########################################
904 --      
905 --      -- This procedure will prune the TMP_FORCE_DLL table in view of DLL names that 
906 --      -- would get included anyhow with the components selected for a given setup. 
907 --      -- As input you have to specify against which release we are talking about. For
908 --      -- the implementation, we use cursors to simplify the mechanics. It is not 
909 --      -- necessary to look for duplicates since the PK condition of this table is that
910 --      -- names are unique and, therefore, it is impossible to make the system input
911 --      -- duplicates for this feature.
912 --      create or replace procedure PRUNE_FORCE_DLL (
913 --          NAME    IN VARCHAR2,
914 --          VERSION IN VARCHAR2)
915 --      as
916 --        DLL_NAME VARCHAR2(50);
917 --        REMOVE   int(1) default 0;
918 --        DONE     int(1) default 0;
919 --        DLL cursor;
920 --      begin
921 --      
922 --        select HLT_DLL.HDL_NAME into DLL
923 --          from TMP_COMP, HLT_COMPONENT, HLT_SOURCE, HLT_SO_TO_DL, HLT_DLL
924 --          where TMP_COMP.ID = HLT_COMPONENT.HCP_ID and
925 --                HLT_COMPONENT.HCP_NAME = HLT_SOURCE.HSO_NAME and
926 --                HLT_SOURCE.HSO_ID = HLT_SO_TO_DL.HSO2DL_SOURCE_ID and
927 --                HLT_SO_TO_DL.HSO2DL_DLL_ID = HLT_DLL.HDL_ID;
928 --        continue handler for sqlstate '02000' set DONE = 1;
929 --      
930 --        open DLL;
931 --        repeat
932 --          fetch DLL into DLL_NAME;
933 --          select count(TMP_FORCE_DLL.NAME) into REMOVE from TMP_FORCE_DLL
934 --            where TMP_FORCE_DLL.NAME = DLL_NAME;
935 --          if REMOVE > 0 then -- this is to avoid the MySQL specific keyword IGNORE
936 --            delete from TMP_FORCE_DLL where TMP_FORCE_DLL.NAME = DLL_NAME;
937 --          end if;
938 --        until DONE = 1 end repeat;
939 --        close DLL;
940 --      
941 --      end;
942 --      /
943 
944 -- #############################
945 -- Views to help me read stuff #
946 -- #############################
947 
948 -- Reads all parameters of a given component
949 create or replace view HLT_CP_TO_PA_VIEW (
950   HCP_ID,
951   HPA_ID,
952   HPA_NAME,
953   HPA_VALUE,
954   HPA_OP)
955 as
956 select HLT_CP_TO_PA.HCP2PA_COMPONENT_ID,
957        HLT_PARAMETER.HPA_ID,
958        HLT_PARAMETER.HPA_NAME,
959        HLT_PARAMETER.HPA_VALUE,
960        HLT_PARAMETER.HPA_OP
961 from HLT_CP_TO_PA, HLT_PARAMETER 
962 where HLT_CP_TO_PA.HCP2PA_PARAMETER_ID = HLT_PARAMETER.HPA_ID;
963 
964 
965 
966 -- Reads all properties of a given source
967 create or replace view HLT_SO_TO_PY_VIEW (
968   HSO_ID,
969   HPY_ID,
970   HPY_NAME,
971   HPY_VALUE,
972   HPY_TYPE)
973 as
974 select HLT_SO_TO_PY.HSO2PY_SOURCE_ID,
975        HLT_PROPERTY.HPY_ID,
976        HLT_PROPERTY.HPY_NAME,
977        HLT_PROPERTY.HPY_VALUE,
978        HLT_PROPERTY.HPY_TYPE
979 from HLT_SO_TO_PY, HLT_PROPERTY 
980 where HLT_SO_TO_PY.HSO2PY_PROPERTY_ID = HLT_PROPERTY.HPY_ID;
981 
982 
983 
984 -- Generates a view where we get all setups associated with a given
985 -- master key. 
986 create or replace view HLT_MK_TO_SETUP_VIEW (
987   HMT_ID,
988   HST_ID)
989 as
990 select HLT_MASTER_TABLE.HMT_ID, HLT_SETUP.HST_ID
991 from HLT_MASTER_TABLE, -- Defines the trigger-menu to use
992      HLT_TRIGGER_MENU, -- trigger menus
993      HLT_TM_TO_TC, -- trigger-menu  -> trigger-chain
994      HLT_TRIGGER_CHAIN, -- trigger chains
995      HLT_TC_TO_TS, -- trigger-chain -> trigger-signature
996      HLT_TRIGGER_SIGNATURE, -- trigger signatures
997      HLT_TS_TO_TE,  -- trigger-signature  -> trigger-element
998      HLT_TE_TO_CP, -- trigger-elements -> setup
999      HLT_SETUP -- setup
1000 where HLT_MASTER_TABLE.HMT_TRIGGER_MENU_ID is not null and
1001       HLT_MASTER_TABLE.HMT_TRIGGER_MENU_ID = HLT_TRIGGER_MENU.HTM_ID and
1002       HLT_TRIGGER_MENU.HTM_ID = HLT_TM_TO_TC.HTM2TC_TRIGGER_MENU_ID and
1003       HLT_TM_TO_TC.HTM2TC_TRIGGER_CHAIN_ID = HLT_TRIGGER_CHAIN.HTC_ID and
1004       HLT_TRIGGER_CHAIN.HTC_SETUP_ID = HLT_SETUP.HST_ID;

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!