javax.jdo.Query.setFilter()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(11.0k)|赞(0)|评价(0)|浏览(157)

本文整理了Java中javax.jdo.Query.setFilter方法的一些代码示例,展示了Query.setFilter的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setFilter方法的具体详情如下:
包路径:javax.jdo.Query
类名称:Query
方法名:setFilter

Query.setFilter介绍

[英]Set the filter for the query.

The filter specification is a String containing a Boolean expression that is to be evaluated for each of the instances in the candidate collection. If the filter is not specified, then it defaults to "true", which has the effect of filtering the input Collection only for class type.

An element of the candidate collection is returned in the result if:

  • it is assignment compatible to the candidate Class of the Query; and
  • for all variables there exists a value for which the filter expression evaluates to true.

The user may denote uniqueness in the filter expression by explicitly declaring an expression (for example, e1 != e2).

Rules for constructing valid expressions follow the Java language, except for these differences:

  • Equality and ordering comparisons between primitives and instances of wrapper classes are valid.
  • Equality and ordering comparisons of Date fields and Date parameters are valid.
  • White space (non-printing characters space, tab, carriage return, and line feed) is a separator and is otherwise ignored.
  • The assignment operators =, +=, etc. and pre- and post-increment and -decrement are not supported. Therefore, there are no side effects from evaluation of any expressions.
  • Methods, including object construction, are not supported, except for Collection.contains(Object o), Collection.isEmpty(), String.startsWith(String s), and String.endsWith(String e). Implementations might choose to support non-mutating method calls as non-standard extensions.
  • Navigation through a null-valued field, which would throw NullPointerException, is treated as if the filter expression returned false for the evaluation of the current set of variable values. Other values for variables might still qualify the candidate instance for inclusion in the result set.
  • Navigation through multi-valued fields (Collection types) is specified using a variable declaration and the Collection.contains(Object o) method.

Identifiers in the expression are considered to be in the name space of the specified class, with the addition of declared imports, parameters and variables. As in the Java language, this is a reserved word which means the element of the collection being evaluated.

Navigation through single-valued fields is specified by the Java language syntax of field_name.field_name....field_name.

A JDO implementation is allowed to reorder the filter expression for optimization purposes.
[中]设置查询的筛选器。
筛选器规范是一个String,其中包含一个布尔表达式,该表达式将针对候选集合中的每个实例进行计算。如果未指定过滤器,则默认为“true”,其效果是仅为类类型过滤输入Collection
在以下情况下,结果中将返回候选集合的元素:
*它与Query的候选人Class兼容;和
*对于所有变量,都存在一个筛选表达式计算为true的值。
用户可以通过显式声明表达式(例如,[$5$])来表示过滤器表达式中的唯一性。
构造有效表达式的规则遵循Java语言,但有以下区别:
*原语和包装类实例之间的相等性和顺序比较是有效的。
*Date字段和Date参数的相等性和顺序比较有效。
*空格(非打印字符空格、制表符、回车符和换行符)是分隔符,否则将被忽略。
*不支持赋值运算符=+=等以及前后递增和递减。因此,任何表达式的计算都没有副作用。
*不支持包括对象构造在内的方法,但Collection.contains(Object o)Collection.isEmpty()String.startsWith(String s)String.endsWith(String e)除外。实现可能会选择支持非变异方法调用作为非标准扩展。
*通过null值字段进行导航,该字段将抛出NullPointerException,就像过滤器表达式返回false以计算当前变量值集一样。变量的其他值可能仍然使候选实例有资格包含在结果集中。
*通过多值字段(Collection类型)的导航是使用变量声明和Collection.contains(Object o)方法指定的。
表达式中的标识符被认为位于指定类的名称空间中,并添加了声明的导入、参数和变量。在Java语言中,this是一个保留字,表示要计算的集合的元素。
通过单值字段的导航由field_name.field_name....field_name的Java语言语法指定。
为了优化,JDO实现可以对过滤器表达式重新排序。

代码示例

代码示例来源: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

@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;
 }
});

代码示例来源:origin: apache/hive

query.setFilter(queryFilterString);
Collection<String> names = (Collection<String>)query.executeWithMap(params);

代码示例来源: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 int deleteRuntimeStats(int maxRetainSecs) throws MetaException {
 if (maxRetainSecs < 0) {
  LOG.warn("runtime stats retention is disabled");
  return 0;
 }
 boolean committed = false;
 try {
  openTransaction();
  int maxCreateTime = (int) (System.currentTimeMillis() / 1000) - maxRetainSecs;
  Query q = pm.newQuery(MRuntimeStat.class);
  q.setFilter("createTime <= maxCreateTime");
  q.declareParameters("int maxCreateTime");
  long deleted = q.deletePersistentAll(maxCreateTime);
  committed = commitTransaction();
  return (int) deleted;
 } finally {
  if (!committed) {
   rollbackTransaction();
  }
 }
}

