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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 17 | DELIMITER // |
| 18 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 22 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 23 | OUT v_template_bpmn_text MEDIUMTEXT, |
| 24 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 25 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 26 | OUT v_template_image_text MEDIUMTEXT, |
| 27 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 28 | OUT v_template_doc_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 29 | OUT v_template_doc_text MEDIUMTEXT) |
| 30 | BEGIN |
| 31 | SELECT t.template_id, |
| 32 | tb.template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 33 | tb.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 34 | tb.template_bpmn_text, |
| 35 | ti.template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 36 | ti.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 37 | ti.template_image_text, |
| 38 | td.template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 39 | td.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 40 | td.template_doc_text |
| 41 | INTO v_template_id, |
| 42 | v_template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 43 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 44 | v_template_bpmn_text, |
| 45 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 46 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 47 | v_template_image_text, |
| 48 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 49 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 50 | 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; |
| 59 | END; |
| 60 | CREATE PROCEDURE set_template |
| 61 | (IN v_template_name VARCHAR(80), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 62 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 63 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 68 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 69 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 70 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 71 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 72 | OUT v_template_doc_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 73 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 82 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 83 | v_old_template_bpmn_text, |
| 84 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 85 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 86 | v_old_template_image_text, |
| 87 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 88 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 89 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 101 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 104 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 108 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 111 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 115 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 118 | 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; |
| 124 | END; |
| 125 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 130 | OUT v_service_type_id VARCHAR(80), |
| 131 | OUT v_deployment_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 132 | OUT v_template_name VARCHAR(80), |
| 133 | OUT v_template_id VARCHAR(36), |
| 134 | OUT v_model_prop_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 135 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 136 | OUT v_model_prop_text MEDIUMTEXT, |
| 137 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 138 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 139 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 144 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 145 | BEGIN |
| 146 | SELECT m.control_name_prefix, |
| 147 | m.control_name_uuid, |
| 148 | m.model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 149 | m.service_type_id, |
| 150 | m.deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 151 | t.template_name, |
| 152 | m.template_id, |
| 153 | mp.model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 154 | mp.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 155 | mp.model_prop_text, |
| 156 | mb.model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 157 | mb.user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 158 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 163 | e.user_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 164 | INTO v_control_name_prefix, |
| 165 | v_control_name_uuid, |
| 166 | v_model_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 167 | v_service_type_id, |
| 168 | v_deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 169 | v_template_name, |
| 170 | v_template_id, |
| 171 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 172 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 173 | v_model_prop_text, |
| 174 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 175 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 176 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 181 | v_event_user_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 182 | 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; |
| 200 | END; |
| 201 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 206 | OUT v_service_type_id VARCHAR(80), |
| 207 | OUT v_deployment_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 208 | OUT v_template_name VARCHAR(80), |
| 209 | OUT v_template_id VARCHAR(36), |
| 210 | OUT v_model_prop_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 211 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 212 | OUT v_model_prop_text MEDIUMTEXT, |
| 213 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 214 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 215 | OUT v_model_blueprint_text MEDIUMTEXT, |
| 216 | OUT v_template_bpmn_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 217 | OUT v_template_bpmn_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 218 | OUT v_template_bpmn_text MEDIUMTEXT, |
| 219 | OUT v_template_image_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 220 | OUT v_template_image_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 221 | OUT v_template_image_text MEDIUMTEXT, |
| 222 | OUT v_template_doc_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 223 | OUT v_template_doc_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 224 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 229 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 230 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 236 | v_service_type_id, |
| 237 | v_deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 238 | v_template_name, |
| 239 | v_template_id, |
| 240 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 241 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 242 | v_model_prop_text, |
| 243 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 244 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 245 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 250 | v_event_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 251 | CALL get_template( |
| 252 | v_template_name, |
| 253 | v_template_id, |
| 254 | v_template_bpmn_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 255 | v_template_bpmn_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 256 | v_template_bpmn_text, |
| 257 | v_template_image_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 258 | v_template_image_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 259 | v_template_image_text, |
| 260 | v_template_doc_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 261 | v_template_doc_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 262 | v_template_doc_text); |
| 263 | END; |
| 264 | CREATE PROCEDURE set_model |
| 265 | (IN v_model_name VARCHAR(80), |
| 266 | IN v_template_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 267 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 268 | IN v_model_prop_text MEDIUMTEXT, |
| 269 | IN v_model_blueprint_text MEDIUMTEXT, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 270 | IN v_service_type_id VARCHAR(80), |
| 271 | IN v_deployment_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 272 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 276 | OUT v_model_prop_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 277 | OUT v_model_blueprint_id VARCHAR(36), |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 278 | OUT v_model_blueprint_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 279 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 283 | OUT v_event_user_id VARCHAR(80)) |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 284 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 291 | DECLARE v_old_service_type_id VARCHAR(80); |
| 292 | DECLARE v_old_deployment_id VARCHAR(80); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 293 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 299 | v_old_service_type_id, |
| 300 | v_old_deployment_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 301 | v_old_template_name, |
| 302 | v_old_template_id, |
| 303 | v_model_prop_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 304 | v_model_prop_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 305 | v_old_model_prop_text, |
| 306 | v_model_blueprint_id, |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 307 | v_model_blueprint_user_id, |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 308 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 313 | v_event_user_id); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 314 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 323 | (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); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 325 | # 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 328 | SET v_event_user_id = v_user_id; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 329 | SET v_event_id = UUID(); |
| 330 | INSERT INTO event |
Determe, Sebastien (sd378r) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 331 | (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); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 333 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 350 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 353 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 357 | (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; |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 360 | 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 364 | model_blueprint_id = v_model_blueprint_id, |
| 365 | service_type_id = v_service_type_id, |
| 366 | deployment_id = v_deployment_id |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 367 | WHERE model_id = v_model_id; |
| 368 | END; |
| 369 | CREATE 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)) |
| 375 | BEGIN |
| 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); |
| 384 | END; |
| 385 | CREATE 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)) |
| 390 | BEGIN |
| 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; |
| 401 | END; |
| 402 | CREATE PROCEDURE del_all_model_instances |
| 403 | (IN v_control_name_uuid VARCHAR(36), |
| 404 | OUT v_model_id VARCHAR(36)) |
| 405 | BEGIN |
| 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; |
| 412 | END; |
| 413 | CREATE 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 417 | IN v_user_id VARCHAR(80), |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 418 | 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)) |
| 423 | BEGIN |
| 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) | b3a21f7 | 2017-08-08 02:58:27 -0700 | [diff] [blame] | 434 | (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); |
ChrisC | 5e9feb2 | 2017-06-21 02:38:57 -0700 | [diff] [blame] | 436 | UPDATE model |
| 437 | SET event_id = v_event_id |
| 438 | WHERE model_id = v_model_id; |
| 439 | END; |
| 440 | CREATE PROCEDURE upd_event |
| 441 | (IN v_event_id VARCHAR(36), |
| 442 | IN v_process_instance_id VARCHAR(80)) |
| 443 | BEGIN |
| 444 | UPDATE event |
| 445 | SET process_instance_id = v_process_instance_id |
| 446 | WHERE event_id = v_event_id; |
| 447 | END |
| 448 | // |
| 449 | DELIMITER ; |