1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors; 2 3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem.*; 6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 7 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 8 import com.daffodilwoods.daffodildb.server.sql99.utils.parser.*; 9 import com.daffodilwoods.database.general.*; 10 import com.daffodilwoods.database.resource.*; 11 12 public class UsagePrivilegesDescriptor extends PrivilegeDescriptor { 13 14 public String object_type; 15 16 public UsagePrivilegesDescriptor() throws DException { 17 } 18 19 public UsagePrivilegesDescriptor(UsagePrivilegesDescriptor upd) throws DException { 20 object_catalog = (upd.object_catalog == null) 21 ? null : upd.object_catalog.toString(); 22 object_name = (upd.object_name == null) 23 ? null : upd.object_name.toString(); 24 object_schema = (upd.object_schema == null) 25 ? null : upd.object_schema.toString(); 26 object_type = (upd.object_type == null) 27 ? null : upd.object_type; 28 grantee = (upd.grantee == null) ? null : upd.grantee.toString(); 29 grantor = (upd.grantor == null) ? null : upd.grantor.toString(); 30 is_grantable = (upd.is_grantable == null) 31 ? null : upd.is_grantable.toString(); 32 } 33 34 public int hashCode() { 35 return object_type.toUpperCase().hashCode() * 3 36 + getGrantee().toUpperCase().hashCode() * 5 37 + getGrantor().toUpperCase().hashCode() * 7 38 + object_catalog.toUpperCase().hashCode() * 11 39 + object_schema.toUpperCase().hashCode() * 13 40 + object_name.toUpperCase().hashCode() * 17; 41 } 42 43 public boolean equals(Object temp) { 44 if (! (temp instanceof UsagePrivilegesDescriptor)) { 45 return false; 46 } 47 48 UsagePrivilegesDescriptor pd = (UsagePrivilegesDescriptor) temp; 49 return ( ( (object_type == null) && (pd.object_type == null)) || object_type.equalsIgnoreCase(pd.object_type)) 50 && ( ( (getGrantee() == null) && (pd.getGrantee() == null)) || getGrantee().equalsIgnoreCase(pd.getGrantee())) 51 && ( ( (getGrantor() == null) && (pd.getGrantor() == null)) || getGrantor().equalsIgnoreCase(pd.getGrantor())) 52 && ( ( (object_catalog == null) && (pd.object_catalog == null)) || object_catalog.equalsIgnoreCase(pd.object_catalog)) 53 && ( ( (object_schema == null) && (pd.object_schema == null)) || object_schema.equalsIgnoreCase(pd.object_schema)) 54 && ( ( (object_name == null) && (pd.object_name == null)) || object_name.equalsIgnoreCase(pd.object_name)) 55 && ( ( (is_grantable == null) && (pd.is_grantable == null)) || is_grantable.equalsIgnoreCase(pd.is_grantable)); 56 } 57 58 public void save(_ServerSession serverSession) throws DException { 59 Object [] parameters = new Object [] {grantor, grantee, 60 object_catalog, object_schema, object_name, 61 object_type, is_grantable}; 62 63 try { 64 SqlSchemaConstants.insert(serverSession, 65 SqlSchemaConstants.usage_privileges_TableName, null, parameters); 66 } catch (PrimaryConstraintException de) { 67 DException tde = new DException("DSE1148", new Object [] {object_type, grantor, grantee, getName()}); 68 throw tde; 69 } catch (SizeMisMatchException de) { 70 if (de.getDseCode().equals("DSE773")) { 71 DException tde = new DException("DSE8103", null); 72 throw tde; 73 } 74 } catch (DException de) { 75 if (de.getDseCode().equals("DSE1255")) { 76 DException tde = new DException("DSE1148", new Object [] {object_type, grantor, grantee, getName()}); 77 throw tde; 78 } 79 if (de.getDseCode().equals("DSE773")) { 80 DException tde = new DException("DSE8103", null); 81 throw tde; 82 } 83 throw de; 84 } 85 } 86 87 public void load(_ServerSession serverSession) throws DException { 88 String clause = "select is_grantable from " + SqlSchemaConstants.usage_privileges_TableName 89 + " where grantor = ? and grantee = ? and object_catalog = ? " 90 + " and object_schema = ? and object_name = ? and object_type = ? "; 91 92 _SelectQueryIterator iter = SqlSchemaConstants.getIterator(serverSession, clause, new Object [] {grantor, grantee, object_catalog, object_schema, object_name, object_type}); 93 if (!iter.first()) { 94 throw new DException("DSE1046", new Object [] {grantor, grantee, object_catalog, object_schema, object_name, object_type}); 95 } else { 96 Object [] obj = (Object []) iter.getObject(); 97 is_grantable = (String ) obj[0]; 98 } 99 } 100 101 private void loadDataFromRecord(Object [] values) throws DException { 102 grantor = values[SystemTablesFields.usagePrivileges_grantor]; 103 grantee = values[SystemTablesFields.usagePrivileges_grantee]; 104 object_catalog = (String ) values[SystemTablesFields.usagePrivileges_object_catalog]; 105 object_schema = (String ) values[SystemTablesFields.usagePrivileges_object_schema]; 106 object_name = (String ) values[SystemTablesFields.usagePrivileges_object_name]; 107 object_type = (String ) values[SystemTablesFields.usagePrivileges_object_type]; 108 is_grantable = (String ) values[SystemTablesFields.usagePrivileges_is_grantable]; 109 } 110 111 public void loadDataFromRecord(_SelectQueryIterator iter) throws DException { 112 Object [] values = (Object []) iter.getObject(); 113 loadDataFromRecord(values); 114 } 115 116 public void delete(_ServerSession serverSession) throws DException { 117 String bve = "GRANTOR=? and GRANTEE=? and OBJECT_CATALOG=? and OBJECT_SCHEMA=? and OBJECT_NAME=? and OBJECT_TYPE=?"; 118 _ServerSession globalSession = serverSession.getGlobalSession(); 119 booleanvalueexpression condition = ConditionParser.parseCondition(bve, globalSession, SqlSchemaConstants.usage_privileges_TableName); 120 super.delete(serverSession, SqlSchemaConstants.usage_privileges_TableName, condition, new Object [] {grantor, grantee, object_catalog, object_schema, object_name, object_type}); 121 } 122 123 private String getName() { 124 return new StringBuffer ().append(object_catalog).append(".").append( 125 object_schema).append(".").append(object_name).toString(); 126 } 127 128 public int getDescriptorType() { 129 return USAGE_PRIVILEGE_DESCRIPTOR; 130 } 131 132 public void updateIsGrantableValue(_ServerSession serversession, String isGrantable) throws DException { 133 String bve = "GRANTOR=? and GRANTEE=? and OBJECT_CATALOG=? and OBJECT_SCHEMA=? and OBJECT_NAME=? and OBJECT_TYPE=?"; 134 _ServerSession globalSession = serversession.getGlobalSession(); 135 booleanvalueexpression condition = ConditionParser.parseCondition(bve, globalSession, SqlSchemaConstants.usage_privileges_TableName); 136 super.update(serversession, SystemTables.usage_privileges_TableName, condition, 137 new Object [] {grantor, grantee, object_catalog, object_schema, object_name, object_type} 138 , 139 new Object [] {isGrantable} 140 , 141 new int[] {SystemTablesFields.usagePrivileges_is_grantable}); 142 } 143 } 144 | Popular Tags |