Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / iapi / sql / dictionary / SchemaDescriptor.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/sql/dictionary/SchemaDescriptor.java
new file mode 100644 (file)
index 0000000..6f27f26
--- /dev/null
@@ -0,0 +1,444 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.sql.dictionary.SchemaDescriptor\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.iapi.sql.dictionary;\r
+\r
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;\r
+import org.apache.derby.iapi.sql.depend.DependencyManager;\r
+import org.apache.derby.iapi.sql.depend.Provider;\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+import org.apache.derby.catalog.DependableFinder;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.reference.Property;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+import org.apache.derby.catalog.UUID;\r
+import org.apache.derby.catalog.Dependable;\r
+\r
+/**\r
+ * This class represents a schema descriptor\r
+ *\r
+ * @version 0.1\r
+ */\r
+\r
+public final class SchemaDescriptor extends TupleDescriptor \r
+       implements UniqueTupleDescriptor, Provider\r
+{\r
+       \r
+       /*\r
+       ** When we boot, we put the system tables in\r
+       ** in 'SYS', owned by user DBA.\r
+       ** '92 talks about two system schemas:\r
+       **\r
+       **              Information Schema: literal name is \r
+       **              SYS.  This schema contains\r
+       **              a series of well defined views that reference\r
+       **              actual base tables from the Definition Schema.\r
+       **\r
+       **              Definition Schema:  literal name is\r
+       **              DEFINITION_SCHEMA.  This schema contains \r
+       **              system tables that can be in any shape or\r
+       **              form.\r
+       **      \r
+       ** SYS is owned by SA_USER_NAME (or DBA).\r
+       */\r
+    /**\r
+     * STD_SYSTEM_SCHEMA_NAME is the name of the system schema in databases that\r
+     * use ANSI standard identifier casing. \r
+     *\r
+     * See org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext#getSystemSchemaName\r
+     */\r
+    public static final        String  STD_SYSTEM_SCHEMA_NAME      = "SYS";\r
+\r
+    public static final        String  IBM_SYSTEM_SCHEMA_NAME      = "SYSIBM";\r
+\r
+    /*\r
+     * Names of system schemas.\r
+     * The following schemas exist in a standard empty DB2 database.  For\r
+     * now creating them in the Derby database but not actually putting\r
+     * any objects in them.  Users should not be able to create any objects\r
+     * in these schemas.\r
+     **/\r
+    public static final        String  IBM_SYSTEM_CAT_SCHEMA_NAME      = "SYSCAT";\r
+    public static final        String  IBM_SYSTEM_FUN_SCHEMA_NAME      = "SYSFUN";\r
+    public static final        String  IBM_SYSTEM_PROC_SCHEMA_NAME     = "SYSPROC";\r
+    public static final        String  IBM_SYSTEM_STAT_SCHEMA_NAME     = "SYSSTAT";\r
+    public static final        String  IBM_SYSTEM_NULLID_SCHEMA_NAME   = "NULLID";\r
+\r
+    /**\r
+     * This schema is used for jar handling procedures.\r
+     **/\r
+    public static final        String  STD_SQLJ_SCHEMA_NAME      = "SQLJ";\r
+     \r
+    /**\r
+     * This schema is for Derby specific system diagnostic procedures and \r
+     * functions which are not available in DB2.  \r
+     **/\r
+    public static final        String  STD_SYSTEM_DIAG_SCHEMA_NAME     = "SYSCS_DIAG";\r
+\r
+    /**\r
+     * This schema is for Derby specific system diagnostic procedures and \r
+     * functions which are not available in DB2.  \r
+     **/\r
+    public static final        String  STD_SYSTEM_UTIL_SCHEMA_NAME     = "SYSCS_UTIL";\r
+\r
+    /**\r
+     * STD_DEFAULT_SCHEMA_NAME is the name of the default schema in databases \r
+     * that use ANSI standard identifier casing. \r
+     *\r
+     * See org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext#getDefaultSchemaName\r
+     */\r
+    public     static  final   String  STD_DEFAULT_SCHEMA_NAME = Property.DEFAULT_USER_NAME;\r
+\r
+\r
+    /**\r
+     * UUID's used as key's in the SYSSCHEMA catalog for the system schema's\r
+     **/\r
+    public static final String SYSCAT_SCHEMA_UUID      =  \r
+        "c013800d-00fb-2641-07ec-000000134f30";\r
+    public static final String SYSFUN_SCHEMA_UUID      =  \r
+        "c013800d-00fb-2642-07ec-000000134f30";\r
+    public static final String SYSPROC_SCHEMA_UUID     =  \r
+        "c013800d-00fb-2643-07ec-000000134f30";\r
+    public static final String SYSSTAT_SCHEMA_UUID     =  \r
+        "c013800d-00fb-2644-07ec-000000134f30";\r
+    public static final String SYSCS_DIAG_SCHEMA_UUID  =  \r
+        "c013800d-00fb-2646-07ec-000000134f30";\r
+    public static final String SYSCS_UTIL_SCHEMA_UUID  =  \r
+        "c013800d-00fb-2649-07ec-000000134f30";\r
+    public static final String NULLID_SCHEMA_UUID  =  \r
+        "c013800d-00fb-2647-07ec-000000134f30";\r
+    public static final String SQLJ_SCHEMA_UUID  =  \r
+        "c013800d-00fb-2648-07ec-000000134f30";\r
+       public static final     String SYSTEM_SCHEMA_UUID =  \r
+        "8000000d-00d0-fd77-3ed8-000a0a0b1900";\r
+       public static final     String SYSIBM_SCHEMA_UUID =  \r
+        "c013800d-00f8-5b53-28a9-00000019ed88";\r
+       public static final     String DEFAULT_SCHEMA_UUID = \r
+        "80000000-00d2-b38f-4cda-000a0a412c00";\r
+\r
+\r
+\r
+    public     static  final   String  STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME = "SESSION";\r
+       public  static  final   String  DEFAULT_USER_NAME = Property.DEFAULT_USER_NAME;\r
+       public  static  final   String  SA_USER_NAME = "DBA";\r
+\r
+\r
+       /** the public interface for this system:\r
+               <ol>\r
+               <li>public String getSchemaName();\r
+               <li>public String getAuthorizationId();\r
+               <li>public void setUUID(UUID uuid);\r
+               <li>public boolean isSystemSchema();\r
+               </ol>\r
+       */\r
+\r
+       //// Implementation\r
+       private final String                    name;\r
+       private UUID                    oid;\r
+       private final String                    aid;\r
+\r
+    private final boolean isSystem;\r
+    private final boolean isSYSIBM;\r
+    \r
+    /**\r
+     * For system schemas, the only possible value for collation type is\r
+     * UCS_BASIC. For user schemas, the collation type can be UCS_BASIC or \r
+     * TERRITORY_BASED.\r
+     */\r
+    private int collationType;\r
+\r
+       /**\r
+        * Constructor for a SchemaDescriptor.\r
+        *\r
+     * @param dataDictionary\r
+        * @param name          The schema descriptor for this table.\r
+        * @param oid           The object id\r
+        * @param aid           The authorizatin id\r
+     * @param isSystem     boolean, true iff this is a system schema, like SYS,\r
+     *                      SYSIBM, SYSCAT, SYSFUN, ....\r
+        */\r
+       public SchemaDescriptor(\r
+    DataDictionary  dataDictionary, \r
+    String          name,\r
+    String          aid, \r
+    UUID            oid,\r
+    boolean         isSystem)\r
+       {\r
+               super (dataDictionary);\r
+\r
+               this.name = name;\r
+               this.aid = aid;\r
+               this.oid = oid;\r
+        this.isSystem = isSystem;\r
+               isSYSIBM = isSystem && IBM_SYSTEM_SCHEMA_NAME.equals(name);\r
+               if (isSystem)\r
+                       collationType = dataDictionary.getCollationTypeOfSystemSchemas();\r
+               else\r
+                       collationType = dataDictionary.getCollationTypeOfUserSchemas();\r
+       }\r
+\r
+       /**\r
+        * Gets the name of the schema \r
+        *\r
+        * @return      The schema name\r
+        */\r
+       public String   getSchemaName()\r
+       {\r
+               return name;\r
+       }\r
+\r
+       /**\r
+        * Gets the authorization id of the schema \r
+        *\r
+        * @return      Authorization id\r
+        *              lives in.\r
+        */\r
+       public String getAuthorizationId()\r
+       {\r
+               return aid;\r
+       }\r
+\r
+       /**\r
+        * Gets the oid of the schema \r
+        *\r
+        * @return      An oid\r
+        */\r
+       public UUID     getUUID()\r
+       {\r
+               return oid;\r
+       }\r
+\r
+       /**\r
+        * Sets the oid of the schema \r
+        *\r
+        * @param oid   The object id\r
+        *\r
+        */\r
+       public void     setUUID(UUID oid)\r
+       {\r
+               this.oid = oid;\r
+       }\r
+\r
+       /**\r
+        * Returns the collation type associated with this schema \r
+        *\r
+        * @return collation type\r
+        *\r
+        */\r
+       public int      getCollationType()\r
+       {\r
+               return collationType;\r
+       }\r
+\r
+       //\r
+       // Provider interface\r
+       //\r
+\r
+       /**             \r
+               @return the stored form of this provider\r
+\r
+                       @see Dependable#getDependableFinder\r
+        */\r
+       public DependableFinder getDependableFinder()\r
+       {\r
+               // Is this OK?\r
+           return      getDependableFinder(StoredFormatIds.SCHEMA_DESCRIPTOR_FINDER_V01_ID);\r
+       }\r
+\r
+       /**\r
+        * Return the name of this Provider.  (Useful for errors.)\r
+        *\r
+        * @return String       The name of this provider.\r
+        */\r
+       public String getObjectName()\r
+       {\r
+               return name;\r
+       }\r
+\r
+       /**\r
+        * Get the provider's UUID \r
+        *\r
+        * @return String       The provider's UUID\r
+        */\r
+       public UUID getObjectID()\r
+       {\r
+               return oid;\r
+       }\r
+\r
+       /**\r
+        * Get the provider's type.\r
+        *\r
+        * @return String               The provider's type.\r
+        */\r
+       public String getClassType()\r
+       {\r
+               return Dependable.SCHEMA;\r
+       }\r
+\r
+       //\r
+       // class interface\r
+       //\r
+\r
+       /**\r
+        * Prints the contents of the SchemaDescriptor\r
+        *\r
+        * @return The contents as a String\r
+        */\r
+       public String toString()\r
+       {\r
+               return name;\r
+       }\r
+\r
+       //      Methods so that we can put SchemaDescriptors on hashed lists\r
+\r
+       /**\r
+         *     Determine if two SchemaDescriptors are the same.\r
+         *\r
+         *     @param  otherObject     other schemadescriptor\r
+         *\r
+         *     @return true if they are the same, false otherwise\r
+         */\r
+\r
+       public boolean equals(Object otherObject)\r
+       {\r
+               if (!(otherObject instanceof SchemaDescriptor))\r
+                       return false;\r
+\r
+               SchemaDescriptor other = (SchemaDescriptor) otherObject;\r
+\r
+               if ((oid != null) && (other.oid != null))\r
+                       return oid.equals( other.oid);\r
+               \r
+               return name.equals(other.name);\r
+       }\r
+\r
+       /**\r
+        * Indicate whether this is a system schema or not\r
+     *\r
+     * Examples of system schema's include: \r
+     *      SYS, SYSIBM, SYSCAT, SYSFUN, SYSPROC, SYSSTAT, and SYSCS_DIAG \r
+        *\r
+        * @return true/false\r
+        */\r
+       public boolean isSystemSchema()\r
+       {\r
+               return(isSystem);\r
+       }\r
+\r
+       /**\r
+        * Indicate whether this is a system schema with grantable routines\r
+        *\r
+        * @return true/false\r
+        */\r
+       public boolean isSchemaWithGrantableRoutines()\r
+       {\r
+               if (!isSystem)\r
+                       return true;\r
+\r
+               if (name.equals(STD_SQLJ_SCHEMA_NAME) || name.equals(STD_SYSTEM_UTIL_SCHEMA_NAME))\r
+                       return true;\r
+\r
+               return false;\r
+       }\r
+\r
+       public boolean isSYSIBM()\r
+       {\r
+               return isSYSIBM;\r
+       }\r
+\r
+       /**\r
+         *     Get a hashcode for this SchemaDescriptor\r
+         *\r
+         *     @return hashcode\r
+         */\r
+       public int hashCode()\r
+       {\r
+               return  oid.hashCode();\r
+       }\r
+       \r
+       /** @see TupleDescriptor#getDescriptorName */\r
+       public String getDescriptorName() \r
+       { \r
+               return name;\r
+       }\r
+       \r
+       /** @see TupleDescriptor#getDescriptorType */\r
+       public String getDescriptorType()\r
+       {\r
+               return "Schema";\r
+    }\r
+    \r
+    /**\r
+     * Drop this schema.\r
+     * Drops the schema if it is empty. If the schema was\r
+     * the current default then the current default will be\r
+     * reset through the language connection context.\r
+     * @throws StandardException Schema could not be dropped.\r
+     */\r
+       public void drop(LanguageConnectionContext lcc) throws StandardException\r
+       {\r
+        DataDictionary dd = getDataDictionary();\r
+        DependencyManager dm = dd.getDependencyManager();\r
+        TransactionController tc = lcc.getTransactionExecute();\r
+       \r
+           //If user is attempting to drop SESSION schema and there is no physical SESSION schema, then throw an exception\r
+           //Need to handle it this special way is because SESSION schema is also used for temporary tables. If there is no\r
+           //physical SESSION schema, we internally generate an in-memory SESSION schema in order to support temporary tables\r
+           //But there is no way for the user to access that in-memory SESSION schema. Following if will be true if there is\r
+           //no physical SESSION schema and hence getSchemaDescriptor has returned an in-memory SESSION schema\r
+           if (getSchemaName().equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME)\r
+                && (getUUID() == null))\r
+               throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, getSchemaName());\r
+           \r
+           /*\r
+            ** Make sure the schema is empty.\r
+            ** In the future we want to drop everything\r
+            ** in the schema if it is CASCADE.\r
+            */\r
+           if (!dd.isSchemaEmpty(this))\r
+           {\r
+               throw StandardException.newException(SQLState.LANG_SCHEMA_NOT_EMPTY, getSchemaName());\r
+           } \r
+           \r
+           /* Prepare all dependents to invalidate.  (This is there chance\r
+            * to say that they can't be invalidated.  For example, an open\r
+            * cursor referencing a table/view that the user is attempting to\r
+            * drop.) If no one objects, then invalidate any dependent objects.\r
+            */\r
+           dm.invalidateFor(this, DependencyManager.DROP_SCHEMA, lcc);\r
+           \r
+           dd.dropSchemaDescriptor(getSchemaName(), tc);\r
+           \r
+           /*\r
+            ** If we have dropped the current default schema,\r
+            ** then we will set the default to null.  The\r
+            ** LCC is free to set the new default schema to \r
+            ** some system defined default.\r
+            */\r
+           SchemaDescriptor currentDefault = lcc.getDefaultSchema();\r
+           if ((currentDefault != null) &&\r
+                getSchemaName().equals(currentDefault.getSchemaName()))\r
+           {\r
+               lcc.setDefaultSchema((SchemaDescriptor)null);\r
+           }        \r
+       }\r
+}\r