Refine search
@Override public List<String> listRoleNames() { boolean success = false; Query query = null; try { openTransaction(); LOG.debug("Executing listAllRoleNames"); query = pm.newQuery("select roleName from org.apache.hadoop.hive.metastore.model.MRole"); query.setResult("roleName"); Collection names = (Collection) query.execute(); List<String> roleNames = new ArrayList<>(); for (Iterator i = names.iterator(); i.hasNext();) { roleNames.add((String) i.next()); } success = commitTransaction(); return roleNames; } finally { rollbackAndCleanup(success, query); } }
private MDelegationToken getTokenFrom(String tokenId) { Query query = pm.newQuery(MDelegationToken.class, "tokenIdentifier == tokenId"); query.declareParameters("java.lang.String tokenId"); query.setUnique(true); MDelegationToken delegationToken = (MDelegationToken) query.execute(tokenId); if (query != null) { query.closeAll(); } return delegationToken; }
private int getObjectCount(String fieldName, String objName) { Long result = 0L; boolean commited = false; Query query = null; try { openTransaction(); String queryStr = "select count(" + fieldName + ") from " + objName; query = pm.newQuery(queryStr); result = (Long) query.execute(); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } return result.intValue(); }
@Override public List<String> getCatalogs() throws MetaException { LOG.debug("Fetching all catalog names"); boolean commited = false; List<String> catalogs = null; String queryStr = "select name from org.apache.hadoop.hive.metastore.model.MCatalog"; Query query = null; openTransaction(); try { query = pm.newQuery(queryStr); query.setResult("name"); catalogs = new ArrayList<>((Collection<String>) query.execute()); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } Collections.sort(catalogs); return catalogs; }
@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); } }
@Override public CurrentNotificationEventId getCurrentNotificationEventId() { boolean commited = false; Query query = null; try { openTransaction(); query = pm.newQuery(MNotificationNextId.class); Collection<MNotificationNextId> ids = (Collection) query.execute(); long id = 0; if (CollectionUtils.isNotEmpty(ids)) { id = ids.iterator().next().getNextEventId() - 1; } commited = commitTransaction(); return new CurrentNotificationEventId(id); } finally { rollbackAndCleanup(commited, query); } }
@Override public void cleanNotificationEvents(int olderThan) { boolean commited = false; Query query = null; try { openTransaction(); long tmp = System.currentTimeMillis() / 1000 - olderThan; int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp; query = pm.newQuery(MNotificationLog.class, "eventTime < tooOld"); query.declareParameters("java.lang.Integer tooOld"); Collection<MNotificationLog> toBeRemoved = (Collection) query.execute(tooOld); if (CollectionUtils.isNotEmpty(toBeRemoved)) { pm.deletePersistentAll(toBeRemoved); } commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } }
private MSerDeInfo getMSerDeInfo(String serDeName) throws MetaException { Query query = null; try { query = pm.newQuery(MSerDeInfo.class, "name == serDeName"); query.declareParameters("java.lang.String serDeName"); query.setUnique(true); MSerDeInfo mSerDeInfo = (MSerDeInfo)query.execute(serDeName); pm.retrieve(mSerDeInfo); return mSerDeInfo; } finally { if (query != null) { query.closeAll(); } } }
@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 void cleanWriteNotificationEvents(int olderThan) { boolean commited = false; Query query = null; try { openTransaction(); long tmp = System.currentTimeMillis() / 1000 - olderThan; int tooOld = (tmp > Integer.MAX_VALUE) ? 0 : (int) tmp; query = pm.newQuery(MTxnWriteNotificationLog.class, "eventTime < tooOld"); query.declareParameters("java.lang.Integer tooOld"); Collection<MTxnWriteNotificationLog> toBeRemoved = (Collection) query.execute(tooOld); if (CollectionUtils.isNotEmpty(toBeRemoved)) { pm.deletePersistentAll(toBeRemoved); } commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } }
/** The following API * * - executeJDOQLUpdate * * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift. * */ public long executeJDOQLUpdate(String queryStr) { boolean committed = false; long numUpdated = 0; Query query = null; try { openTransaction(); query = pm.newQuery(queryStr); numUpdated = (Long) query.execute(); committed = commitTransaction(); if (committed) { return numUpdated; } else { return -1; } } finally { rollbackAndCleanup(committed, query); } }
/** The following API * * - executeJDOQLSelect * * is used by HiveMetaTool. This API **shouldn't** be exposed via Thrift. * */ public Collection<?> executeJDOQLSelect(String queryStr, QueryWrapper queryWrapper) { boolean committed = false; Collection<?> result = null; try { openTransaction(); Query query = queryWrapper.query = pm.newQuery(queryStr); result = ((Collection<?>) query.execute()); committed = commitTransaction(); if (committed) { return result; } else { return null; } } finally { if (!committed) { rollbackTransaction(); } } }
private List<RuntimeStat> getMRuntimeStats(int maxEntries, int maxCreateTime) { Query<MRuntimeStat> query = pm.newQuery(MRuntimeStat.class); query.setOrdering("createTime descending"); if (maxCreateTime > 0) { query.setFilter("createTime < "+maxCreateTime); } if (maxEntries < 0) { maxEntries = Integer.MAX_VALUE; } List<RuntimeStat> ret = new ArrayList<>(); List<MRuntimeStat> res = (List<MRuntimeStat>) query.execute(); int totalEntries = 0; for (MRuntimeStat mRuntimeStat : res) { pm.retrieve(mRuntimeStat); totalEntries += mRuntimeStat.getWeight(); ret.add(MRuntimeStat.toThrift(mRuntimeStat)); if (totalEntries >= maxEntries) { break; } } return ret; }
@Override public List<String> getAllDatabases(String catName) throws MetaException { boolean commited = false; List<String> databases = null; Query query = null; catName = normalizeIdentifier(catName); openTransaction(); try { query = pm.newQuery("select name from org.apache.hadoop.hive.metastore.model.MDatabase " + "where catalogName == catname"); query.declareParameters("java.lang.String catname"); query.setResult("name"); databases = new ArrayList<>((Collection<String>) query.execute(catName)); commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } Collections.sort(databases); return databases; }
private String getPrimaryKeyConstraintName(String catName, String db_name, String tbl_name) throws MetaException { boolean commited = false; String ret = null; Query query = null; try { openTransaction(); query = pm.newQuery(MConstraint.class, "parentTable.tableName == tbl_name && parentTable.database.name == db_name &&" + " parentTable.database.catalogName == catName &&" + " constraintType == MConstraint.PRIMARY_KEY_CONSTRAINT"); query.declareParameters("java.lang.String tbl_name, java.lang.String db_name, " + "java.lang.String catName"); Collection<?> constraints = (Collection<?>) query.execute(tbl_name, db_name, catName); pm.retrieveAll(constraints); for (Iterator<?> i = constraints.iterator(); i.hasNext();) { MConstraint currPK = (MConstraint) i.next(); ret = currPK.getConstraintName(); break; } commited = commitTransaction(); } finally { rollbackAndCleanup(commited, query); } return ret; }
@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; }
@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); } }
@Override public boolean removeMasterKey(Integer id) { LOG.debug("Begin executing removeMasterKey"); boolean success = false; Query query = null; MMasterKey masterKey; try { openTransaction(); query = pm.newQuery(MMasterKey.class, "keyId == id"); query.declareParameters("java.lang.Integer id"); query.setUnique(true); masterKey = (MMasterKey) query.execute(id); if (null != masterKey) { pm.deletePersistent(masterKey); } success = commitTransaction(); } finally { rollbackAndCleanup(success, query); } LOG.debug("Done executing removeMasterKey with status : {}", success); return (null != masterKey) && success; }
@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; }