本文整理了Java中com.gemstone.gemfire.cache.query.Query.execute
方法的一些代码示例,展示了Query.execute
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.execute
方法的具体详情如下:
包路径:com.gemstone.gemfire.cache.query.Query
类名称:Query
方法名:execute
[英]Executes this query and returns an object that represent its result. If the query resolves to a primitive type, an instance of the corresponding wrapper type ( java.lang.Integer, etc.) is returned. If the query resolves to more than one object, a SelectResults is returned. Query execution can potentially take a long time depending on data size and query complexity. The system property "gemfire.Cache.MAX_QUERY_EXECUTION_TIME" can be set to define the maximum time allowed for a query to complete its execution. If query execution time exceeds "gemfire.Cache.MAX_QUERY_EXECUTION_TIME", then the query is canceled and QueryExecutionTimeoutException is thrown back to the caller, if the execution is local to the VM. If the canceled query was initiated by a GemFire client, then a QueryException is thrown on the client with its cause set to QueryExecutionTimeoutException. This timeout does not account for the time taken to construct the results after execution completes and the results returned to the caller.
[中]执行此查询并返回表示其结果的对象。如果查询解析为基元类型,则返回相应包装类型(java.lang.Integer等)的实例。如果查询解析为多个对象,则返回SelectResults。根据数据大小和查询复杂性,查询执行可能需要很长时间。系统属性“gemfire.Cache.MAX_QUERY_EXECUTION_TIME”可以设置为定义查询完成其执行所允许的最长时间。如果查询执行时间超过“gemfire.Cache.MAX_query_execution_time”,那么如果执行是VM本地的,则会取消查询,并将QueryExecutionTimeoutException抛出回调用者。如果取消的查询是由GemFire客户端启动的,则会在客户端上引发QueryException,其原因设置为QueryExecutionTimeoutException。此超时不考虑在执行完成并将结果返回给调用方后构造结果所需的时间。
代码示例来源:origin: org.apache.geode/gemfire-core
private List<?> getRemoveKeys(ExecutionHandlerContext context, ByteArrayWrapper key, int startRank, int stopRank) throws Exception {
Query query = getQuery(key, SortedSetQuery.ZREMRANGEBYRANK, context);
Object[] params = {stopRank + 1};
SelectResults<?> results = (SelectResults<?>) query.execute(params);
return results.asList().subList(startRank, stopRank + 1);
}
}
代码示例来源:origin: org.apache.geode/gemfire-core
private List<Struct> getRange(ExecutionHandlerContext context, ByteArrayWrapper key, int start, int stop, Region r) throws Exception {
Query query = getQuery(key, ListQuery.LRANGE, context);
Object[] params = {Integer.valueOf(stop + 1)};
SelectResults<Struct> results = (SelectResults<Struct>) query.execute(params);
int size = results.size();
if (results == null || size <= start) {
return null;
}
return results.asList().subList(start, size);
}
}
代码示例来源:origin: io.snappydata/gemfire-junit
/**
* Tests that hash index is used and that it returns the correct result
* @throws Exception
*/
private void helpTestHashIndexNotUsedInRangeQuery() throws Exception {
SelectResults results = (SelectResults)qs.newQuery("Select * FROM /portfolios p where p.ID < 2").execute();
assertFalse(observer.indexUsed);
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testShortNumSet() throws Exception {
Short num = Short.valueOf("1");
Object params[]=new Object[1];
params[0]= num;
Query q = CacheUtils.getQueryService().newQuery("$1 IN SET(1,2,3)");
Object result = q.execute(params);
System.out.println(Utils.printResult(result));
if(!result.equals(Boolean.TRUE))
fail("Failed for ShortNum with IN operator");
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testBug35905KeySet() throws Exception{
Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.keySet where toString = '1'");
Collection result = (Collection)query.execute();
if(!result.iterator().next().equals("1"))
fail(query.getQueryString());
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testStringSet() throws Exception {
Query q = CacheUtils.getQueryService().newQuery("'a' IN SET('x','y','z')");
Object result = q.execute();
System.out.println(Utils.printResult(result));
if(!result.equals(Boolean.FALSE))
fail("Failed for StringSet with IN operator");
}
代码示例来源:origin: org.apache.geode/gemfire-core
private int getRange(ExecutionHandlerContext context, ByteArrayWrapper key, ByteArrayWrapper member, DoubleWrapper valueWrapper) throws Exception {
Query query;
if (isReverse())
query = getQuery(key, SortedSetQuery.ZREVRANK, context);
else
query = getQuery(key, SortedSetQuery.ZRANK, context);
Object[] params = {valueWrapper.score, valueWrapper.score, member};
SelectResults<?> results = (SelectResults<?>) query.execute(params);
return (Integer) results.asList().get(0);
}
代码示例来源:origin: io.snappydata/gemfire-hydra-tests
public Object call() throws Exception {
QueryService qs = getCache().getQueryService();
Query q = qs.newQuery("select * from /sample where age < 50");
assertEquals(0, ((SelectResults)q.execute()).size());
return null;
}
});
代码示例来源:origin: io.snappydata/gemfire-junit
public void testGetValues() throws Exception{
Query query = CacheUtils.getQueryService().newQuery("select distinct * from /Portfolios.values where ID = 1");
Collection result = (Collection)query.execute();
Portfolio p = (Portfolio)result.iterator().next();
if(p.getID() != 1)
fail(query.getQueryString());
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testBindValueAsMethodParamter() throws Exception {
Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Portfolios where status.equals($1)");
Object params[] = new Object[1];
params[0] = "active";
Object result = query.execute(params);
if(result instanceof Collection){
int resultSize = ((Collection)result).size();
if( resultSize != 2)
fail("Results not as expected");
}else
fail("Invalid result");
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testFALSE() throws Exception{
Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Portfolios where FALSE");
Object result = query.execute();
if(!(result instanceof Collection) || ((Collection)result).size() != 0)
fail(query.getQueryString());
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testNULL() throws Exception{
Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Portfolios where NULL");
Object result = query.execute();
if(!(result instanceof Collection) || ((Collection)result).size() != 0)
fail(query.getQueryString());
query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM NULL");
result = query.execute();
if(!result.equals(QueryService.UNDEFINED))
fail(query.getQueryString());
}
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testParameterBinding() throws Exception {
Query q = qs.newQuery("select distinct * from /pos where ID = $1");
Object [] params = new Object[]{new Integer(0)};//{"active"};
Object r = q.execute(params);
CacheUtils.getLogger().fine(Utils.printResult(r));
q = qs.newQuery("select distinct * from $1 where status = $2 and ID = $3");
params = new Object[]{this.region, "active", new Integer(0)};
r = q.execute(params);
CacheUtils.getLogger().fine(Utils.printResult(r));
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void xtestVoidMethods() throws Exception {
Region region = CacheUtils.createRegion("Data", Data.class);
region.put("0", new Data());
Query query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Data where voidMethod");
Collection result = (Collection) query.execute();
if (result.size() != 0) fail(query.getQueryString());
query = CacheUtils.getQueryService().newQuery("SELECT DISTINCT * FROM /Data where voidMethod = null ");
result = (Collection) query.execute();
if (result.size() != 1) fail(query.getQueryString());
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testDistinct() throws Exception {
String queryString = "select distinct * from $1";
Query q = CacheUtils.getQueryService().newQuery(queryString);
SelectResults results = (SelectResults)q.execute(new Object[] { data });
assertEquals(4, results.size());
for (Iterator itr = data.iterator(); itr.hasNext(); ) {
Object element = itr.next();
assertTrue(results.contains(element));
assertEquals(1, results.occurrences(element));
}
CacheUtils.closeCache();
}
代码示例来源:origin: io.snappydata/gemfire-junit
private void helpTestIndexForQuery(String query, String indexedExpression, String regionPath) throws Exception {
QueryService qs = CacheUtils.getQueryService();
QueryObserverImpl observer = new QueryObserverImpl();
QueryObserverHolder.setInstance(observer);
SelectResults nonIndexedResults = (SelectResults)qs.newQuery(query).execute();
assertFalse(observer.isIndexesUsed);
qs.createIndex("newIndex", indexedExpression, regionPath);
SelectResults indexedResults = (SelectResults)qs.newQuery(query).execute();
assertEquals(nonIndexedResults.size(), indexedResults.size());
assertTrue(observer.isIndexesUsed);
}
代码示例来源:origin: io.snappydata/gemfire-junit
/**
* Make sure getLocalQueryService works.
*/
public void testBug42294() throws Exception {
ClientCache c = new ClientCacheFactory().create();
QueryService qs = c.getLocalQueryService();
ClientRegionFactory factory = c.createClientRegionFactory(LOCAL);
Region r1 = factory.create("localRegion");
Query q = qs.newQuery("SELECT * from /localRegion");
q.execute();
}
代码示例来源:origin: io.snappydata/gemfire-junit
public void testBug32375() throws Exception {
String queryStr;
Query q;
Object r;
queryStr = "import com.gemstone.gemfire.cache.\"query\".data.Portfolio; " +
"select distinct * from /pos, (select distinct * from /pos p TYPE Portfolio, p.positions where value!=null)";
q = qs.newQuery(queryStr);
// DebuggerSupport.waitForJavaDebugger(cache.getLogger());
CacheUtils.getLogger().fine(queryStr);
r = q.execute();
CacheUtils.getLogger().fine(Utils.printResult(r));
}
代码示例来源:origin: io.snappydata/gemfire-junit
private void helpTestHashIndexOrderByDescQuery() throws Exception {
index = (Index)qs.createHashIndex("idHash", "p.ID", "/portfolios p");
SelectResults results = (SelectResults)qs.newQuery("Select * FROM /portfolios p where p.ID != 0 order by ID desc ").execute();
assertEquals(199, results.size());
assertTrue(observer.indexUsed);
int countDown = 199;
for (Object o: results) {
Portfolio p = (Portfolio) o;
assertEquals(countDown--, p.getID());
}
}
代码示例来源:origin: io.snappydata/gemfire-junit
private void helpTestHashIndexOrderByAscQuery() throws Exception {
index = (Index)qs.createHashIndex("idHash", "p.ID", "/portfolios p");
SelectResults results = (SelectResults)qs.newQuery("Select * FROM /portfolios p where p.ID != 0 order by ID asc ").execute();
assertEquals(199, results.size());
assertTrue(observer.indexUsed);
int countUp = 1;
for (Object o: results) {
Portfolio p = (Portfolio) o;
assertEquals(countUp++, p.getID());
}
}
内容来源于网络,如有侵权,请联系作者删除!