Search in sources :

Example 36 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project Cached-Datastore by Emperorlou.

the class QueryHelper method getFilteredList.

public List<CachedEntity> getFilteredList(String kind, String fieldName, Object equalToValue, String fieldName2, Object equalToValue2) {
    FilterPredicate f1 = new FilterPredicate(fieldName, FilterOperator.EQUAL, equalToValue);
    FilterPredicate f2 = new FilterPredicate(fieldName2, FilterOperator.EQUAL, equalToValue2);
    Filter filter = CompositeFilterOperator.and(f1, f2);
    return ds.fetchAsList(kind, filter, 1000);
}
Also used : CompositeFilter(com.google.appengine.api.datastore.Query.CompositeFilter) Filter(com.google.appengine.api.datastore.Query.Filter) FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate)

Example 37 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project getting-started-java by GoogleCloudPlatform.

the class DatastoreSessionFilter method init.

@Override
public void init(FilterConfig config) throws ServletException {
    // initialize local copy of datastore session variables
    datastore = DatastoreServiceFactory.getDatastoreService();
    // Delete all sessions unmodified for over two days
    DateTime dt = DateTime.now(DateTimeZone.UTC);
    Query query = new Query(SESSION_KIND).setFilter(new FilterPredicate("lastModified", FilterOperator.LESS_THAN_OR_EQUAL, dt.minusDays(2).toString(DTF)));
    Iterator<Entity> results = datastore.prepare(query).asIterator();
    while (results.hasNext()) {
        Entity stateEntity = results.next();
        datastore.delete(stateEntity.getKey());
    }
}
Also used : Entity(com.google.appengine.api.datastore.Entity) Query(com.google.appengine.api.datastore.Query) FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate) DateTime(org.joda.time.DateTime)

Example 38 with FilterPredicate

use of com.google.appengine.api.datastore.Query.FilterPredicate in project codeu-2018-team12 by codeu-2018-team12.

the class PersistentDataStore method setUpUserEntity.

/**
 * Retrieves a User Entity object
 *
 * @param user user in application
 * @return User Entity
 */
private Entity setUpUserEntity(User user) {
    Query query = new Query("chat-users").setFilter(new FilterPredicate("uuid", FilterOperator.EQUAL, user.getId().toString()));
    PreparedQuery preparedQuery = datastore.prepare(query);
    return preparedQuery.asSingleEntity();
}
Also used : FilterPredicate(com.google.appengine.api.datastore.Query.FilterPredicate)

Aggregations

FilterPredicate (com.google.appengine.api.datastore.Query.FilterPredicate)38 Query (com.google.appengine.api.datastore.Query)31 Entity (com.google.appengine.api.datastore.Entity)26 Filter (com.google.appengine.api.datastore.Query.Filter)24 Test (org.junit.Test)21 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)20 CompositeFilter (com.google.appengine.api.datastore.Query.CompositeFilter)20 Key (com.google.appengine.api.datastore.Key)6 DatastoreService (com.google.appengine.api.datastore.DatastoreService)3 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 StringWriter (java.io.StringWriter)2 FetchOptions (com.google.appengine.api.datastore.FetchOptions)1 Transaction (com.google.appengine.api.datastore.Transaction)1 Collection (java.util.Collection)1 List (java.util.List)1 DateTime (org.joda.time.DateTime)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1