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

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

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

Query.setRange介绍

[英]Set the range of results to return. The execution of the query is modified to return only a subset of results. If the filter would normally return 100 instances, and fromIncl is set to 50, and toExcl is set to 70, then the first 50 results that would have been returned are skipped, the next 20 results are returned and the remaining 30 results are ignored. An implementation should execute the query such that the range algorithm is done at the data store.
[中]设置要返回的结果范围。查询的执行被修改为只返回结果的子集。如果过滤器通常会返回100个实例,fromIncl设置为50,toExcl设置为70,那么将跳过前50个本应返回的结果,接下来20个结果将返回,其余30个结果将被忽略。实现应该执行查询,以便在数据存储中执行范围算法。

代码示例

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

Query query = pm.newQuery("javax.jdo.query.SQL", queryText);
if (max != null) {
 query.setRange(0, max.shortValue());

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

query.setResultClass(java.lang.String.class);
if (maxTables >= 0) {
 query.setRange(0, maxTables);

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

int maxEventResponse = MetastoreConf.getIntVar(conf, ConfVars.METASTORE_MAX_EVENT_RESPONSE);
int maxEvents = (rqst.getMaxEvents() < maxEventResponse && rqst.getMaxEvents() > 0) ? rqst.getMaxEvents() : maxEventResponse;
query.setRange(0, maxEvents);
Collection<MNotificationLog> events =
    (Collection) query.executeWithArray(parameterVals.toArray(new Object[parameterVals.size()]));

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

query.setRange(0, maxParts);

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

private List<String> getPartitionNamesNoTxn(String catName, String dbName, String tableName, short max) {
 List<String> pns = new ArrayList<>();
 if (max == 0) {
  return pns;
 }
 catName = normalizeIdentifier(catName);
 dbName = normalizeIdentifier(dbName);
 tableName = normalizeIdentifier(tableName);
 Query query =
   pm.newQuery("select partitionName from org.apache.hadoop.hive.metastore.model.MPartition "
     + "where table.database.name == t1 && table.tableName == t2 && table.database.catalogName == t3 "
     + "order by partitionName asc");
 query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
 query.setResult("partitionName");
 if (max > 0) {
  query.setRange(0, max);
 }
 Collection<String> names = (Collection<String>) query.execute(dbName, tableName, catName);
 pns.addAll(names);
 if (query != null) {
  query.closeAll();
 }
 return pns;
}

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

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

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

q.setRange(0, maxParts);

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

if (maxParts >= 0) {
 query.setRange(0, maxParts);

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

if (max >= 0) {
 query.setRange(0, max);

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

if (max_parts >= 0) {
 query.setRange(0, max_parts);

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

query.setUnique(true);
query.setOrdering("version descending");
query.setRange(0, 1);
MSchemaVersion mSchemaVersion = (MSchemaVersion)query.execute(name, dbName, catName);
pm.retrieve(mSchemaVersion);

代码示例来源:origin: stackoverflow.com

Query query = pm.newQuery(University.class,":p.contains(name)");
query.setOrdering("name asc");
query.setRange(0, 5);
List univs = q.execute(Arrays.asList(array));

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

@SuppressWarnings("unchecked")
public List<T> getItems() {
  if (items == null) {
    Query newQuery = query.getPersistenceManager().newQuery(query);
    int offset = (page - 1) * pageSize;
    newQuery.setRange(offset, offset + pageSize);
    items = (List<T>) newQuery.executeWithMap(map);
  }
  return items;
}

代码示例来源:origin: org.spark-project.hive/hive-metastore

private List<String> getPartitionNamesNoTxn(String dbName, String tableName, short max) {
 List<String> pns = new ArrayList<String>();
 dbName = HiveStringUtils.normalizeIdentifier(dbName);
 tableName = HiveStringUtils.normalizeIdentifier(tableName);
 Query q = pm.newQuery(
   "select partitionName from org.apache.hadoop.hive.metastore.model.MPartition "
   + "where table.database.name == t1 && table.tableName == t2 "
   + "order by partitionName asc");
 q.declareParameters("java.lang.String t1, java.lang.String t2");
 q.setResult("partitionName");
 if(max > 0) {
  q.setRange(0, max);
 }
 Collection names = (Collection) q.execute(dbName, tableName);
 for (Iterator i = names.iterator(); i.hasNext();) {
  pns.add((String) i.next());
 }
 return pns;
}

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

/**
 * Checks if the table associated with class provided is empty
 *
 * @param pm PersistenceManager
 * @param clazz class
 * @return True is the table is empty
 * False if it not.
 */
private boolean isTableEmptyCore(PersistenceManager pm, Class clazz) {
 Query query = pm.newQuery(clazz);
 query.addExtension(LOAD_RESULTS_AT_COMMIT, "false");
 // setRange is implemented efficiently for MySQL, Postgresql (using the LIMIT SQL keyword)
 // and Oracle (using the ROWNUM keyword), with the query only finding the objects required
 // by the user directly in the datastore. For other RDBMS the query will retrieve all
 // objects up to the "to" record, and will not pass any unnecessary objects that are before
 // the "from" record.
 query.setRange(0, 1);
 return ((List<?>) query.execute()).isEmpty();
}

代码示例来源:origin: com.facebook.presto.hive/hive-apache

private List<String> getPartitionNamesNoTxn(String dbName, String tableName, short max) {
 List<String> pns = new ArrayList<String>();
 dbName = HiveStringUtils.normalizeIdentifier(dbName);
 tableName = HiveStringUtils.normalizeIdentifier(tableName);
 Query q = pm.newQuery(
   "select partitionName from org.apache.hadoop.hive.metastore.model.MPartition "
   + "where table.database.name == t1 && table.tableName == t2 "
   + "order by partitionName asc");
 q.declareParameters("java.lang.String t1, java.lang.String t2");
 q.setResult("partitionName");
 if(max > 0) {
  q.setRange(0, max);
 }
 Collection names = (Collection) q.execute(dbName, tableName);
 for (Iterator i = names.iterator(); i.hasNext();) {
  pns.add((String) i.next());
 }
 return pns;
}

代码示例来源:origin: org.apache.hive/hive-standalone-metastore

private List<String> getPartitionNamesNoTxn(String catName, String dbName, String tableName, short max) {
 List<String> pns = new ArrayList<>();
 if (max == 0) {
  return pns;
 }
 catName = normalizeIdentifier(catName);
 dbName = normalizeIdentifier(dbName);
 tableName = normalizeIdentifier(tableName);
 Query query =
   pm.newQuery("select partitionName from org.apache.hadoop.hive.metastore.model.MPartition "
     + "where table.database.name == t1 && table.tableName == t2 && table.database.catalogName == t3 "
     + "order by partitionName asc");
 query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
 query.setResult("partitionName");
 if (max > 0) {
  query.setRange(0, max);
 }
 Collection<String> names = (Collection<String>) query.execute(dbName, tableName, catName);
 pns.addAll(names);
 if (query != null) {
  query.closeAll();
 }
 return pns;
}

代码示例来源:origin: tzaeschke/zoodb

@Test
public void testRangeIntFunctionFail() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = null; 
  q = pm.newQuery(TestClass.class);
  try {
    q.setRange(-1, 3);
    fail();
  } catch (JDOUserException e) {
    //good
  }
  
  try {
    q.setRange(3, 1);
    fail();
  } catch (JDOUserException e) {
    //good
  }
  TestTools.closePM();
}

代码示例来源:origin: tzaeschke/zoodb

@SuppressWarnings("unchecked")
@Test
public void testRangeWithParams() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = pm.newQuery(TestClass.class);
  
  List<TestClass> c0 = (List<TestClass>) q.execute();
  List<TestClass> a0 = new ArrayList<>(c0);
  q.setRange(":min, :max");
  List<TestClass> c2 = (List<TestClass>) q.execute(0, 5);
  List<TestClass> a2 = new ArrayList<>(c2);
  assertEquals(a0, a2);
  List<TestClass> c3 = (List<TestClass>) q.execute(1, 4);
  List<TestClass> a3 = new ArrayList<>(c3);
  for (int i = 1; i <= 3; i++) {
    assertEquals(a0.get(i).getString(), a3.get(i-1).getString());
  }
  
  TestTools.closePM();
}

代码示例来源:origin: tzaeschke/zoodb

private void checkSetRangeFails(PersistenceManager pm, String s) {
  Query q1 = pm.newQuery(TestClass.class);
  try {
    q1.setRange(s);
    q1.compile();
    fail();
  } catch (JDOUserException e) {
    //good, we got an JDOUSerException()
  }
  
  try {
    Query q2 = pm.newQuery(TestClass.class, "RANGE " + s);
    q2.compile();
    fail();
  } catch (JDOUserException e) {
    //good, we got an JDOUSerException()
  }
}

相关文章