use of com.google.appengine.api.datastore.Query in project CodeU-Spring-2018 by maksymko.
the class PersistentDataStore method loadConversations.
/**
* Loads all Conversation 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<Conversation> loadConversations() throws PersistentDataStoreException {
List<Conversation> conversations = new ArrayList<>();
// Retrieve all conversations from the datastore.
Query query = new Query("chat-conversations");
PreparedQuery results = datastore.prepare(query);
for (Entity entity : results.asIterable()) {
try {
UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
UUID ownerUuid = UUID.fromString((String) entity.getProperty("owner_uuid"));
String title = (String) entity.getProperty("title");
Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
Conversation conversation = new Conversation(uuid, ownerUuid, title, creationTime);
conversations.add(conversation);
} catch (Exception e) {
// database entity definition mismatches, or service mismatches.
throw new PersistentDataStoreException(e);
}
}
return conversations;
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class CachedDatastoreService method fetchAsList_Keys.
public List<Key> fetchAsList_Keys(String kind, Filter filter, int limit) {
Query q = new Query(kind);
q.setFilter(filter);
q.setKeysOnly();
return fetchKeys(q, limit);
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class QueryHelper method fetchChildren.
/**
* This performs an ancestor query to fetch all children (within a limit)
* @param ds
* @param parent
* @param limit
* @return
*/
public List<CachedEntity> fetchChildren(Key parent, int limit) {
Query q = new Query();
q.setAncestor(parent);
return ds.fetchAsList(q, limit);
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class QueryHelper method getFilteredORList.
public List<CachedEntity> getFilteredORList(Cursor cursor, String kind, String fieldName, Object equalToValue, String fieldName2, Object equalToValue2, String fieldName3, Object equalToValue3) {
FilterPredicate f1 = new FilterPredicate(fieldName, FilterOperator.EQUAL, equalToValue);
FilterPredicate f2 = new FilterPredicate(fieldName2, FilterOperator.EQUAL, equalToValue2);
FilterPredicate f3 = new FilterPredicate(fieldName3, FilterOperator.EQUAL, equalToValue3);
Filter filter = CompositeFilterOperator.or(f1, f2, f3);
Query q = new Query(kind);
q.setFilter(filter);
return ds.fetchAsList(q, 1000, cursor);
}
use of com.google.appengine.api.datastore.Query in project Cached-Datastore by Emperorlou.
the class ShardedCounterService method readCounter.
/**
* Retrieves the value of the counter identified by the entity and fieldName.
*
* It attempts to return the memcache cache value. If that is null then the shards are
* queried for and counted instead.
*
* This method will return null if a sharded counter has not yet been initialized for the given entity-field.
*
* @param entity
* @param fieldName
* @return
*/
public Long readCounter(Key entityKey, String fieldName) {
long value = 0;
Query query = new Query(SHARD_COUNTER_KIND);
query.setFilter(getShardQueryFilterFor(entityKey, fieldName));
for (CachedEntity shard : ds.fetchAsList(query, 1000)) value += (Long) shard.getProperty("value");
return value;
}
Aggregations