1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.error.StandardException; 25 26 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 27 import org.apache.derby.iapi.sql.dictionary.GenericDescriptorList; 28 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 29 import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor; 30 31 import org.apache.derby.iapi.services.monitor.Monitor; 32 33 import org.apache.derby.iapi.services.sanity.SanityManager; 34 import org.apache.derby.iapi.services.io.StoredFormatIds; 35 import org.apache.derby.iapi.services.io.FormatIdUtil; 36 import org.apache.derby.iapi.services.io.ArrayUtil; 37 import org.apache.derby.iapi.services.io.Formatable; 38 import org.apache.derby.catalog.UUID; 39 40 import java.io.ObjectOutput ; 41 import java.io.ObjectInput ; 42 import java.io.IOException ; 43 import java.util.Enumeration ; 44 45 import java.util.Vector ; 46 47 54 public final class TriggerInfo implements Formatable 55 { 56 72 73 TriggerDescriptor[] triggerArray; 74 String [] columnNames; 75 int[] columnIds; 76 77 80 public TriggerInfo() {} 81 82 91 public TriggerInfo 92 ( 93 TableDescriptor td, 94 int[] changedCols, 95 GenericDescriptorList triggers 96 ) 97 { 98 this.columnIds = changedCols; 99 100 if (columnIds != null) 101 { 102 106 columnNames = new String [columnIds.length]; 107 for (int i = 0; i < columnIds.length; i++) 108 { 109 columnNames[i] = td.getColumnDescriptor(columnIds[i]).getColumnName(); 110 } 111 } 112 113 if (SanityManager.DEBUG) 114 { 115 SanityManager.ASSERT(triggers != null, "null trigger descriptor list"); 116 SanityManager.ASSERT(triggers.size() > 0, "trigger descriptor list has no elements"); 117 } 118 119 122 Enumeration descs = triggers.elements(); 123 124 int size = triggers.size(); 125 triggerArray = new TriggerDescriptor[size]; 126 127 for (int i = 0; i < size; i++) 128 { 129 triggerArray[i] = (TriggerDescriptor) descs.nextElement(); 130 } 131 } 132 133 136 private TriggerInfo 137 ( 138 TriggerDescriptor[] triggers, 139 int[] changedColsIds, 140 String [] changedColsNames 141 ) 142 { 143 this.columnIds = changedColsIds; 144 this.columnNames = changedColsNames; 145 this.triggerArray = triggers; 146 } 147 148 160 boolean hasTrigger(boolean isBefore, boolean isRow) 161 { 162 if (triggerArray == null) 163 { 164 return false; 165 } 166 167 return hasTrigger(new Boolean (isBefore), new Boolean (isRow)); 168 } 169 170 182 private boolean hasTrigger(Boolean isBefore, Boolean isRow) 183 { 184 if (triggerArray == null) 185 { 186 return false; 187 } 188 for (int i = 0; i < triggerArray.length; i++) 189 { 190 if (((isBefore == null) || 191 (triggerArray[i].isBeforeTrigger() == isBefore.booleanValue())) && 192 ((isRow == null) || 193 (triggerArray[i].isRowTrigger() == isRow.booleanValue()))) 194 { 195 return true; 196 } 197 } 198 return false; 199 } 200 201 TriggerDescriptor[] getTriggerArray() 202 { 203 return triggerArray; 204 } 205 217 public void writeExternal(ObjectOutput out) throws IOException 218 { 219 ArrayUtil.writeArray(out, triggerArray); 220 ArrayUtil.writeIntArray(out, columnIds); 221 ArrayUtil.writeArray(out, columnNames); 222 } 223 224 232 public void readExternal(ObjectInput in) 233 throws IOException , ClassNotFoundException 234 { 235 triggerArray = new TriggerDescriptor[ArrayUtil.readArrayLength(in)]; 236 ArrayUtil.readArrayItems(in, triggerArray); 237 238 columnIds = ArrayUtil.readIntArray(in); 239 240 int len = ArrayUtil.readArrayLength(in); 241 if (len > 0) 242 { 243 columnNames = new String [len]; 244 ArrayUtil.readArrayItems(in, columnNames); 245 } 246 } 247 248 253 public int getTypeFormatId() { return StoredFormatIds.TRIGGER_INFO_V01_ID; } 254 255 public String toString() 261 { 262 if (SanityManager.DEBUG) 263 { 264 StringBuffer str = new StringBuffer (); 265 str.append("\nColumn names modified:\t\t("); 266 for (int i = 0; i < columnNames.length; i++) 267 { 268 if (i > 0) 269 str.append(","); 270 271 str.append(columnNames[i]); 272 } 273 str.append(")"); 274 275 str.append("\nColumn ids modified:\t\t("); 276 for (int i = 0; i < columnIds.length; i++) 277 { 278 if (i > 0) 279 str.append(","); 280 281 str.append(columnIds[i]); 282 } 283 str.append(")"); 284 285 str.append("\nTriggers:"); 286 for (int i = 0; i < triggerArray.length; i++) 287 { 288 str.append("\n"+triggerArray[i]); 289 } 290 return str.toString(); 291 } 292 else 293 { 294 return ""; 295 } 296 } 297 } 298 | Popular Tags |