1 21 22 package org.apache.derby.impl.sql.execute; 23 24 25 import org.apache.derby.iapi.sql.execute.ConstantAction; 26 27 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 28 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 29 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 30 import org.apache.derby.iapi.sql.ParameterValueSet; 31 import org.apache.derby.iapi.sql.StatementType; 32 33 import org.apache.derby.iapi.types.DataValueDescriptor; 34 35 import org.apache.derby.iapi.reference.Limits; 36 37 import org.apache.derby.iapi.error.StandardException; 38 39 import org.apache.derby.iapi.sql.Activation; 40 41 import org.apache.derby.iapi.services.sanity.SanityManager; 42 43 import org.apache.derby.iapi.reference.SQLState; 44 45 51 52 class SetSchemaConstantAction extends GenericConstantAction 53 { 54 55 private final String schemaName; 56 private final int type; 57 58 60 66 SetSchemaConstantAction(String schemaName, int type) 67 { 68 this.schemaName = schemaName; 69 this.type = type; 70 } 71 72 78 public String toString() 79 { 80 return "SET SCHEMA " + ((type == StatementType.SET_SCHEMA_USER) ? "USER" : 85 ((type == StatementType.SET_SCHEMA_DYNAMIC && schemaName == null) ? "?" : schemaName)); 86 } 87 88 90 91 98 public void executeConstantAction( Activation activation ) 99 throws StandardException 100 { 101 LanguageConnectionContext lcc; 102 DataDictionary dd; 103 104 lcc = activation.getLanguageConnectionContext(); 106 107 dd = lcc.getDataDictionary(); 108 String thisSchemaName = schemaName; 109 if (type == StatementType.SET_SCHEMA_DYNAMIC) 110 { 111 ParameterValueSet pvs = activation.getParameterValueSet(); 112 DataValueDescriptor dvs = pvs.getParameter(0); 113 thisSchemaName = dvs.getString(); 114 if (thisSchemaName == null || thisSchemaName.length() > Limits.MAX_IDENTIFIER_LENGTH) 116 throw StandardException.newException(SQLState.LANG_DB2_REPLACEMENT_ERROR, "CURRENT SCHEMA"); 117 } 118 else if (type == StatementType.SET_SCHEMA_USER) 119 { 120 thisSchemaName = lcc.getAuthorizationId(); 121 } 122 SchemaDescriptor sd = dd.getSchemaDescriptor(thisSchemaName, null, true); 124 lcc.setDefaultSchema(sd); 125 } 126 } 127 | Popular Tags |