use of com.google.appengine.api.datastore.Query in project CodeU-Spring-2018 by jwang281.
the class PersistentDataStore method loadUsers.
/**
* Loads all User objects from the Datastore service and returns them in a List.
*
* @throws PersistentDataStoreException if an error was detected during the load from the
* Datastore service
*/
public List<User> loadUsers() throws PersistentDataStoreException {
List<User> users = new ArrayList<>();
// Retrieve all users from the datastore.
Query query = new Query("chat-users");
PreparedQuery results = datastore.prepare(query);
for (Entity entity : results.asIterable()) {
try {
UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
String userName = (String) entity.getProperty("username");
String password = (String) entity.getProperty("password");
Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
User user = new User(uuid, userName, password, creationTime);
users.add(user);
} catch (Exception e) {
// database entity definition mismatches, or service mismatches.
throw new PersistentDataStoreException(e);
}
}
return users;
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class CachedDatastoreService method fetchAsList.
public List<CachedEntity> fetchAsList(String kind, Filter filter, int limit) {
Query q = new Query(kind);
q.setFilter(filter);
return fetchAsList(q, limit);
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class CachedDatastoreService method fetchAsList.
public List<CachedEntity> fetchAsList(String kind, Filter filter, int limit, Cursor startEntityCursor) {
Query q = new Query(kind);
q.setFilter(filter);
List<Key> keys = fetchKeys(q, limit, startEntityCursor);
return fetchEntitiesFromKeys(keys);
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class QueryHelper method getFilteredList_Count.
public Long getFilteredList_Count(String kind, Integer limit, String fieldName, FilterOperator operator, Object equalToValue, String fieldName2, FilterOperator operator2, Object equalToValue2, String fieldName3, FilterOperator operator3, Object equalToValue3) {
Query q = new Query(kind);
FilterPredicate f1 = new FilterPredicate(fieldName, operator, equalToValue);
FilterPredicate f2 = new FilterPredicate(fieldName2, operator2, equalToValue2);
FilterPredicate f3 = new FilterPredicate(fieldName3, operator3, equalToValue3);
Filter f = CompositeFilterOperator.and(f1, f2, f3);
q.setFilter(f);
return ds.countEntities(q, 5000);
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class ShardedCounterService method resetCounter.
/**
* This method is used to reset the counter back to 0. It deletes all shards.
*
* @param entity
* @param key
*/
public void resetCounter(Key entityKey, String fieldName) {
Query query = new Query(SHARD_COUNTER_KIND);
query.setFilter(getShardQueryFilterFor(entityKey, fieldName));
query.setKeysOnly();
List<Key> keys = new ArrayList<>();
for (CachedEntity en : ds.fetchAsIterable(query)) {
keys.add(en.getKey());
}
ds.delete(keys);
}
Aggregations