blob: 112cb2b55e5af9a4c58a9b2ef76c156995742e6c [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;
ChrisC5e9feb22017-06-21 02:38:57 -070017DELIMITER //
18CREATE PROCEDURE get_template
19 (IN v_template_name VARCHAR(80),
20 OUT v_template_id VARCHAR(36),
21 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070022 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070023 OUT v_template_bpmn_text MEDIUMTEXT,
24 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070025 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070026 OUT v_template_image_text MEDIUMTEXT,
27 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070028 OUT v_template_doc_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070029 OUT v_template_doc_text MEDIUMTEXT)
30BEGIN
31 SELECT t.template_id,
32 tb.template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070033 tb.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070034 tb.template_bpmn_text,
35 ti.template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070036 ti.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070037 ti.template_image_text,
38 td.template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070039 td.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070040 td.template_doc_text
41 INTO v_template_id,
42 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070043 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070044 v_template_bpmn_text,
45 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070046 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070047 v_template_image_text,
48 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070049 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070050 v_template_doc_text
51 FROM template t,
52 template_bpmn tb,
53 template_image ti,
54 template_doc td
55 WHERE t.template_bpmn_id = tb.template_bpmn_id
56 AND t.template_image_id = ti.template_image_id
57 AND t.template_doc_id = td.template_doc_id
58 AND t.template_name = v_template_name;
59END;
60CREATE PROCEDURE set_template
61 (IN v_template_name VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070062 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070063 IN v_template_bpmn_text MEDIUMTEXT,
64 IN v_template_image_text MEDIUMTEXT,
65 IN v_template_doc_text MEDIUMTEXT,
66 OUT v_template_id VARCHAR(36),
67 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070068 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070069 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070070 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -070071 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070072 OUT v_template_doc_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -070073BEGIN
74 DECLARE v_old_template_bpmn_text MEDIUMTEXT;
75 DECLARE v_old_template_image_text MEDIUMTEXT;
76 DECLARE v_old_template_doc_text MEDIUMTEXT;
77 SET v_template_id = NULL;
78 CALL get_template(
79 v_template_name,
80 v_template_id,
81 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070082 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070083 v_old_template_bpmn_text,
84 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070085 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070086 v_old_template_image_text,
87 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -070088 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -070089 v_old_template_doc_text);
90 IF v_template_id IS NULL THEN
91 BEGIN
92 SET v_template_id = UUID();
93 INSERT INTO template
94 (template_id, template_name)
95 VALUES (v_template_id, v_template_name);
96 END;
97 END IF;
98 IF v_template_bpmn_id IS NULL OR v_template_bpmn_text <> v_old_template_bpmn_text THEN
99 SET v_template_bpmn_id = UUID();
100 INSERT INTO template_bpmn
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700101 (template_bpmn_id, template_id, template_bpmn_text, user_id)
102 VALUES (v_template_bpmn_id, v_template_id, v_template_bpmn_text, v_user_id);
103 SET v_template_bpmn_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700104 END IF;
105 IF v_template_image_id IS NULL OR v_template_image_text <> v_old_template_image_text THEN
106 SET v_template_image_id = UUID();
107 INSERT INTO template_image
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700108 (template_image_id, template_id, template_image_text, user_id)
109 VALUES (v_template_image_id, v_template_id, v_template_image_text, v_user_id);
110 SET v_template_image_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700111 END IF;
112 IF v_template_doc_id IS NULL OR v_template_doc_text <> v_old_template_doc_text THEN
113 SET v_template_doc_id = UUID();
114 INSERT INTO template_doc
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700115 (template_doc_id, template_id, template_doc_text, user_id)
116 VALUES (v_template_doc_id, v_template_id, v_template_doc_text, v_user_id);
117 SET v_template_doc_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700118 END IF;
119 UPDATE template
120 SET template_bpmn_id = v_template_bpmn_id,
121 template_image_id = v_template_image_id,
122 template_doc_id = v_template_doc_id
123 WHERE template_id = v_template_id;
124END;
125CREATE PROCEDURE get_model
126 (IN v_model_name VARCHAR(80),
127 OUT v_control_name_prefix VARCHAR(80),
128 INOUT v_control_name_uuid VARCHAR(36),
129 OUT v_model_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700130 OUT v_service_type_id VARCHAR(80),
131 OUT v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700132 OUT v_template_name VARCHAR(80),
133 OUT v_template_id VARCHAR(36),
134 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700135 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700136 OUT v_model_prop_text MEDIUMTEXT,
137 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700138 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700139 OUT v_model_blueprint_text MEDIUMTEXT,
140 OUT v_event_id VARCHAR(36),
141 OUT v_action_cd VARCHAR(80),
142 OUT v_action_state_cd VARCHAR(80),
143 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700144 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700145BEGIN
146 SELECT m.control_name_prefix,
147 m.control_name_uuid,
148 m.model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700149 m.service_type_id,
150 m.deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700151 t.template_name,
152 m.template_id,
153 mp.model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700154 mp.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700155 mp.model_prop_text,
156 mb.model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700157 mb.user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700158 mb.model_blueprint_text,
159 e.event_id,
160 e.action_cd,
161 e.action_state_cd,
162 e.process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700163 e.user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700164 INTO v_control_name_prefix,
165 v_control_name_uuid,
166 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700167 v_service_type_id,
168 v_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700169 v_template_name,
170 v_template_id,
171 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700172 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700173 v_model_prop_text,
174 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700175 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700176 v_model_blueprint_text,
177 v_event_id,
178 v_action_cd,
179 v_action_state_cd,
180 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700181 v_event_user_id
ChrisC5e9feb22017-06-21 02:38:57 -0700182 FROM model m,
183 template t,
184 model_properties mp,
185 model_blueprint mb,
186 event e
187 WHERE m.template_id = t.template_id
188 AND m.model_prop_id = mp.model_prop_id
189 AND m.model_blueprint_id = mb.model_blueprint_id
190 AND m.event_id = e.event_id
191 AND (m.model_name = v_model_name
192 OR m.control_name_uuid = v_control_name_uuid);
193 SELECT model_instance_id,
194 vm_name,
195 location,
196 timestamp
197 FROM model_instance
198 WHERE model_id = v_model_id
199 ORDER BY 2;
200END;
201CREATE PROCEDURE get_model_template
202 (IN v_model_name VARCHAR(80),
203 OUT v_control_name_prefix VARCHAR(80),
204 INOUT v_control_name_uuid VARCHAR(36),
205 OUT v_model_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700206 OUT v_service_type_id VARCHAR(80),
207 OUT v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700208 OUT v_template_name VARCHAR(80),
209 OUT v_template_id VARCHAR(36),
210 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700211 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700212 OUT v_model_prop_text MEDIUMTEXT,
213 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700214 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700215 OUT v_model_blueprint_text MEDIUMTEXT,
216 OUT v_template_bpmn_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700217 OUT v_template_bpmn_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700218 OUT v_template_bpmn_text MEDIUMTEXT,
219 OUT v_template_image_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700220 OUT v_template_image_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700221 OUT v_template_image_text MEDIUMTEXT,
222 OUT v_template_doc_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700223 OUT v_template_doc_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700224 OUT v_template_doc_text MEDIUMTEXT,
225 OUT v_event_id VARCHAR(36),
226 OUT v_action_cd VARCHAR(80),
227 OUT v_action_state_cd VARCHAR(80),
228 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700229 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700230BEGIN
231 CALL get_model(
232 v_model_name,
233 v_control_name_prefix,
234 v_control_name_uuid,
235 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700236 v_service_type_id,
237 v_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700238 v_template_name,
239 v_template_id,
240 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700241 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700242 v_model_prop_text,
243 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700244 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700245 v_model_blueprint_text,
246 v_event_id,
247 v_action_cd,
248 v_action_state_cd,
249 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700250 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700251 CALL get_template(
252 v_template_name,
253 v_template_id,
254 v_template_bpmn_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700255 v_template_bpmn_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700256 v_template_bpmn_text,
257 v_template_image_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700258 v_template_image_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700259 v_template_image_text,
260 v_template_doc_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700261 v_template_doc_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700262 v_template_doc_text);
263 END;
264CREATE PROCEDURE set_model
265 (IN v_model_name VARCHAR(80),
266 IN v_template_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700267 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700268 IN v_model_prop_text MEDIUMTEXT,
269 IN v_model_blueprint_text MEDIUMTEXT,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700270 IN v_service_type_id VARCHAR(80),
271 IN v_deployment_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700272 INOUT v_control_name_prefix VARCHAR(80),
273 INOUT v_control_name_uuid VARCHAR(36),
274 OUT v_model_id VARCHAR(36),
275 OUT v_model_prop_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700276 OUT v_model_prop_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700277 OUT v_model_blueprint_id VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700278 OUT v_model_blueprint_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700279 OUT v_event_id VARCHAR(36),
280 OUT v_action_cd VARCHAR(80),
281 OUT v_action_state_cd VARCHAR(80),
282 OUT v_event_process_instance_id VARCHAR(80),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700283 OUT v_event_user_id VARCHAR(80))
ChrisC5e9feb22017-06-21 02:38:57 -0700284BEGIN
285 DECLARE v_old_template_name VARCHAR(80);
286 DECLARE v_old_template_id VARCHAR(36);
287 DECLARE v_old_control_name_prefix VARCHAR(80);
288 DECLARE v_old_control_name_uuid VARCHAR(36);
289 DECLARE v_old_model_prop_text MEDIUMTEXT;
290 DECLARE v_old_model_blueprint_text MEDIUMTEXT;
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700291 DECLARE v_old_service_type_id VARCHAR(80);
292 DECLARE v_old_deployment_id VARCHAR(80);
ChrisC5e9feb22017-06-21 02:38:57 -0700293 SET v_model_id = NULL;
294 CALL get_model(
295 v_model_name,
296 v_old_control_name_prefix,
297 v_old_control_name_uuid,
298 v_model_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700299 v_old_service_type_id,
300 v_old_deployment_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700301 v_old_template_name,
302 v_old_template_id,
303 v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700304 v_model_prop_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700305 v_old_model_prop_text,
306 v_model_blueprint_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700307 v_model_blueprint_user_id,
ChrisC5e9feb22017-06-21 02:38:57 -0700308 v_old_model_blueprint_text,
309 v_event_id,
310 v_action_cd,
311 v_action_state_cd,
312 v_event_process_instance_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700313 v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700314 IF v_model_id IS NULL THEN
315 BEGIN
316 # UUID can be provided initially but cannot be updated
317 # if not provided (this is expected) then it will be set here
318 IF v_control_name_uuid IS NULL THEN
319 SET v_control_name_uuid = UUID();
320 END IF;
321 SET v_model_id = v_control_name_uuid;
322 INSERT INTO model
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700323 (model_id, model_name, template_id, control_name_prefix, control_name_uuid, service_type_id, deployment_id)
324 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 -0700325 # since just created model, insert CREATED event as initial default event
326 SET v_action_cd = 'CREATE';
327 SET v_action_state_cd = 'COMPLETED';
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700328 SET v_event_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700329 SET v_event_id = UUID();
330 INSERT INTO event
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700331 (event_id, model_id, action_cd, action_state_cd, user_id)
332 VALUES (v_event_id, v_model_id, v_action_cd, v_action_state_cd, v_event_user_id);
ChrisC5e9feb22017-06-21 02:38:57 -0700333 UPDATE model
334 SET event_id = v_event_id
335 WHERE model_id = v_model_id;
336 END;
337 ELSE
338 BEGIN
339 # use old control_name_prefix if null value is provided
340 IF v_control_name_prefix IS NULL THEN
341 SET v_control_name_prefix = v_old_control_name_prefix;
342 END IF;
343 # UUID can not be updated after initial insert
344 SET v_control_name_uuid = v_old_control_name_uuid;
345 END;
346 END IF;
347 IF v_model_prop_id IS NULL OR v_model_prop_text <> v_old_model_prop_text THEN
348 SET v_model_prop_id = UUID();
349 INSERT INTO model_properties
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700350 (model_prop_id, model_id, model_prop_text, user_id)
351 VALUES (v_model_prop_id, v_model_id, v_model_prop_text, v_user_id);
352 SET v_model_prop_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700353 END IF;
354 IF v_model_blueprint_id IS NULL OR v_model_blueprint_text <> v_old_model_blueprint_text THEN
355 SET v_model_blueprint_id = UUID();
356 INSERT INTO model_blueprint
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700357 (model_blueprint_id, model_id, model_blueprint_text, user_id)
358 VALUES (v_model_blueprint_id, v_model_id, v_model_blueprint_text, v_user_id);
359 SET v_model_blueprint_user_id = v_user_id;
ChrisC5e9feb22017-06-21 02:38:57 -0700360 END IF;
361 UPDATE model
362 SET control_name_prefix = v_control_name_prefix,
363 model_prop_id = v_model_prop_id,
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700364 model_blueprint_id = v_model_blueprint_id,
365 service_type_id = v_service_type_id,
366 deployment_id = v_deployment_id
ChrisC5e9feb22017-06-21 02:38:57 -0700367 WHERE model_id = v_model_id;
368END;
369CREATE PROCEDURE ins_model_instance
370 (IN v_control_name_uuid VARCHAR(36),
371 IN v_vm_name VARCHAR(250),
372 IN v_location VARCHAR(250),
373 OUT v_model_id VARCHAR(36),
374 OUT v_model_instance_id VARCHAR(36))
375BEGIN
376 SELECT m.model_id
377 INTO v_model_id
378 FROM model m
379 WHERE m.control_name_uuid = v_control_name_uuid;
380 SET v_model_instance_id = UUID();
381 INSERT INTO model_instance
382 (model_instance_id, model_id, vm_name, location)
383 VALUES (v_model_instance_id, v_model_id, v_vm_name, v_location);
384END;
385CREATE PROCEDURE del_model_instance
386 (IN v_control_name_uuid VARCHAR(36),
387 IN v_vm_name VARCHAR(250),
388 OUT v_model_id VARCHAR(36),
389 OUT v_model_instance_id VARCHAR(36))
390BEGIN
391 SELECT m.model_id, i.model_instance_id
392 INTO v_model_id,
393 v_model_instance_id
394 FROM model m,
395 model_instance i
396 WHERE m.model_id = i.model_id
397 AND m.control_name_uuid = v_control_name_uuid
398 AND i.vm_name = v_vm_name;
399 DELETE FROM model_instance
400 WHERE model_instance_id = v_model_instance_id;
401END;
402CREATE PROCEDURE del_all_model_instances
403 (IN v_control_name_uuid VARCHAR(36),
404 OUT v_model_id VARCHAR(36))
405BEGIN
406 SELECT m.model_id
407 INTO v_model_id
408 FROM model m
409 WHERE m.control_name_uuid = v_control_name_uuid;
410 DELETE FROM model_instance
411 WHERE model_id = v_model_id;
412END;
413CREATE PROCEDURE ins_event
414 (IN v_model_name VARCHAR(80),
415 IN v_control_name_prefix VARCHAR(80),
416 IN v_control_name_uuid VARCHAR(36),
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700417 IN v_user_id VARCHAR(80),
ChrisC5e9feb22017-06-21 02:38:57 -0700418 IN v_action_cd VARCHAR(80),
419 IN v_action_state_cd VARCHAR(80),
420 IN v_process_instance_id VARCHAR(80),
421 OUT v_model_id VARCHAR(36),
422 OUT v_event_id VARCHAR(36))
423BEGIN
424 DECLARE v_prev_event_id VARCHAR(36);
425 SELECT m.model_id,
426 m.event_id
427 INTO v_model_id,
428 v_prev_event_id
429 FROM model m
430 WHERE m.model_name = v_model_name
431 OR m.control_name_uuid = v_control_name_uuid;
432 SET v_event_id = UUID();
433 INSERT INTO event
Determe, Sebastien (sd378r)b3a21f72017-08-08 02:58:27 -0700434 (event_id, model_id, action_cd, action_state_cd, prev_event_id, process_instance_id, user_id)
435 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 -0700436 UPDATE model
437 SET event_id = v_event_id
438 WHERE model_id = v_model_id;
439END;
440CREATE PROCEDURE upd_event
441 (IN v_event_id VARCHAR(36),
442 IN v_process_instance_id VARCHAR(80))
443BEGIN
444 UPDATE event
445 SET process_instance_id = v_process_instance_id
446 WHERE event_id = v_event_id;
447END
448//
449DELIMITER ;