代码示例来源:origin: apache/hive

query.setFilter("param.contains(constraintName)");
query.declareParameters("java.util.Collection param");
Collection<?> constraints = (Collection<?>)query.execute(constraintNames);

代码示例来源: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

query.setFilter(filter);
query.declareParameters(paramStr);
query.setOrdering("partitionName ascending");

代码示例来源:origin: apache/hive

query.setFilter("this.table.database.catalogName == t1 && this.table.database.name == t2 "
  + "&& this.table.tableName == t3");
query.declareParameters("String t1, String t2, String t3");

代码示例来源:origin: apache/hive

query.setFilter("database.name == db && database.catalogName == cat && tbl_names.contains(tableName)");
query.declareParameters("java.lang.String db, java.lang.String cat, java.util.Collection tbl_names");
Collection mtables = (Collection) query.execute(db, catName, lowered_tbl_names);

代码示例来源:origin: apache/hive

String filter = getJDOFilterStrForPartitionVals(table, part_vals, params);
Query query = queryWrapper.query = pm.newQuery(MPartition.class);
query.setFilter(filter);
query.declareParameters(makeParameterDeclarationString(params));
if (max_parts >= 0) {

代码示例来源:origin: apache/hive

parameters = "java.lang.String t1, java.lang.String t2, java.lang.String t3, java.lang.String t4";
query.setFilter(filter);
query.declareParameters(parameters);
if (colName != null) {

代码示例来源:origin: apache/hive

query.setFilter(filter);
query.declareParameters(parameters);
if (colName != null) {

代码示例来源:origin: com.google.http-client/google-http-client-jdo

/**
 * Returns a new query for a given key.
 *
 * @param persistenceManager persistence manager
 * @return new new query for a given key
 */
Query newKeyQuery(PersistenceManager persistenceManager) {
 Query query = persistenceManager.newQuery(JdoValue.class);
 query.setFilter("id == idParam && key == keyParam");
 query.declareParameters("String idParam, String keyParam");
 return query;
}

代码示例来源:origin: com.google.http-client/google-http-client-jdo

/**
 * Returns a new query for all keys.
 *
 * @param persistenceManager persistence manager
 * @return new query for all keys
 */
Query newAllKeysQuery(PersistenceManager persistenceManager) {
 Query query = persistenceManager.newQuery(JdoValue.class);
 query.setFilter("id == idParam");
 query.declareParameters("String idParam");
 return query;
}

代码示例来源:origin: anjuke/hwi

@SuppressWarnings("unchecked")
public List<MCrontab> runningCrontabs() {
  Query query = getPM().newQuery(MCrontab.class);
  query.setFilter("status == :status");
  query.setOrdering("id DESC");
  HashMap<String, Object> map = new HashMap<String, Object>();
  map.put("status", MCrontab.Status.RUNNING);
  return (List<MCrontab>) query.executeWithMap(map);
}

代码示例来源:origin: apache/sentry

private MSentryGMPrivilege getPrivilege(MSentryGMPrivilege privilege, PersistenceManager pm) {
 Query query = pm.newQuery(MSentryGMPrivilege.class);
 QueryParamBuilder paramBuilder = toQueryParam(privilege);
 query.setFilter(paramBuilder.toString());
 query.setUnique(true);
 MSentryGMPrivilege result = (MSentryGMPrivilege)query.executeWithMap(paramBuilder.getArguments());
 return result;
}

代码示例来源:origin: apache/incubator-sentry

private MSentryRole getMSentryRole(PersistenceManager pm, String roleName) {
 Query query = pm.newQuery(MSentryRole.class);
 query.setFilter("this.roleName == t");
 query.declareParameters("java.lang.String t");
 query.setUnique(true);
 MSentryRole sentryRole = (MSentryRole) query.execute(roleName);
 return sentryRole;
}

代码示例来源:origin: apache/sentry

public Boolean execute(PersistenceManager pm) throws Exception {
  pm.setDetachAllOnCommit(false); // No need to detach objects
  Query query = pm.newQuery(MSentryPrivilege.class);
  query.addExtension(LOAD_RESULTS_AT_COMMIT, "false");
  QueryParamBuilder paramBuilder = QueryParamBuilder.addUsersFilter(query,null, userNames);
  paramBuilder.add(SERVER_NAME, serverName);
  query.setFilter(paramBuilder.toString());
  query.setResult("count(this)");
  Long numPrivs = (Long) query.executeWithMap(paramBuilder.getArguments());
  return numPrivs > 0;
 }
});

代码示例来源:origin: apache/sentry

private MSentryRole getMSentryRole(PersistenceManager pm, String roleName) {
 Query query = pm.newQuery(MSentryRole.class);
 query.setFilter("this.roleName == t");
 query.declareParameters("java.lang.String t");
 query.setUnique(true);
 MSentryRole sentryRole = (MSentryRole) query.execute(roleName);
 return sentryRole;
}

相关文章