use of org.apache.hadoop.hive.metastore.model.MTablePrivilege 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;
}
use of org.apache.hadoop.hive.metastore.model.MTablePrivilege in project hive by apache.
the class ObjectStore method listPrincipalAllTableGrants.
@SuppressWarnings("unchecked")
private List<MTablePrivilege> listPrincipalAllTableGrants(String principalName, PrincipalType principalType, QueryWrapper queryWrapper) {
boolean success = false;
List<MTablePrivilege> mSecurityTabPartList = null;
try {
LOG.debug("Executing listPrincipalAllTableGrants");
openTransaction();
Query query = queryWrapper.query = pm.newQuery(MTablePrivilege.class, "principalName == t1 && principalType == t2");
query.declareParameters("java.lang.String t1, java.lang.String t2");
mSecurityTabPartList = (List<MTablePrivilege>) query.execute(principalName, principalType.toString());
pm.retrieveAll(mSecurityTabPartList);
success = commitTransaction();
LOG.debug("Done retrieving all objects for listPrincipalAllTableGrants");
} finally {
if (!success) {
rollbackTransaction();
}
}
return mSecurityTabPartList;
}
use of org.apache.hadoop.hive.metastore.model.MTablePrivilege in project hive by apache.
the class ObjectStore method listPrincipalTableGrantsAll.
@Override
public List<HiveObjectPrivilege> listPrincipalTableGrantsAll(String principalName, PrincipalType principalType) {
boolean success = false;
Query query = null;
try {
openTransaction();
LOG.debug("Executing listPrincipalAllTableGrants");
List<MTablePrivilege> mSecurityTabPartList;
if (principalName != null && principalType != null) {
query = pm.newQuery(MTablePrivilege.class, "principalName == t1 && principalType == t2");
query.declareParameters("java.lang.String t1, java.lang.String t2");
mSecurityTabPartList = (List<MTablePrivilege>) query.execute(principalName, principalType.toString());
} else {
query = pm.newQuery(MTablePrivilege.class);
mSecurityTabPartList = (List<MTablePrivilege>) query.execute();
}
LOG.debug("Done executing query for listPrincipalAllTableGrants");
pm.retrieveAll(mSecurityTabPartList);
List<HiveObjectPrivilege> result = convertTable(mSecurityTabPartList);
success = commitTransaction();
LOG.debug("Done retrieving all objects for listPrincipalAllTableGrants");
return result;
} finally {
if (!success) {
rollbackTransaction();
}
if (query != null) {
query.closeAll();
}
}
}
use of org.apache.hadoop.hive.metastore.model.MTablePrivilege in project hive by apache.
the class ObjectStore method listAllTableGrants.
@Override
public List<HiveObjectPrivilege> listAllTableGrants(String principalName, PrincipalType principalType, String dbName, String tableName) {
List<MTablePrivilege> mTbls = listAllMTableGrants(principalName, principalType, dbName, tableName);
if (mTbls.isEmpty()) {
return Collections.<HiveObjectPrivilege>emptyList();
}
List<HiveObjectPrivilege> result = new ArrayList<HiveObjectPrivilege>();
for (int i = 0; i < mTbls.size(); i++) {
MTablePrivilege sTbl = mTbls.get(i);
HiveObjectRef objectRef = new HiveObjectRef(HiveObjectType.TABLE, dbName, tableName, null, null);
HiveObjectPrivilege secObj = new HiveObjectPrivilege(objectRef, sTbl.getPrincipalName(), principalType, new PrivilegeGrantInfo(sTbl.getPrivilege(), sTbl.getCreateTime(), sTbl.getGrantor(), PrincipalType.valueOf(sTbl.getGrantorType()), sTbl.getGrantOption()));
result.add(secObj);
}
return result;
}
use of org.apache.hadoop.hive.metastore.model.MTablePrivilege in project hive by apache.
the class ObjectStore method dropTable.
@Override
public boolean dropTable(String dbName, String tableName) throws MetaException, NoSuchObjectException, InvalidObjectException, InvalidInputException {
boolean success = false;
try {
openTransaction();
MTable tbl = getMTable(dbName, tableName);
pm.retrieve(tbl);
if (tbl != null) {
// first remove all the grants
List<MTablePrivilege> tabGrants = listAllTableGrants(dbName, tableName);
if (tabGrants != null && tabGrants.size() > 0) {
pm.deletePersistentAll(tabGrants);
}
List<MTableColumnPrivilege> tblColGrants = listTableAllColumnGrants(dbName, tableName);
if (tblColGrants != null && tblColGrants.size() > 0) {
pm.deletePersistentAll(tblColGrants);
}
List<MPartitionPrivilege> partGrants = this.listTableAllPartitionGrants(dbName, tableName);
if (partGrants != null && partGrants.size() > 0) {
pm.deletePersistentAll(partGrants);
}
List<MPartitionColumnPrivilege> partColGrants = listTableAllPartitionColumnGrants(dbName, tableName);
if (partColGrants != null && partColGrants.size() > 0) {
pm.deletePersistentAll(partColGrants);
}
// delete column statistics if present
try {
deleteTableColumnStatistics(dbName, tableName, null);
} catch (NoSuchObjectException e) {
LOG.info("Found no table level column statistics associated with db " + dbName + " table " + tableName + " record to delete");
}
List<MConstraint> tabConstraints = listAllTableConstraintsWithOptionalConstraintName(dbName, tableName, null);
if (tabConstraints != null && tabConstraints.size() > 0) {
pm.deletePersistentAll(tabConstraints);
}
preDropStorageDescriptor(tbl.getSd());
// then remove the table
pm.deletePersistentAll(tbl);
}
success = commitTransaction();
} finally {
if (!success) {
rollbackTransaction();
}
}
return success;
}
Aggregations