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