private DefaultQuery mockQuery() { InternalQueryService queryService = mock(InternalQueryService.class); when(cache.getQueryService()).thenReturn(queryService); DefaultQuery query = mock(DefaultQuery.class); when(queryService.newQuery(any())).thenReturn(query); when(query.getRegionsInQuery(any())).thenReturn(Collections.singleton(REGION)); return query; }
@Override public Object call() throws RegionNotFoundException, CqExistsException, IndexExistsException, IndexNameConflictException { getCache().getQueryService().createIndex(indexName, indexedExpression, regionPath); return true; } });
@Override public Object call() throws CqException, RegionNotFoundException { getCache().getQueryService().getCq(cqName).executeWithInitialResults(); return true; } });
try { methodDispatch = new MethodDispatch(context.getCache().getQueryService().getMethodInvocationAuthorizer(), resolutionType, this.methodName, argTypes); } catch (NameResolutionException nre) {
@Override public Object call() throws CqException, RegionNotFoundException, CqExistsException { CqAttributes attrs = cqAttr; if (attrs == null) { attrs = createDummyCqAttributes(); } getCache().getQueryService().newCq(cqName, query, attrs); return true; } });
@Override public Object call() throws RegionNotFoundException, CqExistsException, IndexExistsException, IndexNameConflictException { Region region = getCache().getRegion("/" + regionName); CompactRangeIndex index = (CompactRangeIndex) getCache().getQueryService().getIndex(region, indexName); System.out.println(index.dump()); return true; } });
@After public void after() throws Exception { // destroy all existing indexes Collection<Index> indices = server.getCache().getQueryService().getIndexes(); indices.stream().map(Index::getName).forEach(indexName -> { gfsh.executeAndAssertThat("destroy index --name=" + indexName).statusIsSuccess(); }); gfsh.executeAndAssertThat("list index").statusIsSuccess(); assertThat(gfsh.getGfshOutput()).contains("No Indexes Found"); }
context.getCache().getQueryService().getMethodInvocationAuthorizer(), name) .validateReadType(clazz);
@Override public Object query(String queryString, Object[] bindParameters) throws NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { InternalQueryService queryService = cache.getQueryService(); Query query = queryService.newQuery(queryString); for (String regionName : ((DefaultQuery) query).getRegionsInQuery(bindParameters)) { security.authorize(DATA, READ, regionName, ALL); } Object result = query.execute(bindParameters); if (security.needsPostProcessing()) { return postProcessQueryResults(result); } else { return result; } }
} else { member = new AttributeDescriptor(context.getCache().getPdxRegistry(), context.getCache().getQueryService().getMethodInvocationAuthorizer(), stepStr) .getReadMember(clazz);
@Test public void queryForSingleObject() throws ConnectionStateException, DecodingException, InvalidExecutionContextException, EncodingException, NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { Query query = mock(DefaultQuery.class); when(queryService.newQuery(eq(SELECT_STAR_QUERY))).thenReturn(query); when(query.execute((Object[]) any())).thenReturn(STRING_RESULT_1); final OQLQueryRequest request = OQLQueryRequest.newBuilder().setQuery(SELECT_STAR_QUERY).build(); final Result<OQLQueryResponse> result = operationHandler.process(serializationService, request, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertEquals(serializationService.encode(STRING_RESULT_1), result.getMessage().getSingleResult()); }
/** * @param pathArray the path starting with an attribute on the initial type. * @return array of types starting with the initialType and ending with the type of the last * attribute in the path. * @throws NameNotFoundException if could not find an attribute along path * */ public static ObjectType[] calculateTypesAlongPath(ExecutionContext context, ObjectType initialType, String[] pathArray) throws NameNotFoundException { ObjectType[] types = new ObjectType[pathArray.length + 1]; // initialClass goes in front types[0] = initialType; for (int i = 1; i < types.length; i++) { ObjectType currentType = types[i - 1]; Member member = new AttributeDescriptor(context.getCache().getPdxRegistry(), context.getCache().getQueryService().getMethodInvocationAuthorizer(), pathArray[i - 1]) .getReadMember(currentType.resolveClass()); if (member instanceof Field) types[i] = TypeUtils.getObjectType(((Field) member).getType()); else if (member instanceof Method) types[i] = TypeUtils.getObjectType(((Method) member).getReturnType()); } return types; }
@Test public void queryForMultipleObjects() throws ConnectionStateException, DecodingException, InvalidExecutionContextException, EncodingException, NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { Query query = mock(DefaultQuery.class); when(queryService.newQuery(eq(SELECT_STAR_QUERY))).thenReturn(query); SelectResults results = new ResultsBag(); results.setElementType(new ObjectTypeImpl()); results.add(STRING_RESULT_1); results.add(STRING_RESULT_2); when(query.execute((Object[]) any())).thenReturn(results); final OQLQueryRequest request = OQLQueryRequest.newBuilder().setQuery(SELECT_STAR_QUERY).build(); final Result<OQLQueryResponse> result = operationHandler.process(serializationService, request, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertEquals(Arrays.asList(STRING_RESULT_1, STRING_RESULT_2), result.getMessage().getListResult().getElementList().stream() .map(serializationService::decode).collect(Collectors.toList())); }
public static Object evaluateAttribute(ExecutionContext context, Object target, String attribute) throws NameNotFoundException, QueryInvocationTargetException { if (target instanceof Struct) { Struct struct = (Struct) target; try { return struct.get(attribute); } catch (Exception e) { throw new NameNotFoundException(attribute); } } try { return new AttributeDescriptor(context.getCache().getPdxRegistry(), context.getCache().getQueryService().getMethodInvocationAuthorizer(), attribute) .read(target); } catch (NameNotFoundException nfe) { if (DefaultQueryService.QUERY_HETEROGENEOUS_OBJECTS || DefaultQueryService.TEST_QUERY_HETEROGENEOUS_OBJECTS) { return QueryService.UNDEFINED; } else { throw nfe; } } }
queryArgs[0] = argsList.get(0); final Query query = cache.getQueryService().newQuery(oql);
DefaultQuery query = (DefaultQuery) cache.getQueryService().newQuery(queryString); results = lds.executeQuery(query, null, localPrimaryBucketSet);
@Test public void queryForMultipleStructs() throws ConnectionStateException, DecodingException, InvalidExecutionContextException, EncodingException, NameResolutionException, TypeMismatchException, QueryInvocationTargetException, FunctionDomainException { Query query = mock(DefaultQuery.class); when(queryService.newQuery(eq(SELECT_STAR_QUERY))).thenReturn(query); SelectResults results = new LinkedStructSet(); StructTypeImpl elementType = new StructTypeImpl(new String[] {"field1"}); results.setElementType(elementType); results.add(new StructImpl(elementType, new Object[] {STRING_RESULT_1})); results.add(new StructImpl(elementType, new Object[] {STRING_RESULT_2})); when(query.execute((Object[]) any())).thenReturn(results); final OQLQueryRequest request = OQLQueryRequest.newBuilder().setQuery(SELECT_STAR_QUERY).build(); final Result<OQLQueryResponse> result = operationHandler.process(serializationService, request, TestExecutionContext.getNoAuthCacheExecutionContext(cacheStub)); assertEquals( Arrays.asList( BasicTypes.EncodedValueList.newBuilder() .addElement(serializationService.encode(STRING_RESULT_1)).build(), BasicTypes.EncodedValueList.newBuilder() .addElement(serializationService.encode(STRING_RESULT_2)).build()), result.getMessage().getTableResult().getRowList()); }