public List<GeneralMessage> getUnreadMessages(String userId, String tagId, UserTags tags) { Query<UnreaddenMessage> q = ds.createQuery(UnreaddenMessage.class).field("userId").equal(userId.toString()); String order = tags.getOrder(); if (!tagId.equals(UserTags.ALL_TAGS)) { SocioTag tag = tags.getTag(tagId); order = tag.getOrder(); List<String> tagsIds = new ArrayList<String>(); List<SocioTag> leaves = tag.getLeaves(); for (SocioTag leaf : leaves) { tagsIds.add(leaf.getUniqueId()); } q.field("tagId").hasAnyOf(tagsIds); } if (order.equals(SocioTag.ASCENDING_ORDER)) { q.order("-messageDate"); } else { q.order("messageDate"); } q.limit(tags.getRange()); List<GeneralMessage> messagesList = new ArrayList<GeneralMessage>(); Iterable<UnreaddenMessage> messages = q.fetch(); for (UnreaddenMessage unreaddenMessage : messages) { messagesList.add(unreaddenMessage.getMessage()); } tags.setSelectedTag(tagId); ds.save(tags); return messagesList; }
public <T, V> Query<T> find( String kind, Class<T> clazz, String property, V value, int offset, int size) { Query<T> query = find(kind, clazz); query.offset(offset); query.limit(size); return query.filter(property, value); }
public List<User> findWithLimitAndOffset(int limit, int offset, String sortField) { Query<User> findQuery = ds.createQuery(User.class); if (limit > 0) { findQuery = findQuery.limit(limit); } if (offset > 0) { findQuery = findQuery.offset(offset); } if (null != sortField) { findQuery = findQuery.order(sortField); } if (null == findQuery) { return null; } List<User> users = findQuery.asList(); return (users.isEmpty()) ? null : users; }