Objectify / datastore query with inequality filters for multiple data warehouse properties

I am trying to use the google app engine datastore in which I need to get the total salary of an employee for 2 date ranges. I need to provide a range of hours, i.e. startDate and endDate, since I can do this in the data store. I use objectify in the application data store.

+4
source share
1 answer

Take a look at the objectify wiki . The Query Execution section contains examples of how to create basic queries.

Let's assume that your entity looks something like this:

@Entity
public class Salary {
  Ref<Employee> employee;
  @Id 
  Long salaryId;
  @Index
  Date startDate;
  @Index
  Date endDate;
  Long salaryCents;
}

, , :

ofy().load(Salary.class).filter("startDate >", start).filter("startDate <=", end).list();

datastore docs * 'you ,

ofy().load(Salary.class).filter("startDate >", start).filter("endDate <=", end).list();

.

, Java-.

( , ) , :

Iterable<Key<Salary>> keys = ofy().load(Salary.class).filter("startDate >", start).keys();

:

ofy().load(Salary.class).filter("salaryId IN", keys).filter("endDate <=", end).list();

, IN , in-memory , .

, .

+7

Source: https://habr.com/ru/post/1612085/


All Articles