コード例 #1
0
  public List getWeblogEntries(WeblogCategoryData cat, boolean subcats) throws RollerException {
    try {
      Session session = ((HibernatePersistenceStrategy) this.strategy).getSession();
      List entries = new LinkedList();

      if (subcats) {
        // Get entries in subcategories
        Criteria assocsQuery = session.createCriteria(WeblogCategoryAssoc.class);
        assocsQuery.add(Expression.eq("ancestorCategory", cat));
        Iterator assocs = assocsQuery.list().iterator();
        while (assocs.hasNext()) {
          WeblogCategoryAssoc assoc = (WeblogCategoryAssoc) assocs.next();
          Criteria entriesQuery = session.createCriteria(WeblogEntryData.class);
          entriesQuery.add(Expression.eq("category", assoc.getCategory()));
          Iterator entryIter = entriesQuery.list().iterator();
          while (entryIter.hasNext()) {
            WeblogEntryData entry = (WeblogEntryData) entryIter.next();
            entries.add(entry);
          }
        }
      }

      // Get entries in category
      Criteria entriesQuery = session.createCriteria(WeblogEntryData.class);
      entriesQuery.add(Expression.eq("category", cat));
      Iterator entryIter = entriesQuery.list().iterator();
      while (entryIter.hasNext()) {
        WeblogEntryData entry = (WeblogEntryData) entryIter.next();
        entries.add(entry);
      }
      return entries;
    } catch (HibernateException e) {
      throw new RollerException(e);
    }
  }
コード例 #2
0
  public List getWeblogCategories(WebsiteData website, boolean includeRoot) throws RollerException {
    if (website == null) throw new RollerException("website is null");

    if (includeRoot) return getWeblogCategories(website);

    try {
      Session session = ((HibernatePersistenceStrategy) this.strategy).getSession();
      Criteria criteria = session.createCriteria(WeblogCategoryAssoc.class);
      criteria.createAlias("category", "c");
      criteria.add(Expression.eq("c.website", website));
      criteria.add(Expression.isNotNull("ancestorCategory"));
      criteria.add(Expression.eq("relation", "PARENT"));
      Iterator assocs = criteria.list().iterator();
      List cats = new ArrayList();
      while (assocs.hasNext()) {
        WeblogCategoryAssoc assoc = (WeblogCategoryAssoc) assocs.next();
        cats.add(assoc.getCategory());
      }
      return cats;
    } catch (HibernateException e) {
      throw new RollerException(e);
    }
  }