예제 #1
0
  /**
   * すべてのユーザーリストを取得
   *
   * @return
   */
  public static List<UserModel> getAllUserList() {
    List<UserModel> userList = Memcache.get(ALL_USER_LIST);
    if (Utils.isNotEmpty(userList)) return userList;

    userList = userModelDao.getAllUserList();
    if (Utils.isNotEmpty(userList)) Memcache.put(ALL_USER_LIST, userList);

    return userList;
  }
예제 #2
0
  /**
   * グループのユーザーリストを取得
   *
   * @param groupId
   * @return
   */
  public static List<UserModel> getGroupUserList(int groupId) {

    List<UserModel> userList = Memcache.get(getGroupUserListMemcache(groupId));
    if (Utils.isNotEmpty(userList)) return userList;

    userList = userModelDao.getGroupUserList(groupId);
    if (Utils.isNotEmpty(userList)) Memcache.put(getGroupUserListMemcache(groupId), userList);

    return userList == null ? new ArrayList<UserModel>() : userList;
  }
예제 #3
0
  /**
   * ユーザーカウントの取得
   *
   * @return
   */
  public static int getUserCount() {

    int serviceUserCount =
        (Integer) (Memcache.get(SERVICE_USER_COUNT) == null ? 0 : Memcache.get(SERVICE_USER_COUNT));
    if (serviceUserCount > 0) return serviceUserCount;

    serviceUserCount = userModelDao.getUserCount();
    if (serviceUserCount > 0) Memcache.put(SERVICE_USER_COUNT, serviceUserCount);

    return serviceUserCount;
  }
예제 #4
0
  /**
   * ユーザーの取得
   *
   * @param email
   * @return
   */
  public static UserModel getOrNull(String userID) {

    Key key = createKey(userID);
    UserModel model = Memcache.get(key.toString());
    if (model != null) return model;

    model = userModelDao.getOrNull(key);
    if (model != null) Memcache.put(model.getKey().toString(), model);

    return model;
  }
예제 #5
0
  /*
   * (non-Javadoc) {@inheritDoc}
   */
  @Override
  public Navigation run() throws Exception {
    Validators v = new Validators(request);
    v.add("startWeek", v.required(), v.integerType(), v.longRange(START_WEEK_MIN, START_WEEK_MAX));
    v.add("keyword", v.maxlength(KEYWORD_MAX_LENGTH));
    if (!v.validate()) {
      response.setStatus(UNAUTHORIZED);
      Errors errors = v.getErrors();
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < errors.size(); i++) {
        sb.append(errors.get(i) + "\n");
      }
      response.setContentType("text/plain;charset=UTF-8");
      response.getWriter().write(new String(sb));
    } else {
      response.setContentType("text/calendar;charset=UTF-8");
      response.setHeader("Content-Disposition", "filename=\"" + ICALENDAR_FILE_NAME + "\"");

      Integer startWeekNum = Integer.parseInt(request.getParameter("startWeek"));
      StartWeek startWeek = StartWeek.parse(startWeekNum);
      String keyword = request.getParameter("keyword");
      String memcacheKey = "startWeek=" + startWeekNum;
      if (keyword != null) {
        memcacheKey += "&keyword=" + URLEncoder.encode(keyword, "UTF-8");
      }
      Object cache = Memcache.get(memcacheKey);
      if (cache == null) {
        CalendarCondition condition = new CalendarCondition();
        if (keyword != null) {
          // 半角スペースで区切られているキーワードは分割して配列にする。
          condition.setKeywords(Arrays.asList(keyword.split(" ")));
        }
        condition.setStartDate(startWeek.toDate());

        Calendar calendar = calendarService.getCalendar(condition);
        response.getWriter().write(calendar.toString());

        // MemcacheにiCalendarの内容をキャッシュする。
        Memcache.put(memcacheKey, calendar.toString());
      } else {
        // キャッシュがある場合はキャッシュの内容を返す。
        response.getWriter().write((String) cache);
      }
    }
    response.flushBuffer();

    return null;
  }
예제 #6
0
  /**
   * Delete
   *
   * @param model
   * @return
   */
  public static void delete(UserModel userModel) {

    // ユーザーのすべてのDateModelを取得
    List<DateModel> dateModelList = userModel.getDateModelListRef().getModelList();

    for (DateModel dateModel : dateModelList) {
      // DateModelに紐づくつべてのActivityModel を取得
      List<ActivityModel> activityModelList = dateModel.getActivityModelListRef().getModelList();

      for (ActivityModel activityModel : activityModelList) {
        // アクティビティの削除
        ActivityService.delete(userModel, activityModel);
      }

      // DateModelの削除
      DateService.delete(userModel, dateModel);
    }

    // URLリストの削除
    UserUrlsService.deleteAll(userModel);

    userModelDao.delete(userModel.getKey());

    // 自信のキャッシュをクリア
    Memcache.delete(userModel.getKey().toString());

    // ユーザーカウントのキャッシュクリア
    clearUserCountAndListMemcache();
    // グループのキャッシュをクリア
    clearGroupUserListMemcache(userModel.getGroup());
  }
예제 #7
0
  public Object[] getIndexes(UserInfo user) {
    Map<Object, Object> map = Memcache.getAll(user.getIndexes());

    if (map.size() < user.getIndexes().size()) {
      // some indexes are out of Memcache.
      List<Index> idxList = Datastore.get(i, user.getIndexes());

      for (Index idx : idxList) {
        if (!map.containsValue(idx)) {
          Memcache.put(idx.getKey(), idx); // put to Memcache
        }
      }

      return idxList.toArray();
    } else {
      return map.values().toArray();
    }
  }
예제 #8
0
  /**
   * PUT
   *
   * @param model
   * @return
   */
  public static UserModel put(UserModel model) {
    // 永久化
    userModelDao.put(model);

    // 自信のキャッシュをクリア
    Memcache.delete(model.getKey().toString());

    // グループのキャッシュをクリア
    clearGroupUserListMemcache(model.getGroup());

    return model;
  }
예제 #9
0
  /**
   * ユーザーリストを取得
   *
   * @return
   */
  public static S3QueryResultList<UserModel> getUserList(String cursor) {

    S3QueryResultList<UserModel> list = null;

    // 最初のページをキャッシュする
    if (StringUtil.isEmpty(cursor)) {
      // Memcache に存在した場合はMemcache内のmodelを返す
      list = Memcache.get(USER_LIST_FIRST_30);
      if (Utils.isNotEmpty(list)) return list;

      // DBから取得し、存在した場合はMemcacheに入れる
      list = userModelDao.getUserList(Constants.SERVICE_USER_LIST_LIMIT_NUM);
      if (Utils.isNotEmpty(list)) Memcache.put(USER_LIST_FIRST_30, list);

    } else {
      list = userModelDao.getUserList(Constants.SERVICE_USER_LIST_LIMIT_NUM, cursor);
    }

    return list == null
        ? new S3QueryResultList<UserModel>(new ArrayList<UserModel>(), null, null, null, false)
        : list;
  }
예제 #10
0
 /** グループユーザーリストのキャッシュをクリア */
 public static void clearGroupUserListMemcache(int groupId) {
   Memcache.delete(getGroupUserListMemcache(groupId));
 }
예제 #11
0
 /** ユーザー数のキャッシュをクリア */
 public static void clearUserCountAndListMemcache() {
   Memcache.delete(SERVICE_USER_COUNT);
   Memcache.delete(ALL_USER_LIST);
   //        Memcache.delete(EXAMPLE_USER_LIST);
 }