2

Is there a way to consume Odata Service from Android using Odata4j or any other library that contain SELECT WHERE Clause statement

I searched a lot but can't find any solution

omar
  • 41
  • 1
  • 9

2 Answers2

0

For odata4j you need to instantiate a ODataConsumer Object - let's call it consumer. With this object you are able to perform any desired database actions. For example:

OEntity result = consumer.getEntities("YourEntityName").filter("Field2 eq 'xyz'").select("Field1, Field2, Field3").execute();

This would resemble the following SQL query

SELECT Field1, Field2, Field3 FROM YourEntityName WHERE Field2 = 'xyz'

For more information regarding the string arguments for filter() and select() you should have a look into the odata documentation at odata.org -> URI conventions.

If you want to understand the java functions of odata4j use the documentation at odata4j documentation.

I can also recommend the odata4j example files.

Daniel
  • 3,541
  • 3
  • 33
  • 46
  • it works fine but what if I wanted query like this : SELECT Field1, Field2, Field3,Field 4 FROM EntityName1,EntityName2 WHERE Field2 = 'xyz' I made another statement like OEntity result = consumer.getEntities("EntityName2").select("Field4").execute(); but of course it didn't work as I want as by logic it did't contain the relation between EntityName1,EntityName1 represnted in Field2 as a KEY between the two entities . – omar Mar 01 '14 at 23:21
  • Thanks , for my final question , I found this https://code.google.com/p/odata4j/issues/attachmentText?id=30&aid=2700512303282867111&name=NorthwindConsumerExample.java&token=0d2faaa992f33d4d6289279b067a9d03 – omar Mar 02 '14 at 01:46
0

Nice question......

We can access the odata service by using AsyncHttpClient in android.

Here we need to override some methods ,and its taking RequestParams as a parameter will return data as json or xml.

you can read more on AsyncHttpClient Here :http://loopj.com/android-async-http/

here we can pass RequestParams,it will take select as key and query as your original query. try it and let me know if you have any issues

Surya Reddy
  • 1,243
  • 8
  • 15