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 / ColPermsDescriptor.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/sql/dictionary/ColPermsDescriptor.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/iapi/sql/dictionary/ColPermsDescriptor.java
new file mode 100644 (file)
index 0000000..a1ddf0a
--- /dev/null
@@ -0,0 +1,172 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor\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.catalog.Dependable;\r
+import org.apache.derby.catalog.DependableFinder;\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.services.io.FormatableBitSet;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+import org.apache.derby.impl.sql.catalog.DDdependableFinder;\r
+\r
+/**\r
+ * This class describes a row in the SYS.SYSCOLPERMS system table, which keeps\r
+ * the column permissions that have been granted but not revoked.\r
+ */\r
+public class ColPermsDescriptor extends PermissionsDescriptor\r
+{\r
+    private UUID tableUUID;\r
+    private String type;\r
+    private FormatableBitSet columns;\r
+    private String tableName;\r
+       \r
+       public ColPermsDescriptor( DataDictionary dd,\r
+                                          String grantee,\r
+                               String grantor,\r
+                               UUID tableUUID,\r
+                               String type,\r
+                               FormatableBitSet columns) throws StandardException\r
+       {\r
+               super (dd, grantee, grantor);\r
+        this.tableUUID = tableUUID;\r
+        this.type = type;\r
+        this.columns = columns;\r
+        //tableUUID can be null only if the constructor with colPermsUUID\r
+        //has been invoked.\r
+        if (tableUUID != null)\r
+               tableName = dd.getTableDescriptor(tableUUID).getName();\r
+       }\r
+\r
+    /**\r
+     * This constructor just initializes the key fields of a ColPermsDescriptor\r
+     */\r
+       public ColPermsDescriptor( DataDictionary dd,\r
+                               String grantee,\r
+                               String grantor,\r
+                               UUID tableUUID,\r
+                               String type) throws StandardException\r
+    {\r
+        this( dd, grantee, grantor, tableUUID, type, (FormatableBitSet) null);\r
+    }           \r
+    \r
+    public ColPermsDescriptor( DataDictionary dd,\r
+            UUID colPermsUUID) throws StandardException\r
+    {\r
+        super(dd,null,null);\r
+        this.oid = colPermsUUID;\r
+       }\r
+    \r
+    public int getCatalogNumber()\r
+    {\r
+        return DataDictionary.SYSCOLPERMS_CATALOG_NUM;\r
+    }\r
+       \r
+       /*----- getter functions for rowfactory ------*/\r
+    public UUID getTableUUID() { return tableUUID;}\r
+    public String getType() { return type;}\r
+    public FormatableBitSet getColumns() { return columns;}\r
+\r
+       public String toString()\r
+       {\r
+               return "colPerms: grantee=" + getGrantee() + \r
+        ",colPermsUUID=" + getUUID() +\r
+                       ",grantor=" + getGrantor() +\r
+          ",tableUUID=" + getTableUUID() +\r
+          ",type=" + getType() +\r
+          ",columns=" + getColumns();\r
+       }               \r
+\r
+       /**\r
+     * @return true iff the key part of this permissions descriptor equals the key part of another permissions\r
+     *         descriptor.\r
+     */\r
+    public boolean equals( Object other)\r
+    {\r
+        if( !( other instanceof ColPermsDescriptor))\r
+            return false;\r
+        ColPermsDescriptor otherColPerms = (ColPermsDescriptor) other;\r
+        return super.keyEquals( otherColPerms) &&\r
+          tableUUID.equals( otherColPerms.tableUUID) &&\r
+          ((type == null) ? (otherColPerms.type == null) : type.equals( otherColPerms.type));\r
+    }\r
+    \r
+    /**\r
+     * @return the hashCode for the key part of this permissions descriptor\r
+     */\r
+    public int hashCode()\r
+    {\r
+       return super.keyHashCode() + tableUUID.hashCode() +\r
+               ((type == null) ? 0 : type.hashCode());\r
+    }\r
+       \r
+       /**\r
+        * @see PermissionsDescriptor#checkOwner\r
+        */\r
+       public boolean checkOwner(String authorizationId) throws StandardException\r
+       {\r
+               TableDescriptor td = getDataDictionary().getTableDescriptor(tableUUID);\r
+               if (td.getSchemaDescriptor().getAuthorizationId().equals(authorizationId))\r
+                       return true;\r
+               else\r
+                       return false;\r
+       }\r
+\r
+       //////////////////////////////////////////////\r
+       //\r
+       // PROVIDER INTERFACE\r
+       //\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 "Column Privilege on " + tableName; \r
+       }\r
+\r
+       /**\r
+        * Get the provider's type.\r
+        *\r
+        * @return char         The provider's type.\r
+        */\r
+       public String getClassType()\r
+       {\r
+               return Dependable.COLUMNS_PERMISSION;\r
+       }\r
+\r
+       /**             \r
+               @return the stored form of this provider\r
+\r
+                       @see Dependable#getDependableFinder\r
+        */\r
+       public DependableFinder getDependableFinder() \r
+       {\r
+           return      new DDdependableFinder(StoredFormatIds.COLUMNS_PERMISSION_FINDER_V01_ID);\r
+       }\r
+\r
+}\r