protected List<T> makeList(EntityFilter<T> filter, DBCursor cursor) { List<T> list = new ArrayList<T>(); while (cursor.hasNext()) { T candidate = Converter.toObject(getType(), cursor.next()); if (filter == null) { list.add(candidate); } else if (filter.accepts(candidate)) { list.add(candidate); } } return list; }
public UserFacebookEntity getFacebookByEmail(String email) { UserFacebookEntity entity = null; BasicDBObject query = new BasicDBObject(); query.put("email", email); DBCursor cursor = mongoCoreService.getFacebookCollection().find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); entity = new UserFacebookEntity(); entity = Converter.toObject(UserFacebookEntity.class, document); } } finally { cursor.close(); } return entity; }
public List<UserFacebookEntity> findAll() { List<UserFacebookEntity> userList = new ArrayList<UserFacebookEntity>(); String sort = "registeredDate"; String order = "desc"; DBObject sortCriteria = new BasicDBObject(sort, "desc".equals(order) ? -1 : 1); BasicDBObject query = new BasicDBObject(); DBCursor cursor = mongoCoreService.getFacebookCollection().find(query).sort(sortCriteria); try { while (cursor.hasNext()) { DBObject document = cursor.next(); UserFacebookEntity entity = new UserFacebookEntity(); entity = Converter.toObject(UserFacebookEntity.class, document); userList.add(entity); } } finally { cursor.close(); } return userList; }