1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 import org.apache.derby.iapi.error.StandardException; 26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 27 28 import org.apache.derby.iapi.sql.depend.Dependency; 29 import org.apache.derby.iapi.sql.depend.Dependent; 30 31 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 32 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 33 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 34 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 35 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 36 37 import org.apache.derby.iapi.sql.depend.DependencyManager; 38 import org.apache.derby.iapi.reference.SQLState; 39 import org.apache.derby.iapi.sql.execute.ConstantAction; 40 41 import org.apache.derby.iapi.sql.Activation; 42 43 import org.apache.derby.iapi.store.access.TransactionController; 44 45 import org.apache.derby.catalog.UUID; 46 47 import java.util.Enumeration ; 48 49 50 56 57 class DropIndexConstantAction extends IndexConstantAction 58 { 59 60 private String fullIndexName; 61 private long tableConglomerateId; 62 63 64 66 78 DropIndexConstantAction( 79 String fullIndexName, 80 String indexName, 81 String tableName, 82 String schemaName, 83 UUID tableId, 84 long tableConglomerateId) 85 { 86 super(tableId, indexName, tableName, schemaName); 87 this.fullIndexName = fullIndexName; 88 this.tableConglomerateId = tableConglomerateId; 89 } 90 91 93 public String toString() 94 { 95 return "DROP INDEX " + fullIndexName; 98 } 99 100 102 103 109 public void executeConstantAction(Activation activation) 110 throws StandardException 111 { 112 TableDescriptor td; 113 ConglomerateDescriptor cd; 114 115 LanguageConnectionContext lcc = activation.getLanguageConnectionContext(); 116 DataDictionary dd = lcc.getDataDictionary(); 117 DependencyManager dm = dd.getDependencyManager(); 118 TransactionController tc = lcc.getTransactionExecute(); 119 120 129 dd.startWriting(lcc); 130 131 137 if (tableConglomerateId == 0) 139 { 140 td = dd.getTableDescriptor(tableId); 141 if (td == null) 142 { 143 throw StandardException.newException( 144 SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName); 145 } 146 tableConglomerateId = td.getHeapConglomerateId(); 147 } 148 lockTableForDDL(tc, tableConglomerateId, true); 149 150 td = dd.getTableDescriptor(tableId); 151 if (td == null) 152 { 153 throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName); 154 } 155 156 162 SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true) ; 163 164 169 cd = dd.getConglomerateDescriptor(indexName, sd, true); 170 171 if (cd == null) 172 { 173 throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND_DURING_EXECUTION, fullIndexName); 174 } 175 176 182 dropIndex(dm, dd, tc, cd, td, activation.getLanguageConnectionContext()); 183 } 184 185 public static void dropIndex(DependencyManager dm, 186 DataDictionary dd, 187 TransactionController tc, 188 ConglomerateDescriptor cd, 189 TableDescriptor td, 190 LanguageConnectionContext lcc) 191 throws StandardException 192 { 193 if (SanityManager.DEBUG) 194 { 195 SanityManager.ASSERT(tc != null, "tc is null"); 196 SanityManager.ASSERT(cd != null, "cd is null"); 197 } 198 199 202 if (dd.getConglomerateDescriptors(cd.getConglomerateNumber()).length == 1) 203 { 204 205 dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc); 206 207 208 tc.dropConglomerate(cd.getConglomerateNumber()); 209 } 210 211 dm.invalidateFor(cd, DependencyManager.DROP_INDEX, lcc); 214 215 216 dd.dropConglomerateDescriptor(cd, tc); 217 218 222 td.removeConglomerateDescriptor(cd); 223 } 224 225 } 226 | Popular Tags |