1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.services.context.ContextManager; 25 26 import org.apache.derby.iapi.services.compiler.MethodBuilder; 27 28 import org.apache.derby.iapi.services.sanity.SanityManager; 29 30 import org.apache.derby.iapi.error.StandardException; 31 32 import org.apache.derby.iapi.sql.compile.CompilerContext; 33 34 import org.apache.derby.iapi.sql.conn.Authorizer; 35 36 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor; 37 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 38 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 39 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 40 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 41 42 import org.apache.derby.iapi.reference.SQLState; 43 44 import org.apache.derby.iapi.sql.execute.ConstantAction; 45 46 import org.apache.derby.iapi.sql.Activation; 47 import org.apache.derby.iapi.sql.ResultSet; 48 import org.apache.derby.iapi.reference.ClassName; 49 50 import org.apache.derby.impl.sql.compile.ActivationClassBuilder; 51 import org.apache.derby.iapi.services.classfile.VMOpcode; 52 53 59 60 public class LockTableNode extends MiscellaneousStatementNode 61 { 62 private TableName tableName; 63 private boolean exclusiveMode; 64 private long conglomerateNumber; 65 private TableDescriptor lockTableDescriptor; 66 67 73 public void init(Object tableName, Object exclusiveMode) 74 { 75 this.tableName = (TableName) tableName; 76 this.exclusiveMode = ((Boolean ) exclusiveMode).booleanValue(); 77 } 78 79 85 86 public String toString() 87 { 88 if (SanityManager.DEBUG) 89 { 90 return "tableName: " + tableName + "\n" + 91 "exclusiveMode: " + exclusiveMode + "\n" + 92 "conglomerateNumber: " + conglomerateNumber + "\n" + 93 super.toString(); 94 } 95 else 96 { 97 return ""; 98 } 99 } 100 101 public String statementToString() 102 { 103 return "LOCK TABLE"; 104 } 105 106 114 115 public QueryTreeNode bind() throws StandardException 116 { 117 CompilerContext cc = getCompilerContext(); 118 ConglomerateDescriptor cd; 119 DataDictionary dd = getDataDictionary(); 120 SchemaDescriptor sd; 121 122 String schemaName = tableName.getSchemaName(); 123 sd = getSchemaDescriptor(schemaName); 124 125 if (sd.isSystemSchema()) 127 { 128 throw StandardException.newException(SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA, 129 statementToString(), schemaName); 130 } 131 132 lockTableDescriptor = getTableDescriptor(tableName.getTableName(), sd); 133 134 if (lockTableDescriptor == null) 135 { 136 TableName synonymTab = resolveTableToSynonym(tableName); 138 if (synonymTab == null) 139 throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName); 140 tableName = synonymTab; 141 sd = getSchemaDescriptor(tableName.getSchemaName()); 142 143 lockTableDescriptor = getTableDescriptor(synonymTab.getTableName(), sd); 144 if (lockTableDescriptor == null) 145 throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName); 146 } 147 148 if (lockTableDescriptor.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) 150 { 151 throw StandardException.newException(SQLState.LANG_NOT_ALLOWED_FOR_DECLARED_GLOBAL_TEMP_TABLE); 152 } 153 154 conglomerateNumber = lockTableDescriptor.getHeapConglomerateId(); 155 156 157 cd = lockTableDescriptor.getConglomerateDescriptor(conglomerateNumber); 158 159 160 cc.createDependency(lockTableDescriptor); 161 cc.createDependency(cd); 162 163 if (isPrivilegeCollectionRequired()) 164 { 165 cc.pushCurrentPrivType(Authorizer.SELECT_PRIV); 167 cc.addRequiredTablePriv(lockTableDescriptor); 168 cc.popCurrentPrivType(); 169 } 170 171 return this; 172 } 173 174 181 public boolean referencesSessionSchema() 182 throws StandardException 183 { 184 return isSessionSchema(lockTableDescriptor.getSchemaName()); 186 } 187 188 193 public ConstantAction makeConstantAction() throws StandardException 194 { 195 return getGenericConstantActionFactory().getLockTableConstantAction( 196 tableName.getFullTableName(), 197 conglomerateNumber, 198 exclusiveMode); 199 } 200 } 201 | Popular Tags |