1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemamanipulation; 2 3 import java.util.*; 4 5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 6 import com.daffodilwoods.daffodildb.server.serversystem.*; 7 import com.daffodilwoods.daffodildb.server.sql99.common.*; 8 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*; 9 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*; 10 import com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.fromclause.*; 11 import com.daffodilwoods.daffodildb.server.sql99.token.*; 12 import com.daffodilwoods.database.general.*; 13 import com.daffodilwoods.database.resource.*; 14 15 public class altertablestatement implements SQLschemamanipulationstatement { 16 public altertableaction _altertableaction0; 17 public tablename _tablename1; 18 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439222; 19 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439223; 20 21 private boolean selfInitiated = true; 22 23 public void setIsSelfInitiated(boolean selfInitiated0) { 24 selfInitiated = selfInitiated0; 25 } 26 27 public Object run(Object object) throws DException { 28 _ServerSession currentSession = (_ServerSession) object; 29 _ServerSession systemSession = currentSession.getSystemServerSession(); 30 TableDescriptor tableDescriptor = new TableDescriptor(); 31 tableDescriptor.isAlterTable=true; 32 setTableName(tableDescriptor, currentSession); 33 checkTableType(tableDescriptor); 34 String schemaOwner = GeneralUtility.getSchemaOwner(tableDescriptor. 35 table_catalog, tableDescriptor.table_schema, currentSession); 36 GeneralUtility.validateUserRights(schemaOwner, currentSession); 37 executeAlterTableActions(currentSession, tableDescriptor); 38 if (selfInitiated) { 39 createIndexes(tableDescriptor, currentSession); 40 } 41 systemSession.deleteTable(tableDescriptor.getQualifiedTableName(), false); 42 return null; 43 } 44 45 private void executeAlterTableActions(_ServerSession currentSession, 46 TableDescriptor tableDescriptor) throws 47 DException { 48 _altertableaction0.setTableDescriptor(tableDescriptor); 49 _altertableaction0.run(currentSession); 50 } 51 52 private void createIndexes(TableDescriptor tableDescriptor, 53 _ServerSession serverSession) throws DException { 54 ArrayList indexesList = tableDescriptor.indexesList; 55 QualifiedIdentifier tableName = tableDescriptor.getQualifiedTableName(); 56 if (indexesList != null) { 57 for (int i = 0, size = indexesList.size(); i < size; i++) { 58 if (SystemTables.isSystemTable(tableName.getIdentifier())) { 59 serverSession.createIndexForSystemTable(tableName, 60 (String ) indexesList.get(i)); 61 } else { 62 serverSession.createIndex(tableName, (String ) indexesList.get(i), true); 63 } 64 } 65 } 66 } 67 68 private void setTableName(TableDescriptor tableDes, 69 _ServerSession currentSession) throws 70 DException { 71 tableDes.table_catalog = _tablename1.getCatalogName(); 72 tableDes.table_schema = _tablename1.getSchemaName(); 73 tableDes.table_name = _tablename1.getTableName(); 74 if (tableDes.table_catalog == null) { 75 tableDes.table_catalog = currentSession.getCurrentCatalog(); 76 } 77 if (tableDes.table_schema == null) { 78 tableDes.table_schema = currentSession.getCurrentSchema(); 79 } 80 try { 81 tableDes.load(currentSession); 82 } catch (DException ex) { 83 throw new DException("DSE7008", 84 new Object [] {tableDes.getQualifiedTableName(). 85 getIdentifier()}); 86 } 87 } 88 89 private void checkTableType(TableDescriptor tableDescriptor) throws 90 DException { 91 if (tableDescriptor.table_type.equalsIgnoreCase(SqlKeywords.VIEW)) { 92 throw new DException("DSE962", null); 93 } 94 } 95 96 public Object clone() throws CloneNotSupportedException { 97 return this; 98 } 99 100 public String toString() { 101 StringBuffer sb = new StringBuffer (); 102 sb.append(" "); 103 sb.append(_SRESERVEDWORD12065439223); 104 sb.append(" "); 105 sb.append(_SRESERVEDWORD12065439222); 106 sb.append(" "); 107 sb.append(_tablename1); 108 sb.append(" "); 109 sb.append(_altertableaction0); 110 return sb.toString(); 111 } 112 } 113 | Popular Tags |