tags:

views:

52

answers:

1

The odata4j AppEngineConsumerExample demonstrates how to filter entities on string and numeric values with code similar to the following:

reportEntity("\nNon-discontinued product with reorderLevel > 25 (two filter predicates): " , 
            c.getEntities("Product")
            .filter("reorderLevel gt 25 and discontinued eq false")
            .top(1)
            .execute().first());

I'm fairly new to Java (my background is .NET/C#), but the above makes sense. However, I'm unsure how to do something similar for dates. The dates coming from my WCF OData service are formatted as "yyyy-MM-dd'T'HH:mm:ss".

Thanks in advance for your help!

A: 

It turns out this is a function of OData itself rather than odata4j. The string passed to the filter function in odata4j is the same expression that would be passed via a URL. I found tons of filter examples on the Netflix OData Catalog page.

To filter dates, use something like this:

reportEntity("\nProduct with order date greater than March 1, 2010: " , 
        c.getEntities("Product")
        .filter("OrderDate gt datetime'2010-03-01'")
        .top(1)
        .execute().first());
Andrew Dyer
Glad to hear you got this working. Seems like a a syntax for providing literal parameters would have been useful here. Or a query builder api. What do you think?
John Spurlock
A query builder API would have made this easier, but needing to know more about OData query syntax isn't much of an issue. Your library already saves me a TON of work.
Andrew Dyer