本文整理了Java中javax.jdo.Query.execute
方法的一些代码示例,展示了Query.execute
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.execute
方法的具体详情如下:
包路径:javax.jdo.Query
类名称:Query
方法名:execute
[英]Execute the query and return the filtered Collection.
Cancellation of the query using cancel() will result in JDOQueryInterruptedException being thrown here
[中]执行查询并返回过滤后的集合。
使用cancel()取消查询将导致在此处抛出JDOQueryInterruptedException
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
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;
}
代码示例来源:origin: apache/hive
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();
}
代码示例来源:origin: apache/hive
@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;
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
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();
}
}
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
@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;
}
代码示例来源:origin: apache/hive
/** 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);
}
}
代码示例来源:origin: apache/hive
/** 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();
}
}
}
代码示例来源:origin: apache/hive
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;
}
代码示例来源:origin: apache/hive
@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;
}
代码示例来源:origin: apache/hive
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;
}
代码示例来源:origin: apache/hive
@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;
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
@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;
}
代码示例来源:origin: apache/hive
@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;
}
内容来源于网络,如有侵权,请联系作者删除!