コード例 #1
0
ファイル: SiteModel.java プロジェクト: wanghl/Roller
  /**
   * Get list of WebsiteDisplay objects, ordered by number of hits.
   *
   * @param sinceDays Only consider weblogs updated in the last sinceDays
   * @param len Max number of results to return
   */
  public List getHotWeblogs(int sinceDays, int length) {

    List results = new ArrayList();
    try {
      WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
      List hotBlogs = mgr.getHotWeblogs(sinceDays, 0, length);

      Iterator hitCounts = hotBlogs.iterator();
      while (hitCounts.hasNext()) {
        WeblogHitCount hitCount = (WeblogHitCount) hitCounts.next();
        StatCount statCount =
            new StatCount(
                hitCount.getWeblog().getId(),
                hitCount.getWeblog().getHandle(),
                hitCount.getWeblog().getName(),
                "statCount.weblogDayHits",
                hitCount.getDailyHits());
        statCount.setWeblogHandle(hitCount.getWeblog().getHandle());
        results.add(statCount);
      }

    } catch (Exception e) {
      log.error("ERROR: fetching hot weblog list", e);
    }

    return results;
  }
コード例 #2
0
  /** @inheritDoc */
  public void incrementHitCount(Weblog weblog, int amount) throws WebloggerException {

    if (amount == 0) {
      throw new WebloggerException("Tag increment amount cannot be zero.");
    }

    if (weblog == null) {
      throw new WebloggerException("Website cannot be NULL.");
    }

    TypedQuery<WeblogHitCount> q =
        strategy.getNamedQuery("WeblogHitCount.getByWeblog", WeblogHitCount.class);
    q.setParameter(1, weblog);
    WeblogHitCount hitCount;
    try {
      hitCount = q.getSingleResult();
    } catch (NoResultException e) {
      hitCount = null;
    }

    // create it if it doesn't exist
    if (hitCount == null && amount > 0) {
      hitCount = new WeblogHitCount();
      hitCount.setWeblog(weblog);
      hitCount.setDailyHits(amount);
      strategy.store(hitCount);
    } else if (hitCount != null) {
      hitCount.setDailyHits(hitCount.getDailyHits() + amount);
      strategy.store(hitCount);
    }
  }
コード例 #3
0
 /** @inheritDoc */
 public void resetHitCount(Weblog weblog) throws WebloggerException {
   TypedQuery<WeblogHitCount> q =
       strategy.getNamedQuery("WeblogHitCount.getByWeblog", WeblogHitCount.class);
   q.setParameter(1, weblog);
   WeblogHitCount hitCount;
   try {
     hitCount = q.getSingleResult();
     hitCount.setDailyHits(0);
     strategy.store(hitCount);
   } catch (NoResultException e) {
     // ignore: no hit count for weblog
   }
 }