How to persist Joda Money entities using Ofy v5? (Continued)

42 views
Skip to first unread message

David Fuelling

unread,
May 5, 2014, 3:45:24 PM5/5/14
to objectify...@googlegroups.com
This is a continuation of the discussion here.  For some reason I am unable to make new posts on that thread, but new threads seem to be working fine, so here goes.

--


    Hey Guys,
     
    Great discussion. I agree with Jeff's comment above, with a caveat. So, I 
    agree that the default Objectify BigDecimal and Money/BigMoney translators 
    will work just fine for queries on an indexed property doing equality 
    matching (e.g., find all widgets with price="USD $50.00"). However, the 
    potential problem with the default translators is they may not work 
    properly when the Datastore performs a greater-than/less-than filter or an 
    ordered Datastore query based upon one of these indexed fields (e.g., 
    return all stocks with a "price" > "USD $50.00", or return all stocks 
    ordered by "price" in ascending order).
     
    This is because of the difference between numeric comparison and 
    lexicographic comparison. For example, we all know that the number 11.25 
    is less-than the number 100.25, but when converted to a String and compared 
    lexicographically, the String "11.25" is actually greater-than "100.25". 
    While correct from a lexicographic/String comparison perspective, this is 
    quite incorrect from a numeric and/or currency perspective (e.g., "USD 
    $11.25" is going to be greater-than "USD $100.25", when in actuality it 
    should be less-than).
     
    Again, this is only a problem when dealing with ordered filters and/or 
    sorts via the Datastore. Equality queries should work just fine 
    with either translator.
     
    If anyone is interested, I've collected some thoughts and research around 
    this topic here:
    http://softwareblog.sappenin.com/2014/05/best-practices-for-storing-joda-money.html
     
    Hope that helps!
     
    Thanks,
    david
Reply all
Reply to author
Forward
0 new messages