1 21 22 package org.apache.derby.iapi.sql.dictionary; 23 24 import org.apache.derby.iapi.services.context.ContextManager; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 import org.apache.derby.iapi.sql.depend.Dependent; 29 30 import org.apache.derby.iapi.services.context.ContextManager; 31 32 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 33 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 34 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 35 import org.apache.derby.iapi.sql.dictionary.IndexRowGenerator; 36 37 import org.apache.derby.iapi.sql.depend.Dependent; 38 import org.apache.derby.iapi.sql.depend.DependencyManager; 39 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 40 import org.apache.derby.iapi.services.sanity.SanityManager; 41 42 import org.apache.derby.iapi.error.StandardException; 43 44 import java.util.Enumeration ; 45 import java.util.Vector ; 46 47 52 public class IndexLister 53 { 54 60 private TableDescriptor tableDescriptor; 61 private IndexRowGenerator[] indexRowGenerators; 62 private long[] indexConglomerateNumbers; 63 private String [] indexNames; 64 private IndexRowGenerator[] distinctIndexRowGenerators; 66 private long[] distinctIndexConglomerateNumbers; 67 private String [] distinctIndexNames; 68 69 75 81 public IndexLister( TableDescriptor tableDescriptor ) 82 { 83 this.tableDescriptor = tableDescriptor; 84 } 85 86 87 93 100 public IndexRowGenerator[] getIndexRowGenerators() 101 throws StandardException 102 { 103 if ( indexRowGenerators == null ) { getAllIndexes(); } 104 return indexRowGenerators; 105 } 106 107 114 public long[] getIndexConglomerateNumbers() 115 throws StandardException 116 { 117 if ( indexConglomerateNumbers == null ) { getAllIndexes(); } 118 return indexConglomerateNumbers; 119 } 120 121 128 public String [] getIndexNames() throws StandardException 129 { 130 if ( indexNames == null ) { getAllIndexes(); } 131 return indexNames; 132 } 133 134 142 public IndexRowGenerator[] getDistinctIndexRowGenerators() 143 throws StandardException 144 { 145 if ( distinctIndexRowGenerators == null ) { getAllIndexes(); } 146 return distinctIndexRowGenerators; 147 } 148 149 157 public long[] getDistinctIndexConglomerateNumbers() 158 throws StandardException 159 { 160 if ( distinctIndexConglomerateNumbers == null ) { getAllIndexes(); } 161 return distinctIndexConglomerateNumbers; 162 } 163 164 172 public String [] getDistinctIndexNames() throws StandardException 173 { 174 if ( indexNames == null ) { getAllIndexes(); } 175 return indexNames; 176 } 177 178 184 191 private void getAllIndexes() 192 throws StandardException 193 { 194 int indexCount = 0; 195 196 ConglomerateDescriptor[] cds = 197 tableDescriptor.getConglomerateDescriptors(); 198 199 204 long[] workSpace = new long[cds.length - 1]; int distinctIndexCount = 0, duplicateIndex = workSpace.length - 1; 206 207 for (int i = 0; i < cds.length; i++) 208 { 209 ConglomerateDescriptor cd = cds[i]; 211 212 if ( ! cd.isIndex()) 213 continue; 214 215 int k; 216 long thisCongNum = cd.getConglomerateNumber(); 217 218 for (k = 0; k < distinctIndexCount; k++) 219 { 220 if (workSpace[k] == thisCongNum) 221 { 222 workSpace[duplicateIndex--] = i; 223 break; 224 } 225 } 226 if (k == distinctIndexCount) workSpace[distinctIndexCount++] = thisCongNum; 228 229 indexCount++; 230 } 231 232 indexRowGenerators = new IndexRowGenerator[ indexCount ]; 233 indexConglomerateNumbers = new long[ indexCount ]; 234 indexNames = new String [ indexCount ]; 235 distinctIndexRowGenerators = new IndexRowGenerator[ distinctIndexCount ]; 236 distinctIndexConglomerateNumbers = new long[ distinctIndexCount ]; 237 distinctIndexNames = new String [ distinctIndexCount ]; 238 239 int duplicatePtr = workSpace.length - 1; 240 for ( int i = 0, j = -1, k = -1; i < cds.length; i++ ) 241 { 242 ConglomerateDescriptor cd = cds[i]; 243 244 if ( ! cd.isIndex()) 245 continue; 246 247 indexRowGenerators[++j] = 248 (IndexRowGenerator)cd.getIndexDescriptor(); 249 indexConglomerateNumbers[j] = cd.getConglomerateNumber(); 250 if (!(cd.isConstraint())) 251 { 252 indexNames[j] = cd.getConglomerateName(); 254 } 255 256 if (duplicatePtr > duplicateIndex && i == (int) workSpace[duplicatePtr]) 257 duplicatePtr--; 258 else 259 { 260 distinctIndexRowGenerators[++k] = indexRowGenerators[j]; 261 distinctIndexConglomerateNumbers[k] = indexConglomerateNumbers[j]; 262 distinctIndexNames[k] = indexNames[j]; 263 } 264 } 265 } 266 } 267 | Popular Tags |