Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / sql / compile / LockTableNode.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/compile/LockTableNode.java
new file mode 100644 (file)
index 0000000..afb8934
--- /dev/null
@@ -0,0 +1,178 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.LockTableNode\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to you under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package        org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.sql.compile.CompilerContext;\r
+import org.apache.derby.iapi.sql.conn.Authorizer;\r
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+\r
+/**\r
+ * A LockTableNode is the root of a QueryTree that represents a LOCK TABLE command:\r
+ *     LOCK TABLE <TableName> IN SHARE/EXCLUSIVE MODE\r
+ *\r
+ */\r
+\r
+public class LockTableNode extends MiscellaneousStatementNode\r
+{\r
+       private TableName       tableName;\r
+       private boolean         exclusiveMode;\r
+       private long            conglomerateNumber;\r
+       private TableDescriptor                 lockTableDescriptor;\r
+\r
+       /**\r
+        * Initializer for LockTableNode\r
+        *\r
+        * @param tableName             The table to lock\r
+        * @param exclusiveMode boolean, whether or not to get an exclusive lock.\r
+        */\r
+       public void init(Object tableName, Object exclusiveMode)\r
+       {\r
+               this.tableName = (TableName) tableName;\r
+               this.exclusiveMode = ((Boolean) exclusiveMode).booleanValue();\r
+       }\r
+\r
+       /**\r
+        * Convert this object to a String.  See comments in QueryTreeNode.java\r
+        * for how this should be done for tree printing.\r
+        *\r
+        * @return      This object as a String\r
+        */\r
+\r
+       public String toString()\r
+       {\r
+               if (SanityManager.DEBUG)\r
+               {\r
+                       return "tableName: " + tableName + "\n" +\r
+                               "exclusiveMode: " + exclusiveMode + "\n" +\r
+                               "conglomerateNumber: " + conglomerateNumber + "\n" +\r
+                               super.toString();\r
+               }\r
+               else\r
+               {\r
+                       return "";\r
+               }\r
+       }\r
+\r
+       public String statementToString()\r
+       {\r
+               return "LOCK TABLE";\r
+       }\r
+\r
+       /**\r
+        * Bind this LockTableNode.  This means looking up the table,\r
+        * verifying it exists and getting the heap conglomerate number.\r
+        *\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+\r
+       public void bindStatement() throws StandardException\r
+       {\r
+               CompilerContext                 cc = getCompilerContext();\r
+               ConglomerateDescriptor  cd;\r
+               DataDictionary                  dd = getDataDictionary();\r
+               SchemaDescriptor                sd;\r
+\r
+               String schemaName = tableName.getSchemaName();\r
+               sd = getSchemaDescriptor(schemaName);\r
+\r
+               // Users are not allowed to lock system tables\r
+               if (sd.isSystemSchema())\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_NO_USER_DDL_IN_SYSTEM_SCHEMA, \r
+                                                       statementToString(), schemaName);\r
+               }\r
+\r
+               lockTableDescriptor = getTableDescriptor(tableName.getTableName(), sd);\r
+\r
+               if (lockTableDescriptor == null)\r
+               {\r
+                       // Check if the reference is for a synonym.\r
+                       TableName synonymTab = resolveTableToSynonym(tableName);\r
+                       if (synonymTab == null)\r
+                               throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);\r
+                       tableName = synonymTab;\r
+                       sd = getSchemaDescriptor(tableName.getSchemaName());\r
+\r
+                       lockTableDescriptor = getTableDescriptor(synonymTab.getTableName(), sd);\r
+                       if (lockTableDescriptor == null)\r
+                               throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, tableName);\r
+               }\r
+\r
+               //throw an exception if user is attempting to lock a temporary table\r
+               if (lockTableDescriptor.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE)\r
+               {\r
+                               throw StandardException.newException(SQLState.LANG_NOT_ALLOWED_FOR_DECLARED_GLOBAL_TEMP_TABLE);\r
+               }\r
+\r
+               conglomerateNumber = lockTableDescriptor.getHeapConglomerateId();\r
+\r
+               /* Get the base conglomerate descriptor */\r
+               cd = lockTableDescriptor.getConglomerateDescriptor(conglomerateNumber);\r
+\r
+               /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */\r
+               cc.createDependency(lockTableDescriptor);\r
+               cc.createDependency(cd);\r
+\r
+               if (isPrivilegeCollectionRequired())\r
+               {\r
+                       // need SELECT privilege to perform lock table statement.\r
+                       cc.pushCurrentPrivType(Authorizer.SELECT_PRIV);\r
+                       cc.addRequiredTablePriv(lockTableDescriptor);\r
+                       cc.popCurrentPrivType();\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Return true if the node references SESSION schema tables (temporary or permanent)\r
+        *\r
+        * @return      true if references SESSION schema tables, else false\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       public boolean referencesSessionSchema()\r
+               throws StandardException\r
+       {\r
+               //If lock table is on a SESSION schema table, then return true. \r
+               return isSessionSchema(lockTableDescriptor.getSchemaName());\r
+       }\r
+\r
+       /**\r
+        * Create the Constant information that will drive the guts of Execution.\r
+        *\r
+        * @exception StandardException         Thrown on failure\r
+        */\r
+       public ConstantAction   makeConstantAction() throws StandardException\r
+       {\r
+               return getGenericConstantActionFactory().getLockTableConstantAction(\r
+                                               tableName.getFullTableName(),\r
+                                               conglomerateNumber,\r
+                                               exclusiveMode);\r
+       }\r
+}\r