| 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 RoutinePrivilegeDescriptor extends PrivilegeDescriptor { 13 14 public String privilege_type; 15 16 public RoutinePrivilegeDescriptor() throws DException { 17 } 18 19 public RoutinePrivilegeDescriptor(RoutinePrivilegeDescriptor rpd) throws DException { 20 object_catalog = (rpd.object_catalog == null) 21 ? null : rpd.object_catalog.toString(); 22 object_name = (rpd.object_name == null) 23 ? null : rpd.object_name.toString(); 24 object_schema = (rpd.object_schema == null) 25 ? null : rpd.object_schema.toString(); 26 privilege_type = (rpd.privilege_type == null) 27 ? null : rpd.privilege_type.toString(); 28 grantee = (rpd.grantee == null) ? null : rpd.grantee.toString(); 29 grantor = (rpd.grantor == null) ? null : rpd.grantor.toString(); 30 is_grantable = (rpd.is_grantable == null) 31 ? null : rpd.is_grantable.toString(); 32 } 33 34 public int hashCode() { 35 return privilege_type.toUpperCase().hashCode() * 3 36 + getGrantee().toUpperCase().hashCode() * 5 37 + getGrantor().toUpperCase().hashCode() * 7 38 + object_catalog.toUpperCase().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 RoutinePrivilegeDescriptor)) { 45 return false; 46 } 47 RoutinePrivilegeDescriptor pd = (RoutinePrivilegeDescriptor) temp; 48 return ( ( (privilege_type == null) && (pd.privilege_type == null)) || privilege_type.equalsIgnoreCase(pd.privilege_type)) 49 && ( ( (getGrantee() == null) && (pd.getGrantee() == null)) || getGrantee().equalsIgnoreCase(pd.getGrantee())) 50 && ( ( (getGrantor() == null) && (pd.getGrantor() == null)) || getGrantor().equalsIgnoreCase(pd.getGrantor())) 51 && ( ( (object_catalog == null) && (pd.object_catalog == null)) || object_catalog.equalsIgnoreCase(pd.object_catalog)) 52 && ( ( (object_schema == null) && (pd.object_schema == null)) || object_schema.equalsIgnoreCase(pd.object_schema)) 53 && ( ( (object_name == null) && (pd.object_name == null)) || object_name.equalsIgnoreCase(pd.object_name)) 54 && ( ( (is_grantable == null) && (pd.is_grantable == null)) || is_grantable.equalsIgnoreCase(pd.is_grantable)); 55 } 56 57 public void delete(_ServerSession serverSession) throws DException { 58 String bve = "GRANTOR=? and GRANTEE=? and SPECIFIC_CATALOG=? and SPECIFIC_SCHEMA=? and SPECIFIC_NAME=? and PRIVILEGE_TYPE=?"; 59 _ServerSession globalSession = serverSession.getGlobalSession(); 60 booleanvalueexpression condition = ConditionParser.parseCondition(bve, globalSession, SqlSchemaConstants.routine_privileges_TableName); 61 super.delete(serverSession, SqlSchemaConstants.routine_privileges_TableName, condition, new Object [] {grantor, grantee, object_catalog, object_schema, object_name, privilege_type}); 62 } 63 64 public void load(_ServerSession serverSession) throws DException { 65 String clause = "select is_grantable from " + SqlSchemaConstants.routine_privileges_TableName 66 + " where grantor = ? and grantee = ? and specific_catalog = ? and specific_schema= ? and specific_name = ? and privilege_type = ? "; 67 _SelectQueryIterator iter = SqlSchemaConstants.getIterator(serverSession, clause, new Object [] {grantor, grantee, object_catalog, object_schema, object_name, privilege_type}); 68 if (iter.first()) { 69 Object [] obj = (Object []) iter.getObject(); 70 is_grantable = (String ) obj[0]; 71 } else { 72 throw new DException("DSE723", null); 73 } 74 } 75 76 public void save(_ServerSession serverSession) throws DException { 77 Object [] parameters = new Object [] {grantor, 78 grantee, 79 object_catalog, 80 object_schema, 81 object_name, 82 privilege_type, 83 is_grantable 84 }; 85 try { 86 SqlSchemaConstants.insert(serverSession, SystemTables.routine_privileges_TableName, null, parameters); 87 } catch (PrimaryConstraintException de) { 88 DException tde = new DException("DSE1149", new Object [] {privilege_type, grantor, grantee, getName()}); 89 throw tde; 90 } catch (SizeMisMatchException de) { 91 if (de.getDseCode().equals("DSE773")) { 92 DException tde = new DException("DSE8103", null); 93 throw tde; 94 } 95 } catch (DException de) { 96 if (de.getDseCode().equals("DSE1255")) { 97 DException tde = new DException("DSE1149", new Object [] {privilege_type, grantor, grantee, getName()}); 98 throw tde; 99 } 100 if (de.getDseCode().equals("DSE773")) { 101 DException tde = new DException("DSE8103", null); 102 throw tde; 103 } 104 throw de; 105 } 106 } 107 108 public void loadDataFromRecord(_SelectQueryIterator iter) throws DException { 109 Object [] obj = (Object []) iter.getObject(); 110 grantor = obj[SystemTablesFields.routineprivilege_grantor]; 111 grantee = obj[SystemTablesFields.routineprivilege_grantee]; 112 object_catalog = (String ) obj[SystemTablesFields.routineprivilege_specific_catalog]; 113 object_schema = (String ) obj[SystemTablesFields.routineprivilege_specific_schema]; 114 object_name = (String ) obj[SystemTablesFields.routineprivilege_specific_name]; 115 privilege_type = (String ) obj[SystemTablesFields.routineprivilege_privilege_type]; 116 is_grantable = (String ) obj[SystemTablesFields.routineprivilege_is_grantable]; 117 } 118 119 public int getType() throws DException { 120 return 0; 121 } 122 123 private String getName() { 124 return new StringBuffer ().append(object_catalog).append(".").append(object_schema).append(".").append(object_name).toString(); 125 } 126 127 public int getDescriptorType() { 128 return ROUTINE_PRIVILEGES_DESCRIPTOR; 129 } 130 131 public void updateIsGrantableValue(_ServerSession serversession, String isGrantable) throws DException { 132 String bve = "GRANTOR=? and GRANTEE=? and SPECIFIC_CATALOG=? and SPECIFIC_SCHEMA=? and SPECIFIC_NAME=? and PRIVILEGE_TYPE=?"; 133 _ServerSession globalSession = serversession.getGlobalSession(); 134 booleanvalueexpression condition = ConditionParser.parseCondition(bve, globalSession, SqlSchemaConstants.routine_privileges_TableName); 135 super.update(serversession, SystemTables.routine_privileges_TableName, condition, 136 new Object [] {grantor, grantee, object_catalog, object_schema, object_name, privilege_type} 137 , 138 new Object [] {isGrantable} 139 , 140 new int[] {SystemTablesFields.routineprivilege_is_grantable}); 141 } 142 } 143 | Popular Tags |