本文整理了Java中javax.jdo.Query.declareParameters
方法的一些代码示例,展示了Query.declareParameters
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.declareParameters
方法的具体详情如下:
包路径:javax.jdo.Query
类名称:Query
方法名:declareParameters
[英]Declare the list of parameters query execution. The parameter declaration is a String
containing one or more query parameter declarations separated with commas. Each parameter named in the parameter declaration must be bound to a value when the query is executed.
The String
parameter to this method follows the syntax for formal parameters in the Java language.
[中]声明查询执行的参数列表。参数声明是一个String
,包含一个或多个用逗号分隔的查询参数声明。在执行查询时,参数声明中命名的每个参数都必须绑定到一个值。
此方法的String
参数遵循Java语言中形式参数的语法。
代码示例来源:origin: apache/hive
private Query createActivePlanQuery() {
openTransaction();
Query query = pm.newQuery(MWMResourcePlan.class, "status == activeStatus && ns == nsname");
query.declareParameters("java.lang.String activeStatus, java.lang.String nsname");
query.setUnique(true);
return query;
}
代码示例来源:origin: apache/hive
private Query createGetResourcePlanQuery() {
openTransaction();
Query query = pm.newQuery(MWMResourcePlan.class, "name == rpname && ns == nsname");
query.declareParameters("java.lang.String rpname, java.lang.String nsname");
query.setUnique(true);
return query;
}
代码示例来源:origin: apache/hive
private ObjectPair<Query, Map<String, String>> getPartQueryWithParams(
String catName, String dbName, String tblName, List<String> partNames) {
Query query = pm.newQuery();
Map<String, String> params = new HashMap<>();
String filterStr = getJDOFilterStrForPartitionNames(catName, dbName, tblName, partNames, params);
query.setFilter(filterStr);
LOG.debug(" JDOQL filter is {}", filterStr);
query.declareParameters(makeParameterDeclarationString(params));
return new ObjectPair<>(query, params);
}
代码示例来源: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
@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
@Override
public long cleanupEvents() {
boolean commited = false;
Query query = null;
long delCnt;
LOG.debug("Begin executing cleanupEvents");
Long expiryTime =
MetastoreConf.getTimeVar(getConf(), ConfVars.EVENT_EXPIRY_DURATION, TimeUnit.MILLISECONDS);
Long curTime = System.currentTimeMillis();
try {
openTransaction();
query = pm.newQuery(MPartitionEvent.class, "curTime - eventTime > expiryTime");
query.declareParameters("java.lang.Long curTime, java.lang.Long expiryTime");
delCnt = query.deletePersistentAll(curTime, expiryTime);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
LOG.debug("Done executing cleanupEvents");
}
return delCnt;
}
代码示例来源: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
@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 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
private Integer getNumPartitionsViaOrmFilter(Table table, ExpressionTree tree, boolean isValidatedFilter)
throws MetaException {
Map<String, Object> params = new HashMap<>();
String jdoFilter = makeQueryFilterString(table.getCatName(), table.getDbName(), table, tree,
params, isValidatedFilter);
if (jdoFilter == null) {
assert !isValidatedFilter;
return null;
}
Query query = pm.newQuery(
"select count(partitionName) from org.apache.hadoop.hive.metastore.model.MPartition"
);
query.setFilter(jdoFilter);
String parameterDeclaration = makeParameterDeclarationStringObj(params);
query.declareParameters(parameterDeclaration);
Long result = (Long) query.executeWithMap(params);
query.closeAll();
return result.intValue();
}
/**
代码示例来源:origin: apache/hive
private boolean constraintNameAlreadyExists(String name) {
boolean commited = false;
Query constraintExistsQuery = null;
String constraintNameIfExists = null;
try {
openTransaction();
name = normalizeIdentifier(name);
constraintExistsQuery = pm.newQuery(MConstraint.class, "constraintName == name");
constraintExistsQuery.declareParameters("java.lang.String name");
constraintExistsQuery.setUnique(true);
constraintExistsQuery.setResult("name");
constraintNameIfExists = (String) constraintExistsQuery.execute(name);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, constraintExistsQuery);
}
return constraintNameIfExists != null && !constraintNameIfExists.isEmpty();
}
代码示例来源:origin: apache/hive
private MRole getMRole(String roleName) {
MRole mrole = null;
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MRole.class, "roleName == t1");
query.declareParameters("java.lang.String t1");
query.setUnique(true);
mrole = (MRole) query.execute(roleName);
pm.retrieve(mrole);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return mrole;
}
代码示例来源:origin: apache/hive
private boolean poolHasChildren(MWMResourcePlan resourcePlan, String poolPath) {
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)");
query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath");
query.setResult("count(this)");
query.setUnique(true);
Long count = (Long) query.execute(resourcePlan, poolPath + ".");
commited = commitTransaction();
return count != null && count > 0;
} finally {
rollbackAndCleanup(commited, query);
}
}
代码示例来源:origin: apache/hive
@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);
}
}
代码示例来源:origin: apache/hive
private MCatalog getMCatalog(String catalogName) throws MetaException {
boolean committed = false;
Query query = null;
try {
openTransaction();
catalogName = normalizeIdentifier(catalogName);
query = pm.newQuery(MCatalog.class, "name == catname");
query.declareParameters("java.lang.String catname");
query.setUnique(true);
MCatalog mCat = (MCatalog)query.execute(catalogName);
pm.retrieve(mCat);
committed = commitTransaction();
return mCat;
} finally {
rollbackAndCleanup(committed, query);
}
}
代码示例来源:origin: apache/hive
private MRoleMap getMSecurityUserRoleMap(String userName, PrincipalType principalType,
String roleName) {
MRoleMap mRoleMember = null;
boolean commited = false;
Query query = null;
try {
openTransaction();
query =
pm.newQuery(MRoleMap.class,
"principalName == t1 && principalType == t2 && role.roleName == t3");
query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
query.setUnique(true);
mRoleMember = (MRoleMap) query.executeWithArray(userName, principalType.toString(), roleName);
pm.retrieve(mRoleMember);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return mRoleMember;
}
代码示例来源:origin: apache/hive
@Override
public void dropWMTrigger(String resourcePlanName, String triggerName, String ns)
throws NoSuchObjectException, InvalidOperationException, MetaException {
resourcePlanName = normalizeIdentifier(resourcePlanName);
triggerName = normalizeIdentifier(triggerName);
boolean commited = false;
Query query = null;
try {
openTransaction();
MWMResourcePlan resourcePlan = getMWMResourcePlan(resourcePlanName, ns, true);
query = pm.newQuery(MWMTrigger.class, "resourcePlan == rp && name == triggerName");
query.declareParameters("MWMResourcePlan rp, java.lang.String triggerName");
if (query.deletePersistentAll(resourcePlan, triggerName) != 1) {
throw new NoSuchObjectException("Cannot delete trigger: " + triggerName);
}
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
}
代码示例来源:origin: apache/hive
private MWMPool getPool(MWMResourcePlan resourcePlan, String poolPath)
throws NoSuchObjectException {
poolPath = normalizeIdentifier(poolPath);
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path == poolPath");
query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath");
query.setUnique(true);
MWMPool mPool = (MWMPool) query.execute(resourcePlan, poolPath);
commited = commitTransaction();
if (mPool == null) {
throw new NoSuchObjectException("Cannot find pool: " + poolPath);
}
pm.retrieve(mPool);
return mPool;
} finally {
rollbackAndCleanup(commited, query);
}
}
代码示例来源:origin: apache/hive
private MFunction getMFunction(String catName, String db, String function) {
MFunction mfunc = null;
boolean commited = false;
Query query = null;
try {
openTransaction();
catName = normalizeIdentifier(catName);
db = normalizeIdentifier(db);
function = normalizeIdentifier(function);
query = pm.newQuery(MFunction.class,
"functionName == function && database.name == db && database.catalogName == catName");
query.declareParameters("java.lang.String function, java.lang.String db, java.lang.String catName");
query.setUnique(true);
mfunc = (MFunction) query.execute(function, db, catName);
pm.retrieve(mfunc);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return mfunc;
}
代码示例来源:origin: apache/hive
private MCreationMetadata getCreationMetadata(String catName, String dbName, String tblName) {
boolean commited = false;
MCreationMetadata mcm = null;
Query query = null;
catName = normalizeIdentifier(catName);
dbName = normalizeIdentifier(dbName);
tblName = normalizeIdentifier(tblName);
try {
openTransaction();
query = pm.newQuery(
MCreationMetadata.class, "tblName == table && dbName == db && catalogName == cat");
query.declareParameters("java.lang.String table, java.lang.String db, java.lang.String cat");
query.setUnique(true);
mcm = (MCreationMetadata) query.execute(tblName, dbName, catName);
pm.retrieve(mcm);
commited = commitTransaction();
} finally {
rollbackAndCleanup(commited, query);
}
return mcm;
}
内容来源于网络,如有侵权,请联系作者删除!