1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.loader.ClassInspector; 25 26 import org.apache.derby.iapi.services.context.ContextManager; 27 28 import org.apache.derby.iapi.sql.compile.CompilerContext; 29 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 30 31 import org.apache.derby.iapi.reference.SQLState; 32 import org.apache.derby.iapi.reference.Limits; 33 34 import org.apache.derby.iapi.sql.ResultSet; 35 import org.apache.derby.iapi.sql.execute.ConstantAction; 36 37 import org.apache.derby.iapi.types.TypeId; 38 39 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 40 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 41 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 42 43 import org.apache.derby.iapi.error.StandardException; 44 45 import org.apache.derby.iapi.services.monitor.Monitor; 46 import org.apache.derby.iapi.services.sanity.SanityManager; 47 48 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 49 import org.apache.derby.impl.sql.execute.BaseActivation; 50 51 import org.apache.derby.catalog.AliasInfo; 52 import org.apache.derby.catalog.TypeDescriptor; 53 import org.apache.derby.catalog.types.RoutineAliasInfo; 54 import org.apache.derby.catalog.types.SynonymAliasInfo; 55 56 import java.lang.reflect.Member ; 57 import java.util.Vector ; 58 59 64 65 public class CreateAliasNode extends DDLStatementNode 66 { 67 private String javaClassName; 68 private String methodName; 69 private char aliasType; 70 private boolean delimitedIdentifier; 71 72 private AliasInfo aliasInfo; 73 74 75 88 public void init( 89 Object aliasName, 90 Object targetObject, 91 Object methodName, 92 Object aliasSpecificInfo, 93 Object aliasType, 94 Object delimitedIdentifier) 95 throws StandardException 96 { 97 TableName qn = (TableName) aliasName; 98 this.aliasType = ((Character ) aliasType).charValue(); 99 100 initAndCheck(qn); 101 102 switch (this.aliasType) 103 { 104 case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 105 case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 106 { 107 this.javaClassName = (String ) targetObject; 108 this.methodName = (String ) methodName; 109 this.delimitedIdentifier = 110 ((Boolean ) delimitedIdentifier).booleanValue(); 111 112 124 Object [] routineElements = (Object []) aliasSpecificInfo; 125 Object [] parameters = (Object []) routineElements[0]; 126 int paramCount = ((Vector ) parameters[0]).size(); 127 128 if (this.methodName.indexOf('(') != -1) 134 { 135 getDataDictionary().checkVersion( 136 DataDictionary.DD_VERSION_DERBY_10_1, 137 "EXTERNAL NAME 'class.method(<signature>)'"); 138 139 } 140 141 String [] names = null; 142 TypeDescriptor[] types = null; 143 int[] modes = null; 144 145 if (paramCount > Limits.DB2_MAX_PARAMS_IN_STORED_PROCEDURE) 146 throw StandardException.newException(SQLState.LANG_TOO_MANY_PARAMETERS_FOR_STORED_PROC, 147 String.valueOf(Limits.DB2_MAX_PARAMS_IN_STORED_PROCEDURE), aliasName, String.valueOf(paramCount)); 148 149 if (paramCount != 0) { 150 151 names = new String [paramCount]; 152 ((Vector ) parameters[0]).copyInto(names); 153 154 types = new TypeDescriptor[paramCount]; 155 ((Vector ) parameters[1]).copyInto(types); 156 157 modes = new int[paramCount]; 158 for (int i = 0; i < paramCount; i++) { 159 modes[i] = ((Integer ) (((Vector ) parameters[2]).elementAt(i))).intValue(); 160 161 if (TypeId.getBuiltInTypeId(types[i].getJDBCTypeId()).isLongConcatableTypeId()) 162 throw StandardException.newException(SQLState.LANG_LONG_DATA_TYPE_NOT_ALLOWED, names[i]); 163 164 } 165 166 if (paramCount > 1) { 167 String [] dupNameCheck = new String [paramCount]; 168 System.arraycopy(names, 0, dupNameCheck, 0, paramCount); 169 java.util.Arrays.sort(dupNameCheck); 170 for (int dnc = 1; dnc < dupNameCheck.length; dnc++) { 171 if (dupNameCheck[dnc].equals(dupNameCheck[dnc - 1])) 172 throw StandardException.newException(SQLState.LANG_DB2_DUPLICATE_NAMES, dupNameCheck[dnc], getFullName()); 173 } 174 } 175 } 176 177 Integer drso = (Integer ) routineElements[2]; 178 int drs = drso == null ? 0 : drso.intValue(); 179 180 short sqlAllowed; 181 Short sqlAllowedObject = (Short ) routineElements[6]; 182 if (sqlAllowedObject != null) 183 sqlAllowed = sqlAllowedObject.shortValue(); 184 else 185 sqlAllowed = (this.aliasType == AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR ? 186 RoutineAliasInfo.MODIFIES_SQL_DATA : RoutineAliasInfo.READS_SQL_DATA); 187 188 Boolean calledOnNullInputO = (Boolean ) routineElements[7]; 189 boolean calledOnNullInput; 190 if (calledOnNullInputO == null) 191 calledOnNullInput = true; 192 else 193 calledOnNullInput = calledOnNullInputO.booleanValue(); 194 195 aliasInfo = new RoutineAliasInfo(this.methodName, paramCount, names, types, modes, drs, 196 ((Short ) routineElements[5]).shortValue(), sqlAllowed, calledOnNullInput, (TypeDescriptor) routineElements[8]); 198 199 implicitCreateSchema = true; 200 } 201 break; 202 203 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 204 String targetSchema; 205 implicitCreateSchema = true; 206 TableName t = (TableName) targetObject; 207 if (t.getSchemaName() != null) 208 targetSchema = t.getSchemaName(); 209 else targetSchema = getSchemaDescriptor().getSchemaName(); 210 aliasInfo = new SynonymAliasInfo(targetSchema, t.getTableName()); 211 break; 212 213 default: 214 if (SanityManager.DEBUG) 215 { 216 SanityManager.THROWASSERT( 217 "Unexpected value for aliasType (" + aliasType + ")"); 218 } 219 } 220 } 221 222 public String statementToString() 223 { 224 switch (this.aliasType) 225 { 226 case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 227 return "CREATE PROCEDURE"; 228 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 229 return "CREATE SYNONYM"; 230 default: 231 return "CREATE FUNCTION"; 232 } 233 } 234 235 237 247 248 public QueryTreeNode bind() throws StandardException 249 { 250 if (aliasType != AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR) 253 return this; 254 255 if (isSessionSchema(getSchemaDescriptor().getSchemaName())) 258 throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES); 259 260 String targetSchema = ((SynonymAliasInfo)aliasInfo).getSynonymSchema(); 261 String targetTable = ((SynonymAliasInfo)aliasInfo).getSynonymTable(); 262 if (this.getObjectName().equals(targetSchema, targetTable)) 263 throw StandardException.newException(SQLState.LANG_SYNONYM_CIRCULAR, 264 this.getFullName(), 265 targetSchema+"."+targetTable); 266 267 SchemaDescriptor targetSD = getSchemaDescriptor(targetSchema, false); 268 if ((targetSD != null) && isSessionSchema(targetSD)) 269 throw StandardException.newException(SQLState.LANG_OPERATION_NOT_ALLOWED_ON_SESSION_SCHEMA_TABLES); 270 271 return this; 272 } 273 274 279 public ConstantAction makeConstantAction() throws StandardException 280 { 281 String schemaName; 282 switch (aliasType) { 283 case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 284 case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 285 schemaName = getSchemaDescriptor().getSchemaName(); 286 break; 287 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 288 schemaName = getSchemaDescriptor().getSchemaName(); 289 break; 290 default: 291 schemaName = null; 292 } 293 294 return getGenericConstantActionFactory().getCreateAliasConstantAction( 295 getRelativeName(), 296 schemaName, 297 javaClassName, 298 aliasInfo, 299 aliasType); 300 } 301 } 302 | Popular Tags |