1 package de.webman.content.workflow.db; 2 3 import com.teamkonzept.db.*; 4 import com.teamkonzept.lib.*; 5 import de.webman.content.workflow.*; 6 7 import java.util.*; 8 import java.sql.*; 9 10 15 public class VersionStatusTransitionDBData extends TKDBData implements TKHashable 16 { 17 18 19 private static final String EVENT_STRING = "CE_SWITCH_EVENT"; 20 21 22 public int status_id; 23 24 25 public int new_status_id; 26 27 28 public String transition_attributes; 29 30 31 public String status; 32 33 34 public String new_status; 35 36 private String event; 37 38 39 public String mode; 40 41 42 public boolean delete; 43 44 TKHashtable hashed; 45 46 47 public VersionStatus fromStatus; 48 49 50 public VersionStatus toStatus; 51 52 public void init () { 53 54 status_id = -1; 55 new_status_id = -1; 56 transition_attributes = null; 57 58 status = null; 59 new_status = null; 60 61 mode = null; 62 delete = false; 63 64 hashed = null; 65 fromStatus = null; 66 toStatus = null; 67 event = null; 68 } 69 70 74 public String getEvent() 75 { 76 if (event == null) 77 { 78 if (mode != null && mode.equals("+")) 79 event = EVENT_STRING + "_" + status_id + "_" + new_status_id; 80 else 81 event = ""; 82 } 83 return event; 84 } 85 86 public boolean isTransition() 87 { 88 return mode.equals("+"); 89 } 90 91 public VersionStatusTransitionDBData () { 92 93 this.init(); 94 } 95 96 public VersionStatusTransitionDBData( 97 int status_id, int new_status_id, String transition_attributes) 98 { 99 this.init(); 100 101 this.status_id = status_id; 102 this.new_status_id = new_status_id; 103 this.transition_attributes = transition_attributes; 104 105 this.scanAttributes(); 106 } 107 108 public VersionStatusTransitionDBData( 109 VersionStatics statics, 110 int status_id, String status, 111 int new_status_id, String new_status, 112 String transition_attributes) 113 { 114 this.status_id = status_id; 115 this.new_status_id = new_status_id; 116 this.transition_attributes = transition_attributes; 117 118 this.status = status; 119 this.new_status = new_status; 120 121 resolveStatus (statics); 122 this.scanAttributes(); 123 } 124 125 public VersionStatusTransitionDBData (VersionStatics statics, ResultSet r) 126 { 127 try { this.fill (statics, r); } catch (Exception ex) { this.init(); } 128 } 129 130 public VersionStatusTransitionDBData (ResultSet r) { 131 132 this (null,r); 133 } 134 135 public void insertPrimaryIntoQuery (TKQuery query) throws SQLException { 136 137 query.setQueryParams("STATUS_ID", new Integer (status_id)); 138 query.setQueryParams("NEW_STATUS_ID", new Integer (new_status_id)); 139 } 140 141 public void insertInitialIntoQuery (TKQuery query) throws SQLException { 142 143 query.setQueryParams("TRANSITION_ATTRIBUTES", transition_attributes); 144 } 145 146 public void insertIntoQuery (TKQuery query) throws SQLException 147 { 148 insertPrimaryIntoQuery (query); 149 insertInitialIntoQuery (query); 150 } 151 152 public void fill (VersionStatics statics, ResultSet r) throws SQLException 153 { 154 this.status_id = r.getInt("STATUS_ID"); 155 this.new_status_id = r.getInt("NEW_STATUS_ID"); 156 this.transition_attributes = r.getString("TRANSITION_ATTRIBUTES"); 157 158 this.status = r.getString("STATUS"); 159 this.new_status = r.getString("NEW_STATUS"); 160 161 resolveStatus (statics); 162 this.scanAttributes(); 163 } 164 165 public void fill (ResultSet r) throws SQLException 166 { 167 fill (null,r); 168 } 169 170 public void assembleAttributes () 171 { 172 this.transition_attributes = 173 (this.mode == null ? "?" : this.mode) + ";" + 174 (this.delete ? "delete;" : ""); 175 } 176 177 public void scanAttributes () { 178 179 mode = "?"; 180 delete = false; 181 event = null; 182 if (transition_attributes == null) return; 183 184 StringTokenizer tokenizer = new StringTokenizer(transition_attributes,";"); 185 while (tokenizer.hasMoreTokens()) 186 { 187 String attr = tokenizer.nextToken(); 188 if (attr == null) 189 continue; 190 if (attr.equalsIgnoreCase ("?")) mode = attr; 191 else if (attr.equalsIgnoreCase ("+")) mode = attr; 192 else if (attr.equalsIgnoreCase ("-")) mode = attr; 193 else if (attr.equalsIgnoreCase ("delete")) delete = true; 194 } 195 makeHashed(); 196 } 197 198 199 public void resolveStatus (VersionStatics statics) { 200 201 if (statics == null) 202 return; 203 fromStatus = (VersionStatus) statics.getStatusPool().get(new Integer (this.status_id)); 204 toStatus = (VersionStatus) statics.getStatusPool().get(new Integer (this.new_status_id)); 205 rehashStatus(); 206 } 207 208 public void rehashStatus () 209 { 210 if (hashed == null) 211 { 212 makeHashed(); 213 return; 214 } 215 if (fromStatus != null) hashed.put ("FROM",fromStatus.toHashtable()); 216 if (toStatus != null) hashed.put ("TO",toStatus.toHashtable()); 217 } 218 219 public void makeHashed () { 220 221 hashed = new TKHashtable(); 222 223 hashed.put ("STATUS_ID",new Integer (status_id)); 224 hashed.put ("NEW_STATUS_ID",new Integer (new_status_id)); 225 226 if (status != null) hashed.put ("STATUS",status); 227 if (new_status != null) hashed.put ("NEW_STATUS",new_status); 228 229 hashed.put ("THIS_MODE",mode == null ? "?" : mode); 230 hashed.put ("ATTR.L",delete ? "ON" : "OFF"); 231 hashed.put("EVENT", getEvent()); 232 rehashStatus(); 233 } 234 235 public TKHashtable toHashtable () 236 { 237 if (hashed == null) 238 makeHashed(); 239 return hashed; 241 } 242 243 public String toString() 244 { 245 return "( TRANSITION := " 246 + "(STATUS_ID = " + String.valueOf( status_id ) 247 + ", NEW_STATUS_ID = " + String.valueOf( new_status_id ) 248 + ", TRANSITION_ATTRIBUTES = " + transition_attributes 249 + ", STATUS = " + status 250 + ", NEW_STATUS = " + new_status 251 + ", MODE = " + mode 252 + ", ATTR.l = " + delete 253 + ")<BR>" 254 + ")<BR>"; 255 } 256 257 public String toSql () 258 { 259 return "INSERT INTO VERSION_STATUS_TRANSITION (STATUS_ID, NEW_STATUS_ID, TRANSITION_ATTRIBUTES) "+ 260 "VALUES ("+status_id+","+new_status_id+",\""+transition_attributes+"\") "; 261 } 262 } 263 | Popular Tags |