@Override public String[] getMasterKeys() { LOG.debug("Begin executing getMasterKeys"); boolean committed = false; Query query = null; List<MMasterKey> keys; try { openTransaction(); query = pm.newQuery(MMasterKey.class); keys = (List<MMasterKey>) query.execute(); pm.retrieveAll(keys); committed = commitTransaction(); String[] masterKeys = new String[keys.size()]; for (int i = 0; i < keys.size(); i++) { masterKeys[i] = keys.get(i).getMasterKey(); } return masterKeys; } finally { LOG.debug("Done executing getMasterKeys with status : {}", committed); rollbackAndCleanup(committed, query); } }
@Override public List<String> getAllTokenIdentifiers() { LOG.debug("Begin executing getAllTokenIdentifiers"); boolean committed = false; Query query = null; List<String> tokenIdents = new ArrayList<>(); try { openTransaction(); query = pm.newQuery(MDelegationToken.class); List<MDelegationToken> tokens = (List<MDelegationToken>) query.execute(); pm.retrieveAll(tokens); committed = commitTransaction(); for (MDelegationToken token : tokens) { tokenIdents.add(token.getTokenIdentifier()); } return tokenIdents; } finally { LOG.debug("Done executing getAllTokenIdentifers with status : {}", committed); rollbackAndCleanup(committed, query); } }
@SuppressWarnings("unchecked") public List<MRoleMap> listMRoleMembers(String roleName) { boolean success = false; Query query = null; List<MRoleMap> mRoleMemeberList = new ArrayList<>(); try { LOG.debug("Executing listRoleMembers"); openTransaction(); query = pm.newQuery(MRoleMap.class, "role.roleName == t1"); query.declareParameters("java.lang.String t1"); query.setUnique(false); List<MRoleMap> mRoles = (List<MRoleMap>) query.execute(roleName); pm.retrieveAll(mRoles); success = commitTransaction(); mRoleMemeberList.addAll(mRoles); LOG.debug("Done retrieving all objects for listRoleMembers"); } finally { rollbackAndCleanup(success, query); } return mRoleMemeberList; }
@Override public List<MTableColumnStatistics> run(List<String> input) throws MetaException { String filter = "tableName == t1 && dbName == t2 && catName == t3 && ("; String paramStr = "java.lang.String t1, java.lang.String t2, java.lang.String t3"; Object[] params = new Object[input.size() + 3]; params[0] = table.getTableName(); params[1] = table.getDbName(); params[2] = table.getCatName(); for (int i = 0; i < input.size(); ++i) { filter += ((i == 0) ? "" : " || ") + "colName == c" + i; paramStr += ", java.lang.String c" + i; params[i + 3] = input.get(i); } filter += ")"; query.setFilter(filter); query.declareParameters(paramStr); List<MTableColumnStatistics> paritial = (List<MTableColumnStatistics>) query.executeWithArray(params); pm.retrieveAll(paritial); return paritial; } });
@SuppressWarnings("unchecked") private List<MPartitionPrivilege> listPartitionGrants(String catName, String dbName, String tableName, List<String> partNames) { tableName = normalizeIdentifier(tableName); dbName = normalizeIdentifier(dbName); boolean success = false; List<MPartitionPrivilege> mSecurityTabPartList = null; try { openTransaction(); LOG.debug("Executing listPartitionGrants"); mSecurityTabPartList = queryByPartitionNames(catName, dbName, tableName, partNames, MPartitionPrivilege.class, "partition.table.tableName", "partition.table.database.name", "partition.partitionName", "partition.table.database.catalogName"); LOG.debug("Done executing query for listPartitionGrants"); pm.retrieveAll(mSecurityTabPartList); success = commitTransaction(); LOG.debug("Done retrieving all objects for listPartitionGrants"); } finally { if (!success) { rollbackTransaction(); } } return mSecurityTabPartList; }
@SuppressWarnings("unchecked") private List<MPartitionColumnPrivilege> listPartitionAllColumnGrants( String catName, String dbName, String tableName, List<String> partNames) { boolean success = false; tableName = normalizeIdentifier(tableName); dbName = normalizeIdentifier(dbName); catName = normalizeIdentifier(catName); List<MPartitionColumnPrivilege> mSecurityColList = null; try { openTransaction(); LOG.debug("Executing listPartitionAllColumnGrants"); mSecurityColList = queryByPartitionNames(catName, dbName, tableName, partNames, MPartitionColumnPrivilege.class, "partition.table.tableName", "partition.table.database.name", "partition.partitionName", "partition.table.database.catalogName"); LOG.debug("Done executing query for listPartitionAllColumnGrants"); pm.retrieveAll(mSecurityColList); success = commitTransaction(); LOG.debug("Done retrieving all objects for listPartitionAllColumnGrants"); } finally { if (!success) { rollbackTransaction(); } } return mSecurityColList; }
@Override public List<HiveObjectPrivilege> listPartitionGrantsAll(String catName, String dbName, String tableName, String partitionName) { boolean success = false; Query query = null; try { openTransaction(); LOG.debug("Executing listPrincipalPartitionGrantsAll"); query = pm.newQuery(MPartitionPrivilege.class, "partition.table.tableName == t3 && partition.table.database.name == t4 && " + "partition.table.database.catalogName == t5 && partition.partitionName == t6"); query.declareParameters("java.lang.String t3, java.lang.String t4, java.lang.String t5, " + "java.lang.String t6"); List<MPartitionPrivilege> mSecurityTabPartList = (List<MPartitionPrivilege>) query.executeWithArray(tableName, dbName, catName, partitionName); LOG.debug("Done executing query for listPrincipalPartitionGrantsAll"); pm.retrieveAll(mSecurityTabPartList); List<HiveObjectPrivilege> result = convertPartition(mSecurityTabPartList); success = commitTransaction(); LOG.debug("Done retrieving all objects for listPrincipalPartitionGrantsAll"); return result; } finally { rollbackAndCleanup(success, query); } }
@SuppressWarnings("unchecked") private List<MPartitionPrivilege> listPrincipalAllPartitionGrants(String principalName, PrincipalType principalType, QueryWrapper queryWrapper) { boolean success = false; List<MPartitionPrivilege> mSecurityTabPartList = null; try { openTransaction(); LOG.debug("Executing listPrincipalAllPartitionGrants"); Query query = queryWrapper.query = pm.newQuery(MPartitionPrivilege.class, "principalName == t1 && principalType == t2"); query.declareParameters("java.lang.String t1, java.lang.String t2"); mSecurityTabPartList = (List<MPartitionPrivilege>) query.execute(principalName, principalType.toString()); pm.retrieveAll(mSecurityTabPartList); success = commitTransaction(); LOG.debug("Done retrieving all objects for listPrincipalAllPartitionGrants"); } finally { if (!success) { rollbackTransaction(); } } return mSecurityTabPartList; }
@SuppressWarnings("unchecked") private List<MPartitionPrivilege> listTableAllPartitionGrants(String catName, String dbName, String tableName) { tableName = normalizeIdentifier(tableName); dbName = normalizeIdentifier(dbName); catName = normalizeIdentifier(catName); boolean success = false; Query query = null; List<MPartitionPrivilege> mSecurityTabPartList = new ArrayList<>(); try { LOG.debug("Executing listTableAllPartitionGrants"); openTransaction(); String queryStr = "partition.table.tableName == t1 && partition.table.database.name == t2 " + "&& partition.table.database.catalogName == t3"; query = pm.newQuery(MPartitionPrivilege.class, queryStr); query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3"); List<MPartitionPrivilege> mPrivs = (List<MPartitionPrivilege>) query.executeWithArray(tableName, dbName, catName); pm.retrieveAll(mPrivs); success = commitTransaction(); mSecurityTabPartList.addAll(mPrivs); LOG.debug("Done retrieving all objects for listTableAllPartitionGrants"); } finally { rollbackAndCleanup(success, query); } return mSecurityTabPartList; }
@SuppressWarnings("unchecked") private List<MPartitionColumnPrivilege> listTableAllPartitionColumnGrants( String catName, String dbName, String tableName) { boolean success = false; Query query = null; tableName = normalizeIdentifier(tableName); dbName = normalizeIdentifier(dbName); catName = normalizeIdentifier(catName); List<MPartitionColumnPrivilege> mSecurityColList = new ArrayList<>(); try { LOG.debug("Executing listTableAllPartitionColumnGrants"); openTransaction(); String queryStr = "partition.table.tableName == t1 && partition.table.database.name == t2 " + "&& partition.table.database.catalogName == t3"; query = pm.newQuery(MPartitionColumnPrivilege.class, queryStr); query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3"); List<MPartitionColumnPrivilege> mPrivs = (List<MPartitionColumnPrivilege>) query.executeWithArray(tableName, dbName, catName); pm.retrieveAll(mPrivs); success = commitTransaction(); mSecurityColList.addAll(mPrivs); LOG.debug("Done retrieving all objects for listTableAllPartitionColumnGrants"); } finally { rollbackAndCleanup(success, query); } return mSecurityColList; }
@SuppressWarnings("unchecked") private List<MRoleMap> listMSecurityPrincipalMembershipRole(final String roleName, final PrincipalType principalType, QueryWrapper queryWrapper) { boolean success = false; List<MRoleMap> mRoleMemebership = null; try { LOG.debug("Executing listMSecurityPrincipalMembershipRole"); openTransaction(); Query query = queryWrapper.query = pm.newQuery(MRoleMap.class, "principalName == t1 && principalType == t2"); query.declareParameters("java.lang.String t1, java.lang.String t2"); mRoleMemebership = (List<MRoleMap>) query.execute(roleName, principalType.toString()); pm.retrieveAll(mRoleMemebership); success = commitTransaction(); LOG.debug("Done retrieving all objects for listMSecurityPrincipalMembershipRole"); } finally { if (!success) { rollbackTransaction(); } } return mRoleMemebership; }
@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; }
@SuppressWarnings("unchecked") private List<MPartitionColumnPrivilege> listPrincipalAllPartitionColumnGrants( String principalName, PrincipalType principalType, QueryWrapper queryWrapper) { boolean success = false; List<MPartitionColumnPrivilege> mSecurityColumnList = null; try { LOG.debug("Executing listPrincipalAllTableColumnGrants"); openTransaction(); Query query = queryWrapper.query = pm.newQuery(MPartitionColumnPrivilege.class, "principalName == t1 && principalType == t2"); query.declareParameters("java.lang.String t1, java.lang.String t2"); mSecurityColumnList = (List<MPartitionColumnPrivilege>) query.execute(principalName, principalType.toString()); pm.retrieveAll(mSecurityColumnList); success = commitTransaction(); LOG.debug("Done retrieving all objects for listPrincipalAllTableColumnGrants"); } finally { if (!success) { rollbackTransaction(); } } return mSecurityColumnList; }
@SuppressWarnings("unchecked") private List<MTableColumnPrivilege> listPrincipalAllTableColumnGrants(String principalName, PrincipalType principalType, QueryWrapper queryWrapper) { boolean success = false; List<MTableColumnPrivilege> mSecurityColumnList = null; try { LOG.debug("Executing listPrincipalAllTableColumnGrants"); openTransaction(); Query query = queryWrapper.query = pm.newQuery(MTableColumnPrivilege.class, "principalName == t1 && principalType == t2"); query.declareParameters("java.lang.String t1, java.lang.String t2"); mSecurityColumnList = (List<MTableColumnPrivilege>) query.execute(principalName, principalType.toString()); pm.retrieveAll(mSecurityColumnList); success = commitTransaction(); LOG.debug("Done retrieving all objects for listPrincipalAllTableColumnGrants"); } finally { if (!success) { rollbackTransaction(); } } return mSecurityColumnList; }
@Override public List<WMResourcePlan> getAllResourcePlans(String ns) throws MetaException { List<WMResourcePlan> resourcePlans = new ArrayList(); boolean commited = false; Query query = null; try { openTransaction(); query = pm.newQuery(MWMResourcePlan.class, "ns == nsname"); query.declareParameters("java.lang.String nsname"); List<MWMResourcePlan> mplans = (List<MWMResourcePlan>) query.execute(getNsOrDefault(ns)); pm.retrieveAll(mplans); commited = commitTransaction(); if (mplans != null) { for (MWMResourcePlan mplan : mplans) { resourcePlans.add(fromMResourcePlan(mplan)); } } } finally { rollbackAndCleanup(commited, query); } return resourcePlans; }
@Override public List<HiveObjectPrivilege> listGlobalGrantsAll() { boolean commited = false; Query query = null; try { openTransaction(); query = pm.newQuery(MGlobalPrivilege.class); List<MGlobalPrivilege> userNameDbPriv = (List<MGlobalPrivilege>) query.execute(); pm.retrieveAll(userNameDbPriv); commited = commitTransaction(); return convertGlobal(userNameDbPriv); } finally { rollbackAndCleanup(commited, query); } }
private List<MPartition> listMPartitions(String catName, String dbName, String tableName, int max, QueryWrapper queryWrapper) { boolean success = false; List<MPartition> mparts = null; try { openTransaction(); LOG.debug("Executing listMPartitions"); dbName = normalizeIdentifier(dbName); tableName = normalizeIdentifier(tableName); Query query = queryWrapper.query = pm.newQuery(MPartition.class, "table.tableName == t1 && table.database.name == t2 && table.database.catalogName == t3"); query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3"); query.setOrdering("partitionName ascending"); if (max >= 0) { query.setRange(0, max); } mparts = (List<MPartition>) query.execute(tableName, dbName, catName); LOG.debug("Done executing query for listMPartitions"); pm.retrieveAll(mparts); success = commitTransaction(); LOG.debug("Done retrieving all objects for listMPartitions {}", mparts); } finally { if (!success) { rollbackTransaction(); } } return mparts; }
@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 { rollbackAndCleanup(success, query); } }
private void moveDescendents(MWMResourcePlan resourcePlan, String path, String newPoolPath) throws NoSuchObjectException { if (!poolParentExists(resourcePlan, newPoolPath)) { throw new NoSuchObjectException("Pool path is invalid, the parent does not exist"); } boolean commited = false; Query query = null; openTransaction(); try { query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)"); query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath"); List<MWMPool> descPools = (List<MWMPool>) query.execute(resourcePlan, path + "."); pm.retrieveAll(descPools); for (MWMPool pool : descPools) { pool.setPath(newPoolPath + pool.getPath().substring(path.length())); } commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } }
@Override public List<Function> getAllFunctions(String catName) throws MetaException { boolean commited = false; Query query = null; try { openTransaction(); catName = normalizeIdentifier(catName); query = pm.newQuery(MFunction.class, "database.catalogName == catName"); query.declareParameters("java.lang.String catName"); List<MFunction> allFunctions = (List<MFunction>) query.execute(catName); pm.retrieveAll(allFunctions); commited = commitTransaction(); return convertToFunctions(allFunctions); } finally { rollbackAndCleanup(commited, query); } }