use of org.apache.hadoop.hive.metastore.model.MRoleMap in project hive by apache.
the class ObjectStore method removeRole.
@Override
public boolean removeRole(String roleName) throws MetaException, NoSuchObjectException {
boolean success = false;
QueryWrapper queryWrapper = new QueryWrapper();
try {
openTransaction();
MRole mRol = getMRole(roleName);
pm.retrieve(mRol);
if (mRol != null) {
// first remove all the membership, the membership that this role has
// been granted
List<MRoleMap> roleMap = listMRoleMembers(mRol.getRoleName());
if (roleMap.size() > 0) {
pm.deletePersistentAll(roleMap);
}
List<MRoleMap> roleMember = listMSecurityPrincipalMembershipRole(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
if (roleMember.size() > 0) {
pm.deletePersistentAll(roleMember);
}
queryWrapper.close();
// then remove all the grants
List<MGlobalPrivilege> userGrants = listPrincipalMGlobalGrants(mRol.getRoleName(), PrincipalType.ROLE);
if (userGrants.size() > 0) {
pm.deletePersistentAll(userGrants);
}
List<MDBPrivilege> dbGrants = listPrincipalAllDBGrant(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
if (dbGrants.size() > 0) {
pm.deletePersistentAll(dbGrants);
}
queryWrapper.close();
List<MTablePrivilege> tabPartGrants = listPrincipalAllTableGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
if (tabPartGrants.size() > 0) {
pm.deletePersistentAll(tabPartGrants);
}
queryWrapper.close();
List<MPartitionPrivilege> partGrants = listPrincipalAllPartitionGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
if (partGrants.size() > 0) {
pm.deletePersistentAll(partGrants);
}
queryWrapper.close();
List<MTableColumnPrivilege> tblColumnGrants = listPrincipalAllTableColumnGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
if (tblColumnGrants.size() > 0) {
pm.deletePersistentAll(tblColumnGrants);
}
queryWrapper.close();
List<MPartitionColumnPrivilege> partColumnGrants = listPrincipalAllPartitionColumnGrants(mRol.getRoleName(), PrincipalType.ROLE, queryWrapper);
if (partColumnGrants.size() > 0) {
pm.deletePersistentAll(partColumnGrants);
}
queryWrapper.close();
// finally remove the role
pm.deletePersistent(mRol);
}
success = commitTransaction();
} finally {
if (!success) {
rollbackTransaction();
}
queryWrapper.close();
}
return success;
}
Aggregations