blob: d09d3fc8117dff971aa78c8b52bffe5e80f5cb29 [file] [log] [blame]
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -07001#
ChrisC5e9feb22017-06-21 02:38:57 -07002# CLDS stored procedures
3#
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -07004
ChrisC5e9feb22017-06-21 02:38:57 -07005USE cldsdb4;
6
7DROP PROCEDURE IF EXISTS upd_event;
8DROP PROCEDURE IF EXISTS ins_event;
9DROP PROCEDURE IF EXISTS del_all_model_instances;
10DROP PROCEDURE IF EXISTS del_model_instance;
11DROP PROCEDURE IF EXISTS ins_model_instance;
12DROP PROCEDURE IF EXISTS set_model;
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070013DROP PROCEDURE IF EXISTS get_model;
14DROP PROCEDURE IF EXISTS get_model_template;
ChrisC5e9feb22017-06-21 02:38:57 -070015DROP PROCEDURE IF EXISTS set_template;
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070016DROP PROCEDURE IF EXISTS get_template;
Determe, Sebastien (sd378r)7a58af82018-06-06 13:47:21 +020017DROP PROCEDURE IF EXISTS del_model;
ChrisC5e9feb22017-06-21 02:38:57 -070018DELIMITER //
19CREATE PROCEDURE get_template
20 (IN v_template_name VARCHAR(80),
21 OUT v_template_id VARCHAR(36),
22 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070023 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070024 OUT v_template_bpmn_text MEDIUMTEXT,
25 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070026 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070027 OUT v_template_image_text MEDIUMTEXT,
28 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070029 OUT v_template_doc_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070030 OUT v_template_doc_text MEDIUMTEXT)
31BEGIN
32 SELECT t.template_id,
33 tb.template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070034 tb.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070035 tb.template_bpmn_text,
36 ti.template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070037 ti.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070038 ti.template_image_text,
39 td.template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070040 td.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070041 td.template_doc_text
42 INTO v_template_id,
43 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070044 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070045 v_template_bpmn_text,
46 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070047 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070048 v_template_image_text,
49 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070050 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070051 v_template_doc_text
52 FROM template t,
53 template_bpmn tb,
54 template_image ti,
55 template_doc td
56 WHERE t.template_bpmn_id = tb.template_bpmn_id
57 AND t.template_image_id = ti.template_image_id
58 AND t.template_doc_id = td.template_doc_id
59 AND t.template_name = v_template_name;
60END;
61CREATE PROCEDURE set_template
62 (IN v_template_name VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070063 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070064 IN v_template_bpmn_text MEDIUMTEXT,
65 IN v_template_image_text MEDIUMTEXT,
66 IN v_template_doc_text MEDIUMTEXT,
67 OUT v_template_id VARCHAR(36),
68 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070069 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070070 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070071 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070072 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070073 OUT v_template_doc_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -070074BEGIN
75 DECLARE v_old_template_bpmn_text MEDIUMTEXT;
76 DECLARE v_old_template_image_text MEDIUMTEXT;
77 DECLARE v_old_template_doc_text MEDIUMTEXT;
78 SET v_template_id = NULL;
79 CALL get_template(
80 v_template_name,
81 v_template_id,
82 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070083 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070084 v_old_template_bpmn_text,
85 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070086 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070087 v_old_template_image_text,
88 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070089 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070090 v_old_template_doc_text);
91 IF v_template_id IS NULL THEN
92 BEGIN
93 SET v_template_id = UUID();
94 INSERT INTO template
95 (template_id, template_name)
96 VALUES (v_template_id, v_template_name);
97 END;
98 END IF;
99 IF v_template_bpmn_id IS NULL OR v_template_bpmn_text <> v_old_template_bpmn_text THEN
100 SET v_template_bpmn_id = UUID();
101 INSERT INTO template_bpmn
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700102 (template_bpmn_id, template_id, template_bpmn_text, user_id)
103 VALUES (v_template_bpmn_id, v_template_id, v_template_bpmn_text, v_user_id);
104 SET v_template_bpmn_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700105 END IF;
106 IF v_template_image_id IS NULL OR v_template_image_text <> v_old_template_image_text THEN
107 SET v_template_image_id = UUID();
108 INSERT INTO template_image
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700109 (template_image_id, template_id, template_image_text, user_id)
110 VALUES (v_template_image_id, v_template_id, v_template_image_text, v_user_id);
111 SET v_template_image_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700112 END IF;
113 IF v_template_doc_id IS NULL OR v_template_doc_text <> v_old_template_doc_text THEN
114 SET v_template_doc_id = UUID();
115 INSERT INTO template_doc
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700116 (template_doc_id, template_id, template_doc_text, user_id)
117 VALUES (v_template_doc_id, v_template_id, v_template_doc_text, v_user_id);
118 SET v_template_doc_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700119 END IF;
120 UPDATE template
121 SET template_bpmn_id = v_template_bpmn_id,
122 template_image_id = v_template_image_id,
123 template_doc_id = v_template_doc_id
124 WHERE template_id = v_template_id;
125END;
126CREATE PROCEDURE get_model
127 (IN v_model_name VARCHAR(80),
128 OUT v_control_name_prefix VARCHAR(80),
129 INOUT v_control_name_uuid VARCHAR(36),
130 OUT v_model_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700131 OUT v_service_type_id VARCHAR(80),
132 OUT v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700133 OUT v_template_name VARCHAR(80),
134 OUT v_template_id VARCHAR(36),
135 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700136 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700137 OUT v_model_prop_text MEDIUMTEXT,
138 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700139 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700140 OUT v_model_blueprint_text MEDIUMTEXT,
141 OUT v_event_id VARCHAR(36),
142 OUT v_action_cd VARCHAR(80),
143 OUT v_action_state_cd VARCHAR(80),
144 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700145 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700146BEGIN
147 SELECT m.control_name_prefix,
148 m.control_name_uuid,
149 m.model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700150 m.service_type_id,
151 m.deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700152 t.template_name,
153 m.template_id,
154 mp.model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700155 mp.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700156 mp.model_prop_text,
157 mb.model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700158 mb.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700159 mb.model_blueprint_text,
160 e.event_id,
161 e.action_cd,
162 e.action_state_cd,
163 e.process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700164 e.user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700165 INTO v_control_name_prefix,
166 v_control_name_uuid,
167 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700168 v_service_type_id,
169 v_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700170 v_template_name,
171 v_template_id,
172 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700173 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700174 v_model_prop_text,
175 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700176 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700177 v_model_blueprint_text,
178 v_event_id,
179 v_action_cd,
180 v_action_state_cd,
181 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700182 v_event_user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700183 FROM model m,
184 template t,
185 model_properties mp,
186 model_blueprint mb,
187 event e
188 WHERE m.template_id = t.template_id
189 AND m.model_prop_id = mp.model_prop_id
190 AND m.model_blueprint_id = mb.model_blueprint_id
191 AND m.event_id = e.event_id
192 AND (m.model_name = v_model_name
193 OR m.control_name_uuid = v_control_name_uuid);
194 SELECT model_instance_id,
195 vm_name,
196 location,
197 timestamp
198 FROM model_instance
199 WHERE model_id = v_model_id
200 ORDER BY 2;
201END;
202CREATE PROCEDURE get_model_template
203 (IN v_model_name VARCHAR(80),
204 OUT v_control_name_prefix VARCHAR(80),
205 INOUT v_control_name_uuid VARCHAR(36),
206 OUT v_model_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700207 OUT v_service_type_id VARCHAR(80),
208 OUT v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700209 OUT v_template_name VARCHAR(80),
210 OUT v_template_id VARCHAR(36),
211 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700212 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700213 OUT v_model_prop_text MEDIUMTEXT,
214 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700215 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700216 OUT v_model_blueprint_text MEDIUMTEXT,
217 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700218 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700219 OUT v_template_bpmn_text MEDIUMTEXT,
220 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700221 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700222 OUT v_template_image_text MEDIUMTEXT,
223 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700224 OUT v_template_doc_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700225 OUT v_template_doc_text MEDIUMTEXT,
226 OUT v_event_id VARCHAR(36),
227 OUT v_action_cd VARCHAR(80),
228 OUT v_action_state_cd VARCHAR(80),
229 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700230 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700231BEGIN
232 CALL get_model(
233 v_model_name,
234 v_control_name_prefix,
235 v_control_name_uuid,
236 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700237 v_service_type_id,
238 v_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700239 v_template_name,
240 v_template_id,
241 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700242 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700243 v_model_prop_text,
244 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700245 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700246 v_model_blueprint_text,
247 v_event_id,
248 v_action_cd,
249 v_action_state_cd,
250 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700251 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700252 CALL get_template(
253 v_template_name,
254 v_template_id,
255 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700256 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700257 v_template_bpmn_text,
258 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700259 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700260 v_template_image_text,
261 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700262 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700263 v_template_doc_text);
264 END;
265CREATE PROCEDURE set_model
266 (IN v_model_name VARCHAR(80),
267 IN v_template_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700268 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700269 IN v_model_prop_text MEDIUMTEXT,
270 IN v_model_blueprint_text MEDIUMTEXT,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700271 IN v_service_type_id VARCHAR(80),
272 IN v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700273 INOUT v_control_name_prefix VARCHAR(80),
274 INOUT v_control_name_uuid VARCHAR(36),
275 OUT v_model_id VARCHAR(36),
276 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700277 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700278 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700279 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700280 OUT v_event_id VARCHAR(36),
281 OUT v_action_cd VARCHAR(80),
282 OUT v_action_state_cd VARCHAR(80),
283 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700284 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700285BEGIN
286 DECLARE v_old_template_name VARCHAR(80);
287 DECLARE v_old_template_id VARCHAR(36);
288 DECLARE v_old_control_name_prefix VARCHAR(80);
289 DECLARE v_old_control_name_uuid VARCHAR(36);
290 DECLARE v_old_model_prop_text MEDIUMTEXT;
291 DECLARE v_old_model_blueprint_text MEDIUMTEXT;
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700292 DECLARE v_old_service_type_id VARCHAR(80);
293 DECLARE v_old_deployment_id VARCHAR(80);
ChrisC5e9feb22017-06-21 02:38:57 -0700294 SET v_model_id = NULL;
295 CALL get_model(
296 v_model_name,
297 v_old_control_name_prefix,
298 v_old_control_name_uuid,
299 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700300 v_old_service_type_id,
301 v_old_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700302 v_old_template_name,
303 v_old_template_id,
304 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700305 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700306 v_old_model_prop_text,
307 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700308 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700309 v_old_model_blueprint_text,
310 v_event_id,
311 v_action_cd,
312 v_action_state_cd,
313 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700314 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700315 IF v_model_id IS NULL THEN
316 BEGIN
317 # UUID can be provided initially but cannot be updated
318 # if not provided (this is expected) then it will be set here
319 IF v_control_name_uuid IS NULL THEN
320 SET v_control_name_uuid = UUID();
321 END IF;
322 SET v_model_id = v_control_name_uuid;
323 INSERT INTO model
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700324 (model_id, model_name, template_id, control_name_prefix, control_name_uuid, service_type_id, deployment_id)
325 VALUES (v_model_id, v_model_name, v_template_id, v_control_name_prefix, v_control_name_uuid, v_service_type_id, v_deployment_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700326 # since just created model, insert CREATED event as initial default event
327 SET v_action_cd = 'CREATE';
328 SET v_action_state_cd = 'COMPLETED';
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700329 SET v_event_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700330 SET v_event_id = UUID();
331 INSERT INTO event
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700332 (event_id, model_id, action_cd, action_state_cd, user_id)
333 VALUES (v_event_id, v_model_id, v_action_cd, v_action_state_cd, v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700334 UPDATE model
335 SET event_id = v_event_id
336 WHERE model_id = v_model_id;
337 END;
338 ELSE
339 BEGIN
340 # use old control_name_prefix if null value is provided
341 IF v_control_name_prefix IS NULL THEN
342 SET v_control_name_prefix = v_old_control_name_prefix;
343 END IF;
344 # UUID can not be updated after initial insert
345 SET v_control_name_uuid = v_old_control_name_uuid;
346 END;
347 END IF;
348 IF v_model_prop_id IS NULL OR v_model_prop_text <> v_old_model_prop_text THEN
349 SET v_model_prop_id = UUID();
350 INSERT INTO model_properties
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700351 (model_prop_id, model_id, model_prop_text, user_id)
352 VALUES (v_model_prop_id, v_model_id, v_model_prop_text, v_user_id);
353 SET v_model_prop_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700354 END IF;
355 IF v_model_blueprint_id IS NULL OR v_model_blueprint_text <> v_old_model_blueprint_text THEN
356 SET v_model_blueprint_id = UUID();
357 INSERT INTO model_blueprint
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700358 (model_blueprint_id, model_id, model_blueprint_text, user_id)
359 VALUES (v_model_blueprint_id, v_model_id, v_model_blueprint_text, v_user_id);
360 SET v_model_blueprint_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700361 END IF;
362 UPDATE model
363 SET control_name_prefix = v_control_name_prefix,
364 model_prop_id = v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700365 model_blueprint_id = v_model_blueprint_id,
366 service_type_id = v_service_type_id,
367 deployment_id = v_deployment_id
ChrisC5e9feb22017-06-21 02:38:57 -0700368 WHERE model_id = v_model_id;
369END;
370CREATE PROCEDURE ins_model_instance
371 (IN v_control_name_uuid VARCHAR(36),
372 IN v_vm_name VARCHAR(250),
373 IN v_location VARCHAR(250),
374 OUT v_model_id VARCHAR(36),
375 OUT v_model_instance_id VARCHAR(36))
376BEGIN
377 SELECT m.model_id
378 INTO v_model_id
379 FROM model m
380 WHERE m.control_name_uuid = v_control_name_uuid;
381 SET v_model_instance_id = UUID();
382 INSERT INTO model_instance
383 (model_instance_id, model_id, vm_name, location)
384 VALUES (v_model_instance_id, v_model_id, v_vm_name, v_location);
385END;
386CREATE PROCEDURE del_model_instance
387 (IN v_control_name_uuid VARCHAR(36),
388 IN v_vm_name VARCHAR(250),
389 OUT v_model_id VARCHAR(36),
390 OUT v_model_instance_id VARCHAR(36))
391BEGIN
392 SELECT m.model_id, i.model_instance_id
393 INTO v_model_id,
394 v_model_instance_id
395 FROM model m,
396 model_instance i
397 WHERE m.model_id = i.model_id
398 AND m.control_name_uuid = v_control_name_uuid
399 AND i.vm_name = v_vm_name;
400 DELETE FROM model_instance
401 WHERE model_instance_id = v_model_instance_id;
402END;
403CREATE PROCEDURE del_all_model_instances
404 (IN v_control_name_uuid VARCHAR(36),
405 OUT v_model_id VARCHAR(36))
406BEGIN
407 SELECT m.model_id
408 INTO v_model_id
409 FROM model m
410 WHERE m.control_name_uuid = v_control_name_uuid;
411 DELETE FROM model_instance
412 WHERE model_id = v_model_id;
413END;
414CREATE PROCEDURE ins_event
415 (IN v_model_name VARCHAR(80),
416 IN v_control_name_prefix VARCHAR(80),
417 IN v_control_name_uuid VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700418 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700419 IN v_action_cd VARCHAR(80),
420 IN v_action_state_cd VARCHAR(80),
421 IN v_process_instance_id VARCHAR(80),
422 OUT v_model_id VARCHAR(36),
423 OUT v_event_id VARCHAR(36))
424BEGIN
425 DECLARE v_prev_event_id VARCHAR(36);
426 SELECT m.model_id,
427 m.event_id
428 INTO v_model_id,
429 v_prev_event_id
430 FROM model m
431 WHERE m.model_name = v_model_name
432 OR m.control_name_uuid = v_control_name_uuid;
433 SET v_event_id = UUID();
434 INSERT INTO event
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700435 (event_id, model_id, action_cd, action_state_cd, prev_event_id, process_instance_id, user_id)
436 VALUES (v_event_id, v_model_id, v_action_cd, v_action_state_cd, v_prev_event_id, v_process_instance_id, v_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700437 UPDATE model
438 SET event_id = v_event_id
439 WHERE model_id = v_model_id;
440END;
441CREATE PROCEDURE upd_event
442 (IN v_event_id VARCHAR(36),
443 IN v_process_instance_id VARCHAR(80))
444BEGIN
445 UPDATE event
446 SET process_instance_id = v_process_instance_id
447 WHERE event_id = v_event_id;
Determe, Sebastien (sd378r)7a58af82018-06-06 13:47:21 +0200448END;
449CREATE PROCEDURE del_model (IN v_model_name VARCHAR(80))
450BEGIN
451 DECLARE v_model_id VARCHAR(36);
452 SELECT model_id INTO v_model_id from model where model_name = v_model_name;
453 UPDATE model set event_id = null, model_blueprint_id = null, model_prop_id = null where model_id = v_model_id;
454 DELETE from event where model_id = v_model_id;
455 DELETE from model_blueprint where model_id = v_model_id;
456 DELETE from model_properties where model_id = v_model_id;
457 DELETE from model where model_id = v_model_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700458END
459//
460DELIMITER ;