private List<T> parseListResult(final OQLQueryResponse response) { return response.getListResult().getElementList().stream() .map(value -> (T) valueEncoder.decodeValue(value)).collect(Collectors.toList()); }
private List<Object> parseSingleResult(final OQLQueryResponse response) { return Collections.singletonList(valueEncoder.decodeValue(response.getSingleResult())); } }
private List<Map<String, Object>> parseTableResult(final OQLQueryResponse response) { final Table table = response.getTableResult(); final ProtocolStringList fieldNames = table.getFieldNameList(); List<Map<String, Object>> results = new ArrayList<>(); for (BasicTypes.EncodedValueList row : table.getRowList()) { final List<Object> decodedRow = row.getElementList().stream().map(valueEncoder::decodeValue) .collect(Collectors.toList()); Map<String, Object> rowMap = new LinkedHashMap<>(decodedRow.size()); for (int i = 0; i < decodedRow.size(); i++) { rowMap.put(fieldNames.get(i), decodedRow.get(i)); } results.add(rowMap); } return results; }
case 27: result = result && getOqlQueryResponse() .equals(other.getOqlQueryResponse()); break; case 28:
@java.lang.Override public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse buildPartial() { org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse result = new org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse(this); if (resultCase_ == 1) { if (singleResultBuilder_ == null) { result.result_ = result_; } else { result.result_ = singleResultBuilder_.build(); } } if (resultCase_ == 2) { if (listResultBuilder_ == null) { result.result_ = result_; } else { result.result_ = listResultBuilder_.build(); } } if (resultCase_ == 3) { if (tableResultBuilder_ == null) { result.result_ = result_; } else { result.result_ = tableResultBuilder_.build(); } } result.resultCase_ = resultCase_; onBuilt(); return result; }
@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()); }
result = result && getResultCase().equals( other.getResultCase()); if (!result) return false; switch (resultCase_) { case 1: result = result && getSingleResult() .equals(other.getSingleResult()); break; case 2: result = result && getListResult() .equals(other.getListResult()); break; case 3: result = result && getTableResult() .equals(other.getTableResult()); break; case 0:
@java.lang.Override public int hashCode() { if (memoizedHashCode != 0) { return memoizedHashCode; } int hash = 41; hash = (19 * hash) + getDescriptor().hashCode(); switch (resultCase_) { case 1: hash = (37 * hash) + SINGLERESULT_FIELD_NUMBER; hash = (53 * hash) + getSingleResult().hashCode(); break; case 2: hash = (37 * hash) + LISTRESULT_FIELD_NUMBER; hash = (53 * hash) + getListResult().hashCode(); break; case 3: hash = (37 * hash) + TABLERESULT_FIELD_NUMBER; hash = (53 * hash) + getTableResult().hashCode(); break; case 0: default: } hash = (29 * hash) + unknownFields.hashCode(); memoizedHashCode = hash; return hash; }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.OQLQueryResponse oqlQueryResponse = 27;</code> */ public Builder mergeOqlQueryResponse(org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse value) { if (oqlQueryResponseBuilder_ == null) { if (messageTypeCase_ == 27 && messageType_ != org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance()) { messageType_ = org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.newBuilder((org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse) messageType_) .mergeFrom(value).buildPartial(); } else { messageType_ = value; } onChanged(); } else { if (messageTypeCase_ == 27) { oqlQueryResponseBuilder_.mergeFrom(value); } oqlQueryResponseBuilder_.setMessage(value); } messageTypeCase_ = 27; return this; } /**
private OQLQueryResponse encodeResults(final ProtobufSerializationService serializationService, final Object value) throws EncodingException { final Builder builder = OQLQueryResponse.newBuilder(); // The result is a single value if (!(value instanceof SelectResults)) { builder.setSingleResult(serializationService.encode(value)); return builder.build(); } SelectResults<?> selectResults = (SelectResults<?>) value; // The result is a list of objects if (!selectResults.getCollectionType().getElementType().isStructType()) { BasicTypes.EncodedValueList.Builder listResult = BasicTypes.EncodedValueList.newBuilder(); selectResults.stream().map(serializationService::encode).forEach(listResult::addElement); builder.setListResult(listResult); return builder.build(); } // The result is a list of structs SelectResults<Struct> structResults = (SelectResults<Struct>) selectResults; StructType elementType = (StructType) structResults.getCollectionType().getElementType(); BasicTypes.Table.Builder tableResult = BasicTypes.Table.newBuilder(); tableResult.addAllFieldName(Arrays.asList(elementType.getFieldNames())); for (Struct row : structResults) { tableResult.addRow(encodeStruct(serializationService, row)); } builder.setTableResult(tableResult); return builder.build(); }
@Override public List<T> execute(final Object... bindParameters) throws IOException { List<EncodedValue> encodedParameters = Arrays.asList(bindParameters).stream() .map(valueEncoder::encodeValue).collect(Collectors.toList());; Message request = Message.newBuilder().setOqlQueryRequest( OQLQueryRequest.newBuilder().addAllBindParameter(encodedParameters).setQuery(queryString)) .build(); final OQLQueryResponse response = channel.sendRequest(request, MessageTypeCase.OQLQUERYRESPONSE).getOqlQueryResponse(); switch (response.getResultCase()) { case SINGLERESULT: return (List<T>) parseSingleResult(response); case LISTRESULT: return parseListResult(response); case TABLERESULT: return (List<T>) parseTableResult(response); default: throw new RuntimeException("Unexpected response: " + response); } }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.OQLQueryResponse oqlQueryResponse = 27;</code> */ private com.google.protobuf.SingleFieldBuilderV3< org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.Builder, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponseOrBuilder> getOqlQueryResponseFieldBuilder() { if (oqlQueryResponseBuilder_ == null) { if (!(messageTypeCase_ == 27)) { messageType_ = org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance(); } oqlQueryResponseBuilder_ = new com.google.protobuf.SingleFieldBuilderV3< org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.Builder, org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponseOrBuilder>( (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse) messageType_, getParentForChildren(), isClean()); messageType_ = null; } messageTypeCase_ = 27; onChanged();; return oqlQueryResponseBuilder_; }
public Builder mergeFrom(org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse other) { if (other == org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance()) return this; switch (other.getResultCase()) { case SINGLERESULT: { mergeSingleResult(other.getSingleResult()); break; } case LISTRESULT: { mergeListResult(other.getListResult()); break; } case TABLERESULT: { mergeTableResult(other.getTableResult()); break; } case RESULT_NOT_SET: { break; } } this.mergeUnknownFields(other.unknownFields); onChanged(); return this; }
@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())); }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.OQLQueryResponse oqlQueryResponse = 27;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse getOqlQueryResponse() { if (oqlQueryResponseBuilder_ == null) { if (messageTypeCase_ == 27) { return (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse) messageType_; } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance(); } else { if (messageTypeCase_ == 27) { return oqlQueryResponseBuilder_.getMessage(); } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance(); } } /**
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.OQLQueryResponse oqlQueryResponse = 27;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponseOrBuilder getOqlQueryResponseOrBuilder() { if ((messageTypeCase_ == 27) && (oqlQueryResponseBuilder_ != null)) { return oqlQueryResponseBuilder_.getMessageOrBuilder(); } else { if (messageTypeCase_ == 27) { return (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse) messageType_; } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance(); } } /**
@java.lang.Override public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
private void checkResults(final String query, EncodedValue[] bindParameters, String[] fieldnames, final Object[]... rows) throws InvalidExecutionContextException, ConnectionStateException, EncodingException, DecodingException { ProtobufSerializationService serializer = new ProtobufSerializationService(); final Result<OQLQueryResponse> results = invokeHandler(query, bindParameters, serializer); List<BasicTypes.EncodedValueList> expected = new ArrayList<>(); for (Object[] row : rows) { List<EncodedValue> encodedRow = Arrays.asList(row).stream().map(serializer::encode).collect(Collectors.toList()); expected.add(BasicTypes.EncodedValueList.newBuilder().addAllElement(encodedRow).build()); } assertEquals(expected, results.getMessage().getTableResult().getRowList()); assertEquals(Arrays.asList(fieldnames), results.getMessage().getTableResult().getFieldNameList()); }
@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()); }
/** * <code>.org.apache.geode.internal.protocol.protobuf.v1.OQLQueryResponse oqlQueryResponse = 27;</code> */ public org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponseOrBuilder getOqlQueryResponseOrBuilder() { if (messageTypeCase_ == 27) { return (org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse) messageType_; } return org.apache.geode.internal.protocol.protobuf.v1.RegionAPI.OQLQueryResponse.getDefaultInstance(); }