1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemamanipulation; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.serversystem.*; 6 import com.daffodilwoods.daffodildb.server.sql99.common.*; 7 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*; 8 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 10 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*; 11 import com.daffodilwoods.daffodildb.server.sql99.token.*; 12 import com.daffodilwoods.database.general.*; 13 import com.daffodilwoods.database.resource.*; 14 15 public class dropschemastatement implements SQLschemamanipulationstatement { 16 public dropbehavior _dropbehavior0; 17 public schemaname _schemaname1; 18 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439222; 19 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439223; 20 21 24 25 50 51 private ArrayList tables = new ArrayList(); 52 private ArrayList views = new ArrayList(); 53 private ArrayList domains = new ArrayList(); 54 private ArrayList sequences = new ArrayList(); 55 private ArrayList triggers = new ArrayList(); 56 57 public Object run(Object object) throws DException { 58 _ServerSession currentSession = ( (_ServerSession) object); 59 SchemaDescriptor schemaDescriptor = new SchemaDescriptor(); 60 checkSchemaName(); 61 setSchemaName(schemaDescriptor, currentSession); 62 try { 63 GeneralUtility.validateUserRights(schemaDescriptor.schema_owner, 64 currentSession); 65 } catch (DException ex1) { 66 if (ex1.getDseCode().equalsIgnoreCase("DSE12")) { 67 throw new DException("DSE907", 68 new Object [] {schemaDescriptor.schema_owner}); 69 } 70 throw ex1; 71 } 72 String behavior = (String ) _dropbehavior0.run(null); 73 74 dropSchema(schemaDescriptor, currentSession, 75 behavior); 76 77 refreshServerSystem(currentSession); 78 return null; 79 } 80 81 public void refreshServerSystem(_ServerSession currentSession) throws DException { 82 droptriggerstatement dropTriSt = new droptriggerstatement(); 83 for (int i = 0, size = triggers.size(); i < size; i++) { 84 dropTriSt.refreshDataDictionary(currentSession, (TriggerDescriptor) triggers.get(i)); 85 } 86 dropsequencestatement dropSeqSt = new dropsequencestatement(); 87 for (int i = 0, size = sequences.size(); i < size; i++) { 88 dropSeqSt.refreshServerSystem(currentSession, (QualifiedIdentifier) sequences.get(i)); 89 } 90 droptablestatement dropTableSt = new droptablestatement(); 91 for (int i = 0, size = tables.size(); i < size; i++) { 92 dropTableSt.refreshServerSystem(currentSession, (QualifiedIdentifier) tables.get(i)); 93 } 94 dropviewstatement dropViewSt = new dropviewstatement(); 95 for (int i = 0, size = views.size(); i < size; i++) { 96 dropViewSt.refreshServerSystem(currentSession, (ViewDescriptor) views.get(i)); 97 } 98 dropdomainstatement dropDomainSt = new dropdomainstatement(); 99 for (int i = 0, size = domains.size(); i < size; i++) { 100 dropDomainSt.refreshDataDictionary(currentSession, (QualifiedIdentifier) domains.get(i)); 101 } 102 } 103 104 public void dropSchema(SchemaDescriptor schemaDescriptor, 105 _ServerSession currentSession, String behavior) throws 106 DException { 107 if (SqlKeywords.RESTRICT.equalsIgnoreCase(behavior)) { 108 checkDependencies(schemaDescriptor, currentSession); 109 } else { 110 dropDependents(schemaDescriptor, currentSession); 111 } 112 schemaDescriptor.delete(currentSession); 113 } 114 115 private void dropDependents(SchemaDescriptor schemaDescriptor, 116 _ServerSession currentSession) throws DException { 117 dropTriggers(schemaDescriptor, currentSession); 118 dropRoutines(schemaDescriptor, currentSession); 119 dropSequence(schemaDescriptor, currentSession); 120 dropTablesAndView(schemaDescriptor, currentSession); 121 dropDomains(schemaDescriptor, currentSession); 122 } 123 124 private void setSchemaName(SchemaDescriptor schemaDescriptor, 125 _ServerSession currentSession) throws DException { 126 String catalog_Name = _schemaname1.getCatalogName(); 127 String schema_Name = _schemaname1.getSchemaName(); 128 if (catalog_Name == null) { 129 catalog_Name = currentSession.getCurrentCatalog(); 130 } 131 schemaDescriptor.catalog_name = catalog_Name; 132 schemaDescriptor.schema_name = schema_Name; 133 schemaDescriptor.load(currentSession); 134 } 135 136 137 private void checkSchemaName() throws DException { 138 String schema_Name = _schemaname1.getSchemaName(); 139 if (schema_Name.equalsIgnoreCase(SqlSchemaConstants.defaultSchema)) { 140 throw new DException("DSE8169",new Object []{schema_Name}); 141 } 142 } 143 144 private void checkDependencies(SchemaDescriptor schemaDescriptor, 145 _ServerSession currentSession) throws 146 DException { 147 String catalog_Name = schemaDescriptor.catalog_name; 148 String schema_Name = schemaDescriptor.schema_name; 149 150 checkTriggersExistence(currentSession, catalog_Name, schema_Name); 151 checkRoutinesExistence(schemaDescriptor, currentSession); 152 checkTablesAndViewsExistence(currentSession, catalog_Name, schema_Name); 153 checkDomainsExistence(currentSession, catalog_Name, schema_Name); 154 checkSequenceExistencce(currentSession, catalog_Name, schema_Name); 155 } 156 157 private void checkSequenceExistencce(_ServerSession currentSession, 158 String catalog_Name, String schema_Name) throws 159 DException { 160 String clause = QueryMaker.getSequenceQueryForSchema(); 161 _Iterator sequenceIterator = SqlSchemaConstants.getIterator(currentSession, 162 clause, new Object [] {catalog_Name, schema_Name}); 163 if (sequenceIterator.first()) { 164 throw new DException("DSE5010", null); 165 } 166 } 167 168 private void checkTriggersExistence(_ServerSession currentSession, 169 String catalog_Name, String schema_Name) throws 170 DException { 171 String clause = QueryMaker.getTriggersQueryForSchema(); 172 _Iterator triggersIterator = SqlSchemaConstants.getIterator(currentSession, 173 clause, new Object [] {catalog_Name, schema_Name}); 174 if (triggersIterator.first()) { 175 throw new DException("DSE5010", null); 176 } 177 } 178 179 private void checkRoutinesExistence(SchemaDescriptor schemaDescriptor, 180 _ServerSession currentSession) throws 181 DException { 182 String clause = QueryMaker.getRoutinesQueryForSchema(); 183 _Iterator routinesIterator = SqlSchemaConstants.getIterator(currentSession, 184 clause, 185 new Object [] {schemaDescriptor.catalog_name, 186 schemaDescriptor.schema_name}); 187 if (routinesIterator.first()) { 188 throw new DException("DSE5010", null); 189 } 190 } 191 192 private void checkDomainsExistence(_ServerSession currentSession, 193 String catalog_Name, String schema_Name) throws 194 DException { 195 String clause = QueryMaker.getDomainsQueryForSchema(); 196 _Iterator domainsIterator = SqlSchemaConstants.getIterator(currentSession, 197 clause, new Object [] {catalog_Name, schema_Name}); 198 if (domainsIterator.first()) { 199 throw new DException("DSE5010", null); 200 } 201 } 202 203 private void checkTablesAndViewsExistence(_ServerSession currentSession, 204 String catalog_Name, 205 String schema_Name) throws 206 DException { 207 String clause = QueryMaker.getTableAndViewsQueryForSchema(); 208 _Iterator tablesIterator = SqlSchemaConstants.getIterator(currentSession, 209 clause, new Object [] {catalog_Name, schema_Name}); 210 if (tablesIterator.first()) { 211 throw new DException("DSE5010", null); 212 } 213 } 214 215 219 220 private void dropTablesAndView(SchemaDescriptor schemaDescriptor, 221 _ServerSession currentSession) throws 222 DException { 223 String query = QueryMaker.getTableAndViewsQueryForSchema(); 224 _SelectQueryIterator tablesIterator = SqlSchemaConstants.getIterator(currentSession, 225 query, new Object [] {schemaDescriptor.catalog_name, 226 schemaDescriptor.schema_name}); 227 if (tablesIterator.first()) { 228 do { 229 Object [] obj = (Object []) tablesIterator.getObject(); 230 String catalogName = (String ) obj[SystemTablesFields. 231 tables_table_catalog]; 232 String schemaName = (String ) obj[SystemTablesFields.tables_table_schema]; 233 String tableName = (String ) obj[SystemTablesFields.tables_table_name]; 234 String tableType = (String ) obj[SystemTablesFields.tables_table_type]; 235 if (tableType.equalsIgnoreCase("View")) { 236 ViewDescriptor viewDescriptor = new ViewDescriptor(); 237 viewDescriptor.table_catalog = catalogName; 238 viewDescriptor.table_schema = schemaName; 239 viewDescriptor.table_name = tableName; 240 try { 241 viewDescriptor.load(currentSession); 242 } catch (DException ex) { 243 continue; 244 } 245 dropviewstatement view = new dropviewstatement(); 246 view.dropView(viewDescriptor, currentSession, SqlKeywords.CASCADE, 247 schemaDescriptor.schema_owner); 248 views.add(viewDescriptor); 249 } else { 250 TableDescriptor tableDescriptor = new TableDescriptor(); 251 tableDescriptor.table_catalog = catalogName; 252 tableDescriptor.table_schema = schemaName; 253 tableDescriptor.table_name = tableName; 254 tableDescriptor.schemaDescriptor = schemaDescriptor; 255 tableDescriptor.load(currentSession); 256 droptablestatement table = new droptablestatement(); 257 table.dropTable(tableDescriptor, currentSession, SqlKeywords.CASCADE, 258 schemaDescriptor.schema_owner); 259 tables.add(tableDescriptor.getQualifiedTableName()); 260 } 261 } while (tablesIterator.next()); 262 } 263 } 264 265 private void dropDomains(SchemaDescriptor schemaDescriptor, 266 _ServerSession currentSession) throws DException { 267 String query = QueryMaker.getDomainsQueryForSchema(); 268 _SelectQueryIterator domainsIterator = SqlSchemaConstants.getIterator(currentSession, 269 query, new Object [] {schemaDescriptor.catalog_name, 270 schemaDescriptor.schema_name}); 271 if (domainsIterator.first()) { 272 do { 273 Object [] obj = (Object []) domainsIterator.getObject(); 274 DomainDescriptor domainDescriptor = new DomainDescriptor(); 275 domainDescriptor.catalog_name = (String ) obj[SystemTablesFields. 276 domain_catalog_name]; 277 domainDescriptor.schema_name = (String ) obj[SystemTablesFields. 278 domain_schema_name]; 279 domainDescriptor.domain_name = (String ) obj[SystemTablesFields. 280 domain_domain_name]; 281 domainDescriptor.load(currentSession); 282 dropdomainstatement domain = new dropdomainstatement(); 283 domain.dropDomain(domainDescriptor, currentSession, SqlKeywords.CASCADE, 284 schemaDescriptor.schema_owner); 285 domains.add(domainDescriptor.getQualifiedIdentifier()); 286 } while (domainsIterator.next()); 287 } 288 } 289 290 private void dropTriggers(SchemaDescriptor schemaDescriptor, 291 _ServerSession currentSession) throws DException { 292 String query = QueryMaker.getTriggersQueryForSchema(); 293 _SelectQueryIterator triggersIterator = SqlSchemaConstants.getIterator(currentSession, 294 query, new Object [] {schemaDescriptor.catalog_name, 295 schemaDescriptor.schema_name}); 296 if (triggersIterator.first()) { 297 do { 298 Object [] obj = (Object []) triggersIterator.getObject(); 299 TriggerDescriptor triggerDescriptor = new TriggerDescriptor(); 300 triggerDescriptor.trigger_catalog = (String ) obj[SystemTablesFields. 301 triggerDescriptor_trigger_catalog]; 302 triggerDescriptor.trigger_schema = (String ) obj[SystemTablesFields. 303 triggerDescriptor_trigger_schema]; 304 triggerDescriptor.trigger_name = (String ) obj[SystemTablesFields. 305 triggerDescriptor_trigger_name]; 306 triggerDescriptor.load(currentSession); 307 droptriggerstatement trigger = new droptriggerstatement(); 308 trigger.dropTrigger(currentSession, triggerDescriptor); 309 triggers.add(triggerDescriptor); 310 } while (triggersIterator.next()); 311 } 312 } 313 314 private void dropRoutines(SchemaDescriptor schemaDescriptor, 315 _ServerSession currentSession) throws DException { 316 String query = QueryMaker.getRoutinesQueryForSchema(); 317 _SelectQueryIterator routinesIterator = SqlSchemaConstants.getIterator(currentSession, 318 query, new Object [] {schemaDescriptor.catalog_name, 319 schemaDescriptor.schema_name}); 320 if (routinesIterator.first()) { 321 do { 322 Object [] obj = (Object []) routinesIterator.getObject(); 323 RoutineDescriptor routineDescriptor = new RoutineDescriptor(); 324 routineDescriptor.SPECIFIC_CATALOG = (String ) obj[SystemTablesFields. 325 routines_specific_catalog]; 326 routineDescriptor.SPECIFIC_SCHEMA = (String ) obj[SystemTablesFields. 327 routines_specific_schema]; 328 routineDescriptor.SPECIFIC_NAME = (String ) obj[SystemTablesFields. 329 routines_specific_name]; 330 routineDescriptor.ROUTINE_TYPE = (String ) obj[SystemTablesFields. 331 routines_routine_type]; 332 routineDescriptor.load(currentSession); 333 droproutinestatement dropRountine = new droproutinestatement(); 334 dropRountine.dropRoutine(currentSession, routineDescriptor, 335 SqlKeywords.CASCADE); 336 } while (routinesIterator.next()); 337 } 338 } 339 340 private void dropSequence(SchemaDescriptor schemaDescriptor, 341 _ServerSession currentSession) throws DException { 342 String query = QueryMaker.getSequenceQueryForSchema(); 343 _SelectQueryIterator sequenceIterator = SqlSchemaConstants.getIterator(currentSession, 344 query, new Object [] {schemaDescriptor.catalog_name, 345 schemaDescriptor.schema_name}); 346 if (sequenceIterator.first()) { 347 do { 348 Object [] obj = (Object []) sequenceIterator.getObject(); 349 SequenceNumberDescriptor sequenceDescriptor = new 350 SequenceNumberDescriptor(); 351 sequenceDescriptor.sequence_catalog = (String ) obj[SystemTablesFields. 352 sequence_number_sequence_catalog]; 353 sequenceDescriptor.sequence_schema = (String ) obj[SystemTablesFields. 354 sequence_number_sequence_schema]; 355 sequenceDescriptor.sequence_name = (String ) obj[SystemTablesFields. 356 sequence_number_sequence_name]; 357 sequenceDescriptor.load(currentSession); 358 dropsequencestatement sequence = new dropsequencestatement(); 359 sequence.dropSequence(currentSession, sequenceDescriptor); 360 sequences.add(sequenceDescriptor.getQualifiedName()); 361 } while (sequenceIterator.next()); 362 } 363 } 364 365 public Object clone() throws CloneNotSupportedException { 366 return this; 367 } 368 369 public String toString() { 370 StringBuffer sb = new StringBuffer (); 371 sb.append(" "); 372 sb.append(_SRESERVEDWORD12065439223); 373 sb.append(" "); 374 sb.append(_SRESERVEDWORD12065439222); 375 sb.append(" "); 376 sb.append(_schemaname1); 377 sb.append(" "); 378 sb.append(_dropbehavior0); 379 return sb.toString(); 380 } 381 } 382 | Popular Tags |