1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemadefinition; 2 3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*; 4 import com.daffodilwoods.daffodildb.server.serversystem.*; 5 import com.daffodilwoods.daffodildb.server.sql99.common.*; 6 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*; 7 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*; 8 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*; 9 import com.daffodilwoods.daffodildb.server.sql99.token.*; 10 import com.daffodilwoods.database.resource.*; 11 12 public class roledefinition implements SQLschemadefinitionstatement, schemaelement { 13 public SRESERVEDWORD1206543922SRESERVEDWORD1206543922grantor 14 _OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922grantor0; 15 public rolename _rolename1; 16 public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442552; 17 public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439223; 18 19 33 public Object run(Object object) throws DException { 34 _ServerSession currentSession = (_ServerSession) object; 35 RoleDescriptor roleDescriptor = new RoleDescriptor(); 36 setRoleName(currentSession, roleDescriptor); 37 RoleAuthorizationDescriptor roleAuthDes = new RoleAuthorizationDescriptor(); 38 39 setRoleAuthorization(currentSession, roleDescriptor.role_name, roleAuthDes); 40 roleDescriptor.save(currentSession); 41 roleAuthDes.save(currentSession); 42 43 return null; 44 } 45 46 54 private void setRoleName(_ServerSession currentSession, RoleDescriptor roleDescriptor) throws DException { 55 roleDescriptor.role_name = (String ) _rolename1.run(null); 56 checkIfUserExistsWithSameName(currentSession, roleDescriptor.role_name); 57 } 58 59 private void checkIfUserExistsWithSameName(_ServerSession currentSession, String role_name) throws 60 DException { 61 _SelectQueryIterator usersIterator = SqlSchemaConstants.getIterator(currentSession, QueryMaker.getUsersQuery(), new Object [] {role_name}); 62 if (usersIterator.first() || 63 role_name.equalsIgnoreCase(SystemTables.SYSTEM)) { 64 throw new DException("DSE876", new Object [] {role_name}); 65 } 66 } 67 68 77 private void setRoleAuthorization(_ServerSession currentSession, 78 String roleName, 79 RoleAuthorizationDescriptor 80 roleAuthDes) throws 81 DException { 82 setRoleAuthorizationGrantee(currentSession, roleAuthDes); 83 roleAuthDes.grantor = SqlSchemaConstants.SYSTEM; 84 roleAuthDes.is_grantable = SqlSchemaConstants.YES; 85 roleAuthDes.role_name = roleName; 86 } 87 88 99 private void setRoleAuthorizationGrantee(_ServerSession currentSession, RoleAuthorizationDescriptor roleAuthDes) throws DException { 100 if (_OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922grantor0 == null) { 101 String current_user = currentSession.getCurrentUser(); 102 roleAuthDes.grantee = currentSession.getCurrentRole() == null ? current_user 103 : currentSession.getCurrentRole(); 104 } else { 105 String grantr = _OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922grantor0._grantor0.toString(); 106 roleAuthDes.grantee = grantr.equalsIgnoreCase(SqlKeywords.CURRENT_USER) 107 ? currentSession.getCurrentUser() 108 : grantr.equalsIgnoreCase(SqlKeywords.CURRENT_ROLE) 109 ? currentSession.getCurrentRole() : grantr; 110 if (roleAuthDes.grantee == null) { 111 throw new DException("DSE520", null); 112 } 113 } 114 } 115 116 public Object clone() throws CloneNotSupportedException { 117 return this; 118 } 119 120 public String toString() { 121 StringBuffer sb = new StringBuffer (); 122 sb.append(" "); 123 sb.append(_SRESERVEDWORD12065439223); 124 sb.append(" "); 125 sb.append(_SNONRESERVEDWORD1364442552); 126 sb.append(" "); 127 sb.append(_rolename1); 128 sb.append(" "); 129 if (_OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922grantor0 != null) { 130 sb.append(_OptSRESERVEDWORD1206543922SRESERVEDWORD1206543922grantor0); 131 } 132 return sb.toString(); 133 } 134 135 public void setSchemaDescriptor(_Descriptor schemaDescriptor) throws 136 DException {} 137 } 138 | Popular Tags |