Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 1 | # |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 2 | # CLDS stored procedures |
| 3 | # |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 4 | |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 5 | USE cldsdb4; |
| 6 | |
| 7 | DROP PROCEDURE IF EXISTS upd_event; |
| 8 | DROP PROCEDURE IF EXISTS ins_event; |
| 9 | DROP PROCEDURE IF EXISTS del_all_model_instances; |
| 10 | DROP PROCEDURE IF EXISTS del_model_instance; |
| 11 | DROP PROCEDURE IF EXISTS ins_model_instance; |
| 12 | DROP PROCEDURE IF EXISTS set_model; |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 13 | DROP PROCEDURE IF EXISTS get_model; |
| 14 | DROP PROCEDURE IF EXISTS get_model_template; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 15 | DROP PROCEDURE IF EXISTS set_template; |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 16 | DROP PROCEDURE IF EXISTS get_template; |
Determe, Sebastien (sd378r) | 7a58af8 | 2018-06-06 13:47:21 +0200 | [diff] [blame^] | 17 | DROP PROCEDURE IF EXISTS del_model; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 18 | DELIMITER // |
| 19 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 23 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 24 | OUT v_template_bpmn_text MEDIUMTEXT, |
| 25 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 26 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 27 | OUT v_template_image_text MEDIUMTEXT, |
| 28 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 29 | OUT v_template_doc_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 30 | OUT v_template_doc_text MEDIUMTEXT) |
| 31 | BEGIN |
| 32 | SELECT t.template_id, |
| 33 | tb.template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 34 | tb.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 35 | tb.template_bpmn_text, |
| 36 | ti.template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 37 | ti.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 38 | ti.template_image_text, |
| 39 | td.template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 40 | td.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 41 | td.template_doc_text |
| 42 | INTO v_template_id, |
| 43 | v_template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 44 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 45 | v_template_bpmn_text, |
| 46 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 47 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 48 | v_template_image_text, |
| 49 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 50 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 51 | 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; |
| 60 | END; |
| 61 | CREATE PROCEDURE set_template |
| 62 | (IN v_template_name VARCHAR(80), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 63 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 64 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 69 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 70 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 71 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 72 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 73 | OUT v_template_doc_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 74 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 83 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 84 | v_old_template_bpmn_text, |
| 85 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 86 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 87 | v_old_template_image_text, |
| 88 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 89 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 90 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 102 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 105 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 109 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 112 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 116 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 119 | 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; |
| 125 | END; |
| 126 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 131 | OUT v_service_type_id VARCHAR(80), |
| 132 | OUT v_deployment_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 133 | OUT v_template_name VARCHAR(80), |
| 134 | OUT v_template_id VARCHAR(36), |
| 135 | OUT v_model_prop_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 136 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 137 | OUT v_model_prop_text MEDIUMTEXT, |
| 138 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 139 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 140 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 145 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 146 | BEGIN |
| 147 | SELECT m.control_name_prefix, |
| 148 | m.control_name_uuid, |
| 149 | m.model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 150 | m.service_type_id, |
| 151 | m.deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 152 | t.template_name, |
| 153 | m.template_id, |
| 154 | mp.model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 155 | mp.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 156 | mp.model_prop_text, |
| 157 | mb.model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 158 | mb.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 159 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 164 | e.user_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 165 | INTO v_control_name_prefix, |
| 166 | v_control_name_uuid, |
| 167 | v_model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 168 | v_service_type_id, |
| 169 | v_deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 170 | v_template_name, |
| 171 | v_template_id, |
| 172 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 173 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 174 | v_model_prop_text, |
| 175 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 176 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 177 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 182 | v_event_user_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 183 | 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; |
| 201 | END; |
| 202 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 207 | OUT v_service_type_id VARCHAR(80), |
| 208 | OUT v_deployment_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 209 | OUT v_template_name VARCHAR(80), |
| 210 | OUT v_template_id VARCHAR(36), |
| 211 | OUT v_model_prop_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 212 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 213 | OUT v_model_prop_text MEDIUMTEXT, |
| 214 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 215 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 216 | OUT v_model_blueprint_text MEDIUMTEXT, |
| 217 | OUT v_template_bpmn_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 218 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 219 | OUT v_template_bpmn_text MEDIUMTEXT, |
| 220 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 221 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 222 | OUT v_template_image_text MEDIUMTEXT, |
| 223 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 224 | OUT v_template_doc_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 225 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 230 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 231 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 237 | v_service_type_id, |
| 238 | v_deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 239 | v_template_name, |
| 240 | v_template_id, |
| 241 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 242 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 243 | v_model_prop_text, |
| 244 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 245 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 246 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 251 | v_event_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 252 | CALL get_template( |
| 253 | v_template_name, |
| 254 | v_template_id, |
| 255 | v_template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 256 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 257 | v_template_bpmn_text, |
| 258 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 259 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 260 | v_template_image_text, |
| 261 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 262 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 263 | v_template_doc_text); |
| 264 | END; |
| 265 | CREATE PROCEDURE set_model |
| 266 | (IN v_model_name VARCHAR(80), |
| 267 | IN v_template_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 268 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 269 | IN v_model_prop_text MEDIUMTEXT, |
| 270 | IN v_model_blueprint_text MEDIUMTEXT, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 271 | IN v_service_type_id VARCHAR(80), |
| 272 | IN v_deployment_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 273 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 277 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 278 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 279 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 280 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 284 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 285 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 292 | DECLARE v_old_service_type_id VARCHAR(80); |
| 293 | DECLARE v_old_deployment_id VARCHAR(80); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 294 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 300 | v_old_service_type_id, |
| 301 | v_old_deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 302 | v_old_template_name, |
| 303 | v_old_template_id, |
| 304 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 305 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 306 | v_old_model_prop_text, |
| 307 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 308 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 309 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 314 | v_event_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 315 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 324 | (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); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 326 | # 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 329 | SET v_event_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 330 | SET v_event_id = UUID(); |
| 331 | INSERT INTO event |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 332 | (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); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 334 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 351 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 354 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 358 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 361 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 365 | model_blueprint_id = v_model_blueprint_id, |
| 366 | service_type_id = v_service_type_id, |
| 367 | deployment_id = v_deployment_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 368 | WHERE model_id = v_model_id; |
| 369 | END; |
| 370 | CREATE 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)) |
| 376 | BEGIN |
| 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); |
| 385 | END; |
| 386 | CREATE 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)) |
| 391 | BEGIN |
| 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; |
| 402 | END; |
| 403 | CREATE PROCEDURE del_all_model_instances |
| 404 | (IN v_control_name_uuid VARCHAR(36), |
| 405 | OUT v_model_id VARCHAR(36)) |
| 406 | BEGIN |
| 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; |
| 413 | END; |
| 414 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 418 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 419 | 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)) |
| 424 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 435 | (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); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 437 | UPDATE model |
| 438 | SET event_id = v_event_id |
| 439 | WHERE model_id = v_model_id; |
| 440 | END; |
| 441 | CREATE PROCEDURE upd_event |
| 442 | (IN v_event_id VARCHAR(36), |
| 443 | IN v_process_instance_id VARCHAR(80)) |
| 444 | BEGIN |
| 445 | UPDATE event |
| 446 | SET process_instance_id = v_process_instance_id |
| 447 | WHERE event_id = v_event_id; |
Determe, Sebastien (sd378r) | 7a58af8 | 2018-06-06 13:47:21 +0200 | [diff] [blame^] | 448 | END; |
| 449 | CREATE PROCEDURE del_model (IN v_model_name VARCHAR(80)) |
| 450 | BEGIN |
| 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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 458 | END |
| 459 | // |
| 460 | DELIMITER ; |