Пример #1
0
 public Integer getCount() {
   Integer listCount = 0;
   try {
     BasicDBObject query = new BasicDBObject();
     DBCursor cursor = mongoCoreService.getFacebookCollection().find(query);
     listCount = cursor.count();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return listCount;
 }
Пример #2
0
 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;
 }
Пример #3
0
  public UserFacebookEntity save(UserFacebookEntity entity, Long userId) {
    try {
      System.out.println("Save or update facebook data");
      entity.setId(
          CommonUtils.longValue(
              MongoCoreService.getNextId(mongoCoreService.getDatabase(), "fbSeqGen")));
      entity.setUserId(userId);
      entity.setRegisteredDate(new Date(System.currentTimeMillis()));
      DBObject dbObject = Converter.toDBObject(entity);
      WriteResult result =
          mongoCoreService.getFacebookCollection().save(dbObject, WriteConcern.SAFE);

    } catch (Exception e) {
      e.printStackTrace();
    }
    return entity;
  }
Пример #4
0
 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;
 }