-
1. Re: Using DSL and trying to use reflections to drive building the query
anistor Mar 6, 2014 7:53 PM (in response to van.halbert)1 of 1 people found this helpfulHi Van,
the definitive source of metadata is the protobuf definition file, not the java or the cpp class you are using to represent the data. The marshallers (eg PersonMarshaller) are responsible for mapping your data (Person class) to a Person message type, the one defined in the protobuf file. The mapping is done in the readFrom/writeTo methods of the marshaller. Trying to do some guessing based on Java reflection is a bit like trying to guess what readFrom/writeTo methods are doing - flawed in most cases, although it can work if you follow some rigorous mapping conventions. But I would not recommend going the reflection route. It's easier to obtain the metadata from the proto file. You don't need to actually parse it yourself, it's parsed already. ProtoStreamMarshaller.getSerializationContext(cacheManager).getMessageDescriptor("quickstart.Person") will give you a com.google.protobuf.Descriptors.Descriptor for the quickstart.Person protobuf type, which has all you need (see here https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/Descriptors.Descriptor)
Cheers
-
2. Re: Using DSL and trying to use reflections to drive building the query
anistor Mar 6, 2014 7:56 PM (in response to anistor)Btw,
in
{code}
Query query = qf.from(Person.class)
.having("phone.number").eq(phoneNumber).toBuilder()
.build();
{code}
"phone.number" refers to the protobuf property, not the java property. The java property could have been named a bit differently, the only one who has toe deal with the mapping is the marshaller. -
3. Re: Using DSL and trying to use reflections to drive building the query
van.halbert Mar 6, 2014 8:34 PM (in response to anistor)This is great. Thanks.
This will definitely simplify the task of mapping it to a relational structure.
Cheers.
-
4. Re: Using DSL and trying to use reflections to drive building the query
van.halbert Apr 1, 2014 6:29 PM (in response to anistor)Do you have a data type mapping matrix between the protobuf types and java object types that you can point me to?
Thanks.
-
5. Re: Using DSL and trying to use reflections to drive building the query
van.halbert Apr 1, 2014 7:08 PM (in response to van.halbert)I think I found it, the FieldDescriptor.getJavaType(). Sorry, I should have looked deeper first before asking. But you never know how deep you have to look.
Thanks.
Van