简体   繁体   中英

How to filter on basis of JodaTime in objectify

I am new to Google Appengine. In my application, the datastore entities store a org.joda.time.DateTime object. I want to query the datastore to return all the entities in between a range of 2 particular DateTime. My code for this is :

@Entity
@Cache
@Index
public class Sample {

    @Id
    Long id; // autogen

    private DateTime dateTime;
    private int activeCount;
    private int inactiveCount;
}

I want a query similar to -

 Iterable<Sample> sampleIterable = ofy().load().type(Sample.class)
                    .filter("dateTime <", DateTime.now())
                    .filter("dateTime >", DateTime.now().minusDays(1))
                    .iterable();

Is it possible to query the DateTime like this ? What would be the correct way to query DateTime in objectify ? I am sorry for the lack of clearity.

If you register the Joda translators with Objectify, you can use DateTime as both a field and a filter clause. You can use DateTime to filter against regular Date properties too.

JodaTimeTranslators.add(ObjectifyService.factory());

This is not enabled by default because everyone would then need to include joda time as a dependency.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM