1 21 22 package org.apache.derby.iapi.sql.dictionary; 23 24 import org.apache.derby.iapi.error.StandardException; 25 import org.apache.derby.iapi.services.sanity.SanityManager; 26 27 import org.apache.derby.catalog.UUID; 28 29 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor; 30 import org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor; 31 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 32 import org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor; 33 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 34 35 import org.apache.derby.iapi.error.StandardException; 36 import org.apache.derby.iapi.services.sanity.SanityManager; 37 38 import org.apache.derby.catalog.UUID; 39 40 import java.util.ArrayList ; 41 42 public class ConstraintDescriptorList extends ArrayList 43 { 44 45 private boolean scanned; 46 47 56 public void setScanned(boolean scanned) 57 { 58 this.scanned = scanned; 59 } 60 61 66 public boolean getScanned() 67 { 68 return scanned; 69 } 70 71 78 public ConstraintDescriptor getConstraintDescriptor(UUID indexUUID) 79 { 80 ConstraintDescriptor retCD = null; 81 int size = size(); 82 83 for (int index = 0; index < size; index++) 84 { 85 ConstraintDescriptor cd = elementAt(index); 86 87 if (! (cd instanceof KeyConstraintDescriptor)) 88 { 89 continue; 90 } 91 92 KeyConstraintDescriptor keyCD = (KeyConstraintDescriptor) cd; 93 94 if (keyCD.getIndexId().equals(indexUUID)) 95 { 96 retCD = cd; 97 break; 98 } 99 } 100 return retCD; 101 } 102 103 110 public ConstraintDescriptor getConstraintDescriptorById(UUID uuid) 111 { 112 ConstraintDescriptor returnCD = null; 113 int size = size(); 114 115 for (int index = 0; index < size; index++) 116 { 117 ConstraintDescriptor cd = elementAt(index); 118 119 if (cd.getUUID().equals(uuid)) 120 { 121 returnCD = cd; 122 break; 123 } 124 } 125 return returnCD; 126 } 127 128 135 public ConstraintDescriptor dropConstraintDescriptorById(UUID uuid) 136 { 137 ConstraintDescriptor cd = null; 138 int size = size(); 139 140 for (int index = 0; index < size; index++) 141 { 142 cd = elementAt(index); 143 144 if (cd.getUUID().equals(uuid)) 145 { 146 remove( cd ); 147 break; 148 } 149 } 150 151 return cd; 152 } 153 154 155 156 164 public ConstraintDescriptor getConstraintDescriptorByName(SchemaDescriptor sd, 165 String name) 166 { 167 ConstraintDescriptor retCD = null; 168 int size = size(); 169 170 for (int index = 0; index < size; index++) 171 { 172 ConstraintDescriptor cd = elementAt(index); 173 174 if (cd.getConstraintName().equals(name)) 175 { 176 if ((sd == null) || 177 (sd.equals(cd.getSchemaDescriptor()))) 178 { 179 retCD = cd; 180 break; 181 } 182 } 183 } 184 return retCD; 185 } 186 187 188 193 public ReferencedKeyConstraintDescriptor getPrimaryKey() 194 { 195 int size = size(); 196 197 for (int index = 0; index < size; index++) 198 { 199 ConstraintDescriptor cd = elementAt(index); 200 201 if (cd.getConstraintType() == DataDictionary.PRIMARYKEY_CONSTRAINT) 202 { 203 return (ReferencedKeyConstraintDescriptor)cd; 204 } 205 } 206 return (ReferencedKeyConstraintDescriptor)null; 207 } 208 209 220 public ConstraintDescriptorList getConstraintDescriptorList(boolean enabled) 221 { 222 ConstraintDescriptorList cdl = new ConstraintDescriptorList(); 223 int size = size(); 224 225 for (int index = 0; index < size; index++) 226 { 227 ConstraintDescriptor cd = elementAt(index); 228 229 if (cd.isEnabled() == enabled) 230 { 231 cdl.add(cd); 232 } 233 } 234 return cdl; 235 } 236 237 244 public ConstraintDescriptor elementAt(int n) 245 { 246 return (ConstraintDescriptor) get(n); 247 } 248 249 258 public ConstraintDescriptorList getSubList(int type) 259 { 260 ConstraintDescriptor cd = null; 261 ConstraintDescriptorList cdl = new ConstraintDescriptorList(); 262 int size = size(); 263 264 for (int index = 0; index < size; index++) 265 { 266 cd = elementAt(index); 267 268 if (cd.getConstraintType() == type) 269 { 270 cdl.add(cd); 271 } 272 } 273 return cdl; 274 } 275 } 276 | Popular Tags |