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.common.*; 7 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 9 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*; 10 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*; 11 import com.daffodilwoods.daffodildb.server.sql99.utils.*; 12 import com.daffodilwoods.daffodildb.server.sql99.utils.parser.*; 13 import com.daffodilwoods.daffodildb.utils.*; 14 import com.daffodilwoods.database.general.*; 15 import com.daffodilwoods.database.resource.*; 16 17 public class RoleAuthorizationDescriptor extends Descriptor { 18 19 private static final String roleAuthQuery = new StringBuffer ().append("select * from ") 20 .append(SqlSchemaConstants.role_authorization_TableName) 21 .append(" where ") 22 .append("role_name = ? ") 23 .append(" and grantee = ? ").toString(); 24 public String role_name; 25 public String grantee; 26 public String grantor; 27 public String is_grantable; 28 29 public RoleAuthorizationDescriptor() throws DException { 30 } 31 32 public void load(_ServerSession serverSession) throws com.daffodilwoods.database.resource.DException { 33 _SelectQueryIterator roleAuthIterator = SqlSchemaConstants.getIterator(serverSession, roleAuthQuery, new Object [] {role_name, grantee}); 34 if (!roleAuthIterator.first()) { 35 throw new DException("DSE875", new Object [] {role_name, grantee}); 36 } else { 37 Object [] obj = (Object []) roleAuthIterator.getObject(); 38 grantor = (String ) obj[SystemTablesFields.roleAuthorization_grantor]; 39 is_grantable = (String ) obj[SystemTablesFields.roleAuthorization_is_grantable]; 40 } 41 } 42 43 public void loadDataFromRecord(_SelectIterator iter) throws DException { 44 Object [] obj = (Object []) iter.getObject(); 45 role_name = (String ) obj[SystemTablesFields.roleAuthorization_role_name]; 46 grantee = (String ) obj[SystemTablesFields.roleAuthorization_grantee]; 47 grantor = (String ) obj[SystemTablesFields.roleAuthorization_grantor]; 48 is_grantable = (String ) obj[3]; } 50 51 public void save(_ServerSession serverSession) throws com.daffodilwoods.database.resource.DException { 52 Object [] parameters = new Object [] {role_name, grantee, grantor, is_grantable}; 53 try { 54 SqlSchemaConstants.insert(serverSession, 55 SqlSchemaConstants.role_authorization_TableName, null, parameters); 56 } catch (PrimaryConstraintException de) { 57 DException tde = new DException("DSE1151", new Object [] {grantee, role_name}); 58 throw tde; 59 } catch (SizeMisMatchException de) { 60 if (de.getDseCode().equals("DSE773")) { 61 DException tde = new DException("DSE8103", null); 62 throw tde; 63 } 64 } catch (DException de) { 65 if (de.getDseCode().equals("DSE1255")) { 66 DException tde = new DException("DSE1151", new Object [] {grantee, role_name}); 67 throw tde; 68 } 69 if (de.getDseCode().equals("DSE773")) { 70 DException tde = new DException("DSE8103", null); 71 throw tde; 72 } 73 throw de; 74 } 75 76 } 77 78 public void delete(_ServerSession serverSession) throws com.daffodilwoods.database.resource.DException { 79 String bve = "ROLE_NAME=? and GRANTEE=?"; 80 _ServerSession globalSession = serverSession.getGlobalSession(); 81 booleanvalueexpression condition = ConditionParser.parseCondition(bve, globalSession, SqlSchemaConstants.role_authorization_TableName); 82 super.delete(serverSession, SqlSchemaConstants.role_authorization_TableName, condition, new Object [] {role_name, grantee}); 83 } 84 85 public int getDescriptorType() { 86 return ROLE_AUTHORIZATION_DESCRIPTOR; 87 } 88 89 public void updateIsGrantableValue(_ServerSession serverSession, String isGrantable) throws DException { 90 TableDetails tableDetail = new TableDetails(); 91 tableDetail.setTableName(SystemTables.role_authorization_TableName.getTableName()); 92 _ServerSession systemSession = serverSession.getSystemServerSession(); 93 _ServerSession globalSession = serverSession.getGlobalSession(); 94 String bve = " ROLE_NAME=? and GRANTEE=? "; 95 booleanvalueexpression condition = ConditionParser.parseCondition(bve, serverSession, SystemTables.role_authorization_TableName); 96 ConditionSingleTableExecuter conSingTE = new ConditionSingleTableExecuter(null, 97 tableDetail, globalSession, condition, null); 98 _Iterator iter = globalSession.getInternalIterator(SystemTables.role_authorization_TableName, conSingTE); 99 _Reference[] ref = condition.getReferences(new TableDetails[] {tableDetail}); 100 iter.setConditionVariableValue(ref, FieldUtility.getFields(new Object [] {role_name, grantee}), 1); 101 SqlSchemaConstants.update(systemSession, 102 SqlSchemaConstants.role_authorization_TableName, iter, 103 new int[] {SystemTablesFields.roleAuthorization_is_grantable} 104 , new Object [] {isGrantable}); 105 106 } 107 108 public int hashCode() { 109 return role_name.toUpperCase().hashCode() * 3 110 + grantee.toUpperCase().hashCode() * 7; 111 } 112 113 public boolean equals(Object temp) { 114 if (! (temp instanceof RoleAuthorizationDescriptor)) { 115 return false; 116 } 117 RoleAuthorizationDescriptor pd = (RoleAuthorizationDescriptor) temp; 118 return ( ( (role_name == null) && (pd.role_name == null)) 119 || role_name.equalsIgnoreCase(pd.role_name)) 120 && ( ( (grantee == null) && (pd.grantee == null)) 121 || grantee.equalsIgnoreCase(pd.grantee)); 122 } 123 } 124 | Popular Tags |