1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.sql.execute.ConstantAction; 25 26 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 27 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 28 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptor; 29 import org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList; 30 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 31 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 32 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor; 33 import org.apache.derby.iapi.sql.depend.DependencyManager; 34 import org.apache.derby.iapi.store.access.TransactionController; 35 36 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 37 38 import org.apache.derby.iapi.sql.depend.Provider; 39 import org.apache.derby.iapi.sql.depend.ProviderInfo; 40 41 import org.apache.derby.iapi.reference.SQLState; 42 43 import org.apache.derby.iapi.sql.Activation; 44 45 import org.apache.derby.iapi.error.StandardException; 46 47 import org.apache.derby.iapi.services.sanity.SanityManager; 48 49 import org.apache.derby.catalog.UUID; 50 51 57 58 class CreateViewConstantAction extends DDLConstantAction 59 { 60 61 private final String tableName; 62 private final String schemaName; 63 private final String viewText; 64 private final int tableType; 65 private final int checkOption; 66 private final ColumnInfo[] columnInfo; 67 private final ProviderInfo[] providerInfo; 68 private final UUID compSchemaId; 69 70 84 CreateViewConstantAction( 85 String schemaName, 86 String tableName, 87 int tableType, 88 String viewText, 89 int checkOption, 90 ColumnInfo[] columnInfo, 91 ProviderInfo[] providerInfo, 92 UUID compSchemaId) 93 { 94 this.schemaName = schemaName; 95 this.tableName = tableName; 96 this.tableType = tableType; 97 this.viewText = viewText; 98 this.checkOption = checkOption; 99 this.columnInfo = columnInfo; 100 this.providerInfo = providerInfo; 101 this.compSchemaId = compSchemaId; 102 103 if (SanityManager.DEBUG) 104 { 105 SanityManager.ASSERT(schemaName != null, "Schema name is null"); 106 } 107 } 108 109 111 public String toString() 112 { 113 return constructToString("CREATE VIEW ", tableName); 114 } 115 116 118 119 126 public void executeConstantAction( Activation activation ) 127 throws StandardException 128 { 129 TableDescriptor td; 130 UUID toid; 131 SchemaDescriptor schemaDescriptor; 132 ColumnDescriptor columnDescriptor; 133 ViewDescriptor vd; 134 135 LanguageConnectionContext lcc = activation.getLanguageConnectionContext(); 136 DataDictionary dd = lcc.getDataDictionary(); 137 DependencyManager dm = dd.getDependencyManager(); 138 TransactionController tc = lcc.getTransactionExecute(); 139 140 149 dd.startWriting(lcc); 150 151 SchemaDescriptor sd = DDLConstantAction.getSchemaDescriptorForCreate(dd, activation, schemaName); 152 153 156 DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator(); 157 td = ddg.newTableDescriptor(tableName, 158 sd, 159 tableType, 160 TableDescriptor.ROW_LOCK_GRANULARITY); 161 162 dd.addDescriptor(td, sd, DataDictionary.SYSTABLES_CATALOG_NUM, false, tc); 163 toid = td.getUUID(); 164 165 ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnInfo.length]; 167 int index = 1; 168 for (int ix = 0; ix < columnInfo.length; ix++) 169 { 170 columnDescriptor = new ColumnDescriptor( 171 columnInfo[ix].name, 172 index++, 173 columnInfo[ix].dataType, 174 columnInfo[ix].defaultValue, 175 columnInfo[ix].defaultInfo, 176 td, 177 (UUID) null, 178 columnInfo[ix].autoincStart, 179 columnInfo[ix].autoincInc 180 ); 181 cdlArray[ix] = columnDescriptor; 182 } 183 184 dd.addDescriptorArray(cdlArray, td, 185 DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc); 186 187 ColumnDescriptorList cdl = td.getColumnDescriptorList(); 189 for (int i = 0; i < cdlArray.length; i++) 190 cdl.add(cdlArray[i]); 191 192 193 vd = ddg.newViewDescriptor(toid, tableName, viewText, 194 checkOption, 195 (compSchemaId == null) ? 196 lcc.getDefaultSchema().getUUID() : 197 compSchemaId); 198 199 for (int ix = 0; ix < providerInfo.length; ix++) 200 { 201 202 try 203 { 204 Provider provider = (Provider) providerInfo[ix]. 205 getDependableFinder(). 206 getDependable( 207 providerInfo[ix].getObjectId()); 208 if (provider == null) { 210 throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, "OBJECT", providerInfo[ix].getObjectId()); 211 } 212 dm.addDependency(vd, provider, lcc.getContextManager()); 213 } 214 catch(java.sql.SQLException te) 215 { 216 throw StandardException.plainWrapException(te); 218 } 219 } 220 storeViewTriggerDependenciesOnPrivileges(activation, vd); 222 223 dd.addDescriptor(vd, sd, DataDictionary.SYSVIEWS_CATALOG_NUM, true, tc); 224 } 225 } 226 | Popular Tags |