Elias Torres wrote:
Allen,

Locale was using a starts-with case-insensitive search. I'm not really
sure if this is even needed. Don't all locales match cc-CC anyways? We
were using an IlikeExpression. I simply did a direct conversion of what
their code does. ILIKE is actually not SQL99 or any other SQL standard.
As a matter of fact it seems that only PostgreSQL supports it. If you
look at the source of ILikeExpression:

#################################
Dialect dialect = criteriaQuery.getFactory().getDialect();
String[] columns = criteriaQuery.getColumnsUsingProjection(criteria,
propertyName);
if (columns.length!=1) throw new HibernateException("...");
if ( dialect instanceof PostgreSQLDialect ) {
        return columns[0] + " ilike ?";
}
else {
return dialect.getLowercaseFunction() + '(' + columns[0] + ") like ?";
}
//TODO: get SQL rendering out of this package!
}
#################################

I'm simply using the published HQL spec functions [1] but obviously
Hibernate is not perfect. Anyways to make a story short, if we don't
need "starts-with case-insensitive search", we can fix this problem
really easily if you tell me what exactly was meant in that query.

I don't know what all of that "ilike" stuff means, maybe Hibernate wasn't doing the right thing on all databases, but nobody reported it as a bug so as far as I'm concerned it was working properly. I am working off of MySQL and it was working properly, so obviously postgres isn't the only supported sql for that function.

There isn't any explicit reason why it has to be a case insensitive search, I had merely done it that way because there didn't seem to be a reason not to. If you really think it can't be case insensitive then do it another way, but it seemed to be working before so I don't see why it can't continue working.



I did note that I have a bug. starts-with should put the '%' at the end
and not at the start. :(

if (locale != null) {
  queryString.append("lower(locale) like ? ");
  params.add("%" + locale.toLowerCase());
}

Anyways, I really looked into executing that query using CriteriaAPI
(even went to #hibernate on freenode IRC), read tons of posts and none
of them gave me any answers/hope. I don't think this should be a major
problems since everything is pretty standard in the query except for the
lower, which is obviously causing some problems.

Let me know what you think and if this help at all with you unease in me
using HQL. Again, it's not that I want it, but I don't think we have a
choice unless I separate my query into separate method as I had initially.

I don't have any real preference either way, I only care that it works.

If you want your query to be a separate method then that's fine, we should just discuss that on the list a little bit and make sure that it's a decision made on purpose and that we understand the ramifications.

-- Allen



-Elias

[1] http://www.hibernate.org/hib_docs/v3/reference/en/html/queryhql.html

Allen Gilliland wrote:
Another thing that I just noticed is that I am getting an exception now
when I try using a weblog url that specifies a locale ...

ERROR 2006-09-28 12:13:50,017 ErrorCounter:reportError - line 1:119:
unexpected token: lower
ERROR 2006-09-28 12:13:50,019 WeblogEntriesLatestPager:getEntries -
ERROR: getting entry month map
java.lang.reflect.UndeclaredThrowableException
        at $Proxy0.createQuery(Unknown Source)
        at
org.apache.roller.business.hibernate.HibernateWeblogManagerImpl.getWeblogEntries(HibernateWeblogManagerImpl.java:479)

        at
org.apache.roller.business.hibernate.HibernateWeblogManagerImpl.getWeblogEntryMap(HibernateWeblogManagerImpl.java:1039)

        at
org.apache.roller.business.hibernate.HibernateWeblogManagerImpl.getWeblogEntryObjectMap(HibernateWeblogManagerImpl.java:986)

        at
org.apache.roller.ui.rendering.pagers.WeblogEntriesLatestPager.getEntries(WeblogEntriesLatestPager.java:78)

        at
org.apache.roller.ui.rendering.pagers.WeblogEntriesLatestPager.<init>(WeblogEntriesLatestPager.java:67)

        at
org.apache.roller.ui.rendering.model.PageModel.getWeblogEntriesPager(PageModel.java:225)

        at
org.apache.roller.ui.rendering.model.PageModel.getWeblogEntriesPager(PageModel.java:244)



In general I am getting a little bit uneasy about how we've gone from
using the Criteria api to the HQL query for that method.  This is twice
now that I've caught problems with the way HQL was used.  Was there
really no way to continue using the old Criteria api way?

-- Allen



Allen Gilliland wrote:
Elias, there are a number of things in this commit that seem a little
strange to me ...

1. why do we need 3 separate tables for the tag aggregate data?

2. why do we need a SummariesTask to run asynchronously?  i thought
the aggregate data was going to be compiled at the time the tags were
saved with the entry?

3. why do we need to move things into a separate TagManager class?

Also, I am noticing that the formatting of your code is not always
consistent.  For example, in the WeblogTagAggregateData class you are
mixing code formatting styles.  Maybe that's just a copy/paste issue,
but I think it's important that as we add new code we keep the
formatting consistent.

-- Allen


[EMAIL PROTECTED] wrote:
Author: eliast
Date: Wed Sep 27 21:38:07 2006
New Revision: 450690

URL: http://svn.apache.org/viewvc?view=rev&rev=450690
Log:
Added code to summarize tag table into aggregate tables for better
performance

- Added a new TagManager and dependencies
- Added two new beans: SiteTagAggregateData and WeblogTagAggregateData
- Added a new task: TagSummariesTask
- Moved method from WeblogManager to TagManager (getTags())
- Modified createdb.vm to include the two new tables

Added:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java (with props) incubator/roller/trunk/src/org/apache/roller/model/TagManager.java (with props) incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java (with props) incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java (with props) incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java (with props)
Modified:
    incubator/roller/trunk/metadata/database/createdb.vm
    incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java

incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java

    incubator/roller/trunk/src/org/apache/roller/model/Roller.java
incubator/roller/trunk/src/org/apache/roller/model/WeblogManager.java incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java

    incubator/roller/trunk/testdata/WEB-INF/classes/hibernate.cfg.xml
    incubator/roller/trunk/web/WEB-INF/classes/roller.properties

Modified: incubator/roller/trunk/metadata/database/createdb.vm
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/metadata/database/createdb.vm?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

--- incubator/roller/trunk/metadata/database/createdb.vm (original)
+++ incubator/roller/trunk/metadata/database/createdb.vm Wed Sep 27
21:38:07 2006
@@ -222,15 +222,34 @@
 create index wet_userid_idx on weblogentrytag( userid );
 create index wet_name_idx on weblogentrytag( name );
-create table weblogentrytagagg (
+create table weblogtagagg (
     id              varchar(48)   not null primary key,
websiteid varchar(48) not null, name varchar(255) not null,
     count           integer          not null
 );
-create index weta_websiteid_idx on weblogentrytagagg( websiteid );
-create index weta_name_idx on weblogentrytagagg( name );
+create index weta_websiteid_idx on weblogtagagg( websiteid );
+create index weta_name_idx on weblogtagagg( name );
+
+create table usertagagg (
+    id              varchar(48)   not null primary key,
+ userid varchar(48) not null, + name varchar(255) not null,
+    count           integer          not null
+);
+
+create index userta_userid_idx on usertagagg( userid );
+create index userta_name_idx on usertagagg( name );
+
+create table sitetagagg (
+    id              varchar(48)   not null primary key,
+    name            varchar(255)  not null,
+    count           integer          not null
+);
+
+create index siteta_name_idx on sitetagagg( name );
+
create table newsfeed (
     id              varchar(48) not null primary key,

Modified:
incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

---
incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
(original)
+++
incubator/roller/trunk/metadata/database/hibernate/hibernate.cfg.xml
Wed Sep 27 21:38:07 2006
@@ -94,7 +94,9 @@
         <mapping
resource="org/apache/roller/pojos/RefererData.hbm.xml" />
<mapping
resource="org/apache/roller/pojos/WeblogEntryData.hbm.xml" />
-        <mapping
resource="org/apache/roller/pojos/WeblogEntryTagData.hbm.xml"
/>        +        <mapping
resource="org/apache/roller/pojos/WeblogEntryTagData.hbm.xml"
/>        +        <mapping
resource="org/apache/roller/pojos/WeblogTagAggregateData.hbm.xml"
/>    +        <mapping
resource="org/apache/roller/pojos/SiteTagAggregateData.hbm.xml"
/>                             <mapping
resource="org/apache/roller/pojos/EntryAttributeData.hbm.xml" />
         <mapping
resource="org/apache/roller/pojos/WeblogCategoryData.hbm.xml" />
         <mapping
resource="org/apache/roller/pojos/WeblogCategoryAssoc.hbm.xml" />

Modified:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java

URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
(original)
+++
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateRollerImpl.java
Wed Sep 27 21:38:07 2006
@@ -29,6 +29,7 @@
 import org.apache.roller.model.AutoPingManager;
 import org.apache.roller.model.PingQueueManager;
 import org.apache.roller.model.PingTargetManager;
+import org.apache.roller.model.TagManager;
 import org.apache.roller.planet.model.PlanetManager;
 import org.apache.roller.model.PropertiesManager;
 import org.apache.roller.model.RefererManager;
@@ -63,6 +64,7 @@
     private PingQueueManager pingQueueManager = null;
     private AutoPingManager autoPingManager = null;
     private PingTargetManager pingTargetManager = null;
+    private TagManager tagManager = null;
               protected HibernateRollerImpl() throws RollerException {
@@ -225,5 +227,15 @@
         }
         return pingTargetManager;
     }
+    +    /**
+     * @see org.apache.roller.model.Roller#getTagManager()
+     */
+    public TagManager getTagManager() throws RollerException {
+        if (tagManager == null) {
+            tagManager = new HibernateTagManagerImpl(strategy);
+        }
+        return tagManager;
+    }          }

Added:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java

URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java?view=auto&rev=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java
(added)
+++
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java
Wed Sep 27 21:38:07 2006
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.business.hibernate;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.TagManager;
+import org.apache.roller.pojos.SiteTagAggregateData;
+import org.apache.roller.pojos.TagCloudEntry;
+import org.apache.roller.pojos.UserData;
+import org.apache.roller.pojos.WeblogTagAggregateData;
+import org.apache.roller.pojos.WebsiteData;
+import org.apache.roller.util.DateUtil;
+import org.hibernate.HibernateException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.criterion.Expression;
+
+
+/**
+ * Hibernate implementation of the TagManager.
+ * @author Elias Torres (<a
href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>)
+ *
+ */
+public class HibernateTagManagerImpl implements TagManager {
+    +    private static final long serialVersionUID =
-6573148804064466850L;
+
+    private static Log log =
LogFactory.getLog(HibernateTagManagerImpl.class);
+    +    private HibernatePersistenceStrategy strategy = null;
+        +    public
HibernateTagManagerImpl(HibernatePersistenceStrategy strat) {
+        log.debug("Instantiating Hibernate Tag Manager");
+        +        this.strategy = strat;
+    }
+
+    public List getTags(Date startDate,
+        Date endDate,
+        WebsiteData website,
+        UserData user,
+        boolean sortByCount,
+        int limit) throws RollerException {
+      try {
+        List results = new ArrayList();
+        +        Session session = ((HibernatePersistenceStrategy)
strategy).getSession();
+        +        StringBuffer queryString = new StringBuffer();
+        queryString.append("select t.name, count(t.name) ");
+        queryString.append("from WeblogEntryTagData t ");
+        queryString.append("where t.time between ? and ? ");
+        if(website != null)
+          queryString.append("and t.website.id = '" +
website.getId() + "' ");
+        if(user != null)
+          queryString.append("and t.user.id = '" + user.getId() + "'
");
+        queryString.append("group by t.name ");
+        queryString.append(sortByCount ? "order by col_1_0_ desc " :
"order by t.name ");
+
+        Query query = session.createQuery(queryString.toString());
+        query.setTimestamp(0, DateUtil.getStartOfDay(startDate));
+        query.setTimestamp(1, DateUtil.getEndOfDay(endDate));
+        if(limit > 0)
+          query.setMaxResults(limit);
+        +        for (Iterator iter = query.list().iterator();
iter.hasNext();) {
+          Object[] row = (Object[]) iter.next();
+          TagCloudEntry ce = new TagCloudEntry();
+          ce.setName((String) row[0]);
+          ce.setCount(((Integer)row[1]).intValue());
+          results.add(ce);
+        }
+        +        return results;
+        +      } catch (HibernateException e) {
+        throw new RollerException(e);
+      }
+
+    }
+
+    public void release() {
+      // TODO Auto-generated method stub
+      +    }
+
+    public Date summarize(Date startDate) throws RollerException {
+      +      Session session = ((HibernatePersistenceStrategy)
strategy).getSession();
+      +      // This queries the db for the last time we'll include
in our batch processing
+      Query query = session.createQuery("select time from
WeblogEntryTagData group by time order by time desc");
+      query.setMaxResults(1);
+      +      Timestamp thisRun = (Timestamp) query.uniqueResult();
+      +      if(thisRun == null || thisRun.compareTo(startDate) == 0)
+      {
+        // nothing to do
+        log.debug("TagManager.summarize() found nothing to do.");
+        return null;
+      }
+                        +      // #### SiteTagAgg ####
+      +      List params = new ArrayList(2);
+      StringBuffer queryString = new StringBuffer();
+      queryString.append("select name, count(name) from
WeblogEntryTagData where ");
+      if(startDate != null) {
+        queryString.append("time > ? and ");
+        params.add(startDate);
+      }
+      queryString.append("time <= ? group by name");
+      params.add(thisRun);
+      +      query =  session.createQuery(queryString.toString());
+      for(int i = 0; i < params.size(); i++)
+        query.setParameter(i, params.get(i));
+      +      List results = query.list();
+      log.debug("TagManager.summarize() found " + results.size() + "
tags to summarize.");
+      +      for(Iterator it = results.iterator(); it.hasNext(); )
+      {
+        Object[] row = (Object[]) it.next();
+        String tagName = (String) row[0];
+        int tagCount = ((Integer)row[1]).intValue();
+        +        SiteTagAggregateData siteData =
(SiteTagAggregateData)
session.createCriteria(SiteTagAggregateData.class).add(Expression.eq("name",
tagName)).uniqueResult();
+        if(siteData == null) +            siteData = new
SiteTagAggregateData(null, tagName, tagCount);
+        else
+            siteData.setCount(siteData.getCount()+tagCount);
+        +        strategy.store(siteData);
+      } +
+      // #### WeblogTagAgg ####
+      +      params = new ArrayList(2);
+      queryString = new StringBuffer();
+      queryString.append("select t.website, t.name, count(t.name)
from WeblogEntryTagData t where ");
+      if(startDate != null) {
+        queryString.append("t.time > ? and ");
+        params.add(startDate);
+      }
+      queryString.append("t.time <= ? group by t.website, t.name");
+      params.add(thisRun);
+      +      query =  session.createQuery(queryString.toString());
+      for(int i = 0; i < params.size(); i++)
+        query.setParameter(i, params.get(i));
+      +      results = query.list();
+      log.debug("TagManager.summarize() found " + results.size() + "
tags/website to summarize.");
+                +      for(Iterator it = results.iterator();
it.hasNext(); )
+      {
+        Object[] row = (Object[]) it.next();
+        WebsiteData website = (WebsiteData) row[0];
+        String tagName = (String) row[1];
+        int tagCount = ((Integer)row[2]).intValue();
+        +        WeblogTagAggregateData weblogData =
(WeblogTagAggregateData) session
+          .createCriteria(WeblogTagAggregateData.class)
+          .add(Expression.eq("name", tagName))
+          .add(Expression.eq("website", website))
+          .uniqueResult();
+        if(weblogData == null) +          weblogData = new
WeblogTagAggregateData(null, website, tagName, tagCount);
+        else
+          weblogData.setCount(weblogData.getCount()+tagCount);
+        +        strategy.store(weblogData);
+      } +        +      session.flush(); +
+      return thisRun;
+    }
+}

Propchange:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java

------------------------------------------------------------------------------

    svn:eol-style = native

Propchange:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java

------------------------------------------------------------------------------

    svn:keywords = Date Author Id Revision HeadURL

Propchange:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateTagManagerImpl.java

------------------------------------------------------------------------------

    svn:mime-type = text/plain

Modified:
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java

URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
(original)
+++
incubator/roller/trunk/src/org/apache/roller/business/hibernate/HibernateWeblogManagerImpl.java
Wed Sep 27 21:38:07 2006
@@ -814,51 +814,7 @@
             throw new RollerException(e);
         }
     }
-            -    public List getTags(Date startDate,
-        Date endDate,
-        WebsiteData website,
-        UserData user,
-        boolean sortByCount,
-        int limit) throws RollerException {
-      try {
-        List results = new ArrayList();
-        -        Session session = ((HibernatePersistenceStrategy)
strategy).getSession();
-        -        StringBuffer queryString = new StringBuffer();
-        queryString.append("select t.name, count(t.name) ");
-        queryString.append("from WeblogEntryTagData t ");
-        queryString.append("where t.time between ? and ? ");
-        if(website != null)
-          queryString.append("and t.website.id = '" +
website.getId() + "' ");
-        if(user != null)
-          queryString.append("and t.user.id = '" + user.getId() + "'
");
-        queryString.append("group by t.name ");
-        queryString.append(sortByCount ? "order by col_1_0_ desc " :
"order by t.name ");
-
-        Query query = session.createQuery(queryString.toString());
-        query.setTimestamp(0, DateUtil.getStartOfDay(startDate));
-        query.setTimestamp(1, DateUtil.getEndOfDay(endDate));
-        if(limit > 0)
-          query.setMaxResults(limit);
-        -        for (Iterator iter = query.list().iterator();
iter.hasNext();) {
-          Object[] row = (Object[]) iter.next();
-          TagCloudEntry ce = new TagCloudEntry();
-          ce.setName((String) row[0]);
-          ce.setCount(((Integer)row[1]).intValue());
-          results.add(ce);
-        }
-        -        return results;
-        -      } catch (HibernateException e) {
-        throw new RollerException(e);
-      }
-
-    }
-    +                     public List getComments(
             WebsiteData     website,
             WeblogEntryData entry,

Modified: incubator/roller/trunk/src/org/apache/roller/model/Roller.java
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/model/Roller.java?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

--- incubator/roller/trunk/src/org/apache/roller/model/Roller.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/model/Roller.java
Wed Sep 27 21:38:07 2006
@@ -128,6 +128,13 @@
               /**
+     * Get TagManager associated with this Roller instance.
+     */
+    public TagManager getTagManager() throws RollerException;
+        +    +    +    /**
      * Flush object states.
      */
     public void flush() throws RollerException;

Added:
incubator/roller/trunk/src/org/apache/roller/model/TagManager.java
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/model/TagManager.java?view=auto&rev=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/model/TagManager.java
(added)
+++
incubator/roller/trunk/src/org/apache/roller/model/TagManager.java
Wed Sep 27 21:38:07 2006
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.model;
+
+import java.util.Date;
+import java.util.List;
+
+import org.apache.roller.RollerException;
+import org.apache.roller.pojos.UserData;
+import org.apache.roller.pojos.WebsiteData;
+
+/**
+ * @author Elias Torres (<a
href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>)
+ *
+ */
+public interface TagManager {
+            +    /**
+     * Get all tag (name, count) pairs for a specific date range,
optionally only for a given site or user.
+     * @param startDate
+     * @param endDate
+     * @param website
+     * @param user
+     * @param sortByCount
+     * @param limit
+     * @return
+     * @throws RollerException
+     */
+    public List getTags(Date startDate,
+        Date endDate,
+        WebsiteData website,
+        UserData user,
+        boolean sortByCount,
+        int limit) throws RollerException;
+        +    +    public Date summarize(Date startDate) throws
RollerException;
+    +    /**
+     * Release all resources held by manager.
+     */
+    public void release();    +}

Propchange:
incubator/roller/trunk/src/org/apache/roller/model/TagManager.java
------------------------------------------------------------------------------

    svn:eol-style = native

Propchange:
incubator/roller/trunk/src/org/apache/roller/model/TagManager.java
------------------------------------------------------------------------------

    svn:keywords = Date Author Id Revision HeadURL

Propchange:
incubator/roller/trunk/src/org/apache/roller/model/TagManager.java
------------------------------------------------------------------------------

    svn:mime-type = text/plain

Modified:
incubator/roller/trunk/src/org/apache/roller/model/WeblogManager.java
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/model/WeblogManager.java?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/model/WeblogManager.java
(original)
+++
incubator/roller/trunk/src/org/apache/roller/model/WeblogManager.java
Wed Sep 27 21:38:07 2006
@@ -304,25 +304,7 @@
      * Get all ancestor associates for a category.
      */
     public List getWeblogCategoryAncestorAssocs(WeblogCategoryData
data) throws RollerException;
-        -    /**
-     * Get all tag (name, count) pairs for a specific date range,
optionally only for a given site or user.
-     * @param startDate
-     * @param endDate
-     * @param website
-     * @param user
-     * @param sortByCount
-     * @param limit
-     * @return
-     * @throws RollerException
-     */
-    public List getTags(Date startDate,
-        Date endDate,
-        WebsiteData website,
-        UserData user,
-        boolean sortByCount,
-        int limit) throws RollerException;
-        +                    /**
      * Save comment.
      */

Added:
incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java

URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java?view=auto&rev=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java
(added)
+++
incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java
Wed Sep 27 21:38:07 2006
@@ -0,0 +1,153 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+*  contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Generated file - Do not edit!
+ */
+package org.apache.roller.pojos;
+
+import org.apache.roller.util.PojoUtil;
+
+
+/**
+ * @author Elias Torres
+ *
+ * @ejb:bean name="SiteTagAggregateData"
+ * @struts.form include-all="true"
+ * @hibernate.class lazy="false" table="sitetagagg"
+ * @hibernate.cache usage="read-write"
+ */
+public class SiteTagAggregateData extends PersistentObject
+    implements java.io.Serializable
+{
+    private static final long serialVersionUID = -7766410727897537118L;
+    private java.lang.String id = null;
+    private java.lang.String name = null;    +    private int count
= 0;
+
+    public SiteTagAggregateData()
+    {
+    }
+
+    public SiteTagAggregateData(java.lang.String id,
+                       java.lang.String name, int count)
+    {
+        this.id = id;
+        this.name = name;
+        this.count = count;
+    }
+
+    public SiteTagAggregateData(SiteTagAggregateData otherData)
+    {
+        setData(otherData);
+    }
+
+    //------------------------------------------------------- Simple
properties
+
+    /** +     * Unique ID and primary key of this Referer.
+     *
+     * @hibernate.id column="id" generator-class="uuid.hex"
unsaved-value="null"
+     */
+    public java.lang.String getId()
+    {
+        return this.id;
+    }
+
+    public void setId(java.lang.String id)
+    {
+        this.id = id;
+    }
+
+    /**
+     * Tag value
+     *
+     * @roller.wrapPojoMethod type="simple"
+     * @ejb:persistent-field
+     * @hibernate.property column="name" non-null="true" unique="false"
+     */
+    public String getName() {
+        return this.name;
+    }
+    /** @ejb:persistent-field */
+    public void setName( String name ) {
+        this.name = name;
+    }   +    +    /**
+    *
+    * @roller.wrapPojoMethod type="simple"
+    * @ejb:persistent-field
+    * @hibernate.property column="count" non-null="true" unique="false"
+    */
+   public int getCount()
+   {
+       return this.count;
+   }
+
+   /** @ejb:persistent-field */
+   public void setCount(int count)
+   {
+       this.count = count;
+   }    +
+   public String toString() {
+     StringBuffer str = new StringBuffer("{");
+     +     str.append("id=" + id + " " +
+             "name=" + name + " " +
+             "count=" + count);
+     str.append('}');
+     +     return (str.toString());
+ }
+ +   public boolean equals(Object pOther) {
+       if (pOther instanceof SiteTagAggregateData) {
+           SiteTagAggregateData lTest = (SiteTagAggregateData) pOther;
+           boolean lEquals = true;
+           +           lEquals = PojoUtil.equals(lEquals, this.id,
lTest.getId());
+           lEquals = PojoUtil.equals(lEquals, this.name,
lTest.getName());
+           lEquals = this.count == lTest.getCount();
+           return lEquals;
+       } else {
+           return false;
+       }
+   }
+ +   public int hashCode() {
+       int result = 17;
+       result = PojoUtil.addHashCode(result, this.id);
+       result = PojoUtil.addHashCode(result, this.name);
+       result = PojoUtil.addHashCode(result, new Integer(this.count));
+       +       return result;
+   }
+ +    /**
+     * Setter is needed in RollerImpl.storePersistentObject()
+     */
+    public void setData(org.apache.roller.pojos.PersistentObject
otherData)
+    {
+        SiteTagAggregateData data = (SiteTagAggregateData) otherData;
+        this.id = data.getId();
+        this.name = data.getName();
+        this.count = data.getCount();
+    }
+
+}
\ No newline at end of file

Propchange:
incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java

------------------------------------------------------------------------------

    svn:eol-style = native

Propchange:
incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java

------------------------------------------------------------------------------

    svn:keywords = Date Author Id Revision HeadURL

Propchange:
incubator/roller/trunk/src/org/apache/roller/pojos/SiteTagAggregateData.java

------------------------------------------------------------------------------

    svn:mime-type = text/plain

Added:
incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java

URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java?view=auto&rev=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java
(added)
+++
incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java
Wed Sep 27 21:38:07 2006
@@ -0,0 +1,174 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+*  contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Generated file - Do not edit!
+ */
+package org.apache.roller.pojos;
+
+import org.apache.roller.util.PojoUtil;
+
+
+/**
+ * @author Elias Torres
+ *
+ * @ejb:bean name="WeblogTagAggregateData"
+ * @struts.form include-all="true"
+ * @hibernate.class lazy="false" table="weblogtagagg"
+ * @hibernate.cache usage="read-write"
+ */
+public class WeblogTagAggregateData extends PersistentObject
+    implements java.io.Serializable
+{
+    private static final long serialVersionUID = -4343500268898106982L;
+    private java.lang.String id = null;
+    private java.lang.String name = null;    +    private
WebsiteData website = null;
+    private int count = 0;
+
+    public WeblogTagAggregateData()
+    {
+    }
+
+    public WeblogTagAggregateData(java.lang.String id,
+                       WebsiteData website,
+                       java.lang.String name, int count)
+    {
+        this.id = id;
+        this.website = website;
+        this.name = name;
+        this.count = count;
+    }
+
+    public WeblogTagAggregateData(WeblogTagAggregateData otherData)
+    {
+        setData(otherData);
+    }
+
+    //------------------------------------------------------- Simple
properties
+
+    /** +     * Unique ID and primary key of this Referer.
+     *
+     * @hibernate.id column="id" generator-class="uuid.hex"
unsaved-value="null"
+     */
+    public java.lang.String getId()
+    {
+        return this.id;
+    }
+
+    public void setId(java.lang.String id)
+    {
+        this.id = id;
+    }
+    +    /**
+     * @roller.wrapPojoMethod type="pojo"
+     * @ejb:persistent-field
+     * @hibernate.many-to-one column="websiteid" cascade="none"
not-null="true"
+     */
+    public WebsiteData getWebsite() {
+        return this.website;
+    }
+    +    /** @ejb:persistent-field */
+    public void setWebsite(WebsiteData website) {
+        this.website = website;
+    }    +
+    /**
+     * Tag value
+     *
+     * @roller.wrapPojoMethod type="simple"
+     * @ejb:persistent-field
+     * @hibernate.property column="name" non-null="true" unique="false"
+     */
+    public String getName() {
+        return this.name;
+    }
+    /** @ejb:persistent-field */
+    public void setName( String name ) {
+        this.name = name;
+    }   +    +    /**
+    *
+    * @roller.wrapPojoMethod type="simple"
+    * @ejb:persistent-field
+    * @hibernate.property column="count" non-null="true" unique="false"
+    */
+   public int getCount()
+   {
+       return this.count;
+   }
+
+   /** @ejb:persistent-field */
+   public void setCount(int count)
+   {
+       this.count = count;
+   }    +
+   public String toString() {
+     StringBuffer str = new StringBuffer("{");
+     +     str.append("id=" + id + " " +
+             "websiteid=" + website.getId() +
+             "name=" + name + " " +
+             "count=" + count);
+     str.append('}');
+     +     return (str.toString());
+ }
+ +   public boolean equals(Object pOther) {
+       if (pOther instanceof WeblogTagAggregateData) {
+           WeblogTagAggregateData lTest = (WeblogTagAggregateData)
pOther;
+           boolean lEquals = true;
+           +           lEquals = PojoUtil.equals(lEquals, this.id,
lTest.getId());
+           lEquals = PojoUtil.equals(lEquals, this.website,
lTest.getWebsite());
+           lEquals = PojoUtil.equals(lEquals, this.name,
lTest.getName());
+           lEquals = this.count == lTest.getCount();
+           return lEquals;
+       } else {
+           return false;
+       }
+   }
+ +   public int hashCode() {
+       int result = 17;
+       result = PojoUtil.addHashCode(result, this.id);
+       result = PojoUtil.addHashCode(result, this.website);
+       result = PojoUtil.addHashCode(result, this.name);
+       result = PojoUtil.addHashCode(result, new Integer(this.count));
+       +       return result;
+   }
+ +    /**
+     * Setter is needed in RollerImpl.storePersistentObject()
+     */
+    public void setData(org.apache.roller.pojos.PersistentObject
otherData)
+    {
+        WeblogTagAggregateData data = (WeblogTagAggregateData)
otherData;
+        this.id = data.getId();
+        this.website = data.getWebsite();
+        this.name = data.getName();
+        this.count = data.getCount();
+    }
+
+}
\ No newline at end of file

Propchange:
incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java

------------------------------------------------------------------------------

    svn:eol-style = native

Propchange:
incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java

------------------------------------------------------------------------------

    svn:keywords = Date Author Id Revision HeadURL

Propchange:
incubator/roller/trunk/src/org/apache/roller/pojos/WeblogTagAggregateData.java

------------------------------------------------------------------------------

    svn:mime-type = text/plain

Added:
incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java

URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java?view=auto&rev=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java
(added)
+++
incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java
Wed Sep 27 21:38:07 2006
@@ -0,0 +1,123 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+*  contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+/*
+ * Created on Mar 10, 2004
+ */
+package org.apache.roller.ui.core.tasks;
+
+import java.text.ParseException;
+import java.util.Date;
+import java.util.TimerTask;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.RollerException;
+import org.apache.roller.model.Roller;
+import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.ScheduledTask;
+import org.apache.roller.pojos.RollerPropertyData;
+import org.apache.roller.util.DateUtil;
+
+/**
+ * Maintains tag summary information for faster response to tag UI
in Roller weblogs.
+ * + * @author Elias Torres (<a
href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a>)
+ *
+ */
+public class TagSummariesTask extends TimerTask implements
ScheduledTask {
+    +    private static Log log =
LogFactory.getLog(TagSummariesTask.class);
+    +    private static final String LAST_RUN = "tag.summary.lastRun";
+    +    /**
+     * Task init.
+     */
+    public void init(Roller roller, String realPath) throws
RollerException {
+        log.debug("initing");
+    }
+    +    +    /**
+     * Excecute the task.
+     */
+    public void run() {
+        +        log.info("task started");
+        +        try {
+            Roller roller = RollerFactory.getRoller();
+            +            // find the last time we ran
+            RollerPropertyData property =
roller.getPropertiesManager().getProperty(LAST_RUN);
+            +            Date lastRun = null;
+            +            if (property == null)
+            {
+              // the first time we need to create a new property object
+              property = new RollerPropertyData();
+              property.setName(LAST_RUN);
+            }
+            else
+            {
+              // else, let's get last time we ran.
+              try {
+                lastRun = DateUtil.parse(property.getValue(),
DateUtil.defaultTimestampFormat());
+              } catch (ParseException e) {
+                e.printStackTrace();
+              }      +            }
+            +            Date summarized =
roller.getTagManager().summarize(lastRun);
+            +            if(summarized != null) {
+              property.setValue(DateUtil.defaultTimestamp(summarized));
+              roller.getPropertiesManager().saveProperty(property);
+              roller.flush();
+            }
+                        +            roller.release();
+            log.info("task completed");   +            +        }
catch (RollerException e) {
+            log.error("Error while summarizing tag table.", e);
+        } catch (Exception ee) {
+            log.error("unexpected exception", ee);
+        }
+        +        log.info("task completed");
+    }
+    +    +    /**
+     * Main method so that this task may be run from outside the
webapp.
+     */
+    public static void main(String[] args) throws Exception {
+        try {            +            TagSummariesTask task = new
TagSummariesTask();
+            task.init(null, null);
+            task.run();
+            System.exit(0);
+        } catch (RollerException ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        }
+    }
+    +}

Propchange:
incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java

------------------------------------------------------------------------------

    svn:eol-style = native

Propchange:
incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java

------------------------------------------------------------------------------

    svn:keywords = Date Author Id Revision HeadURL

Propchange:
incubator/roller/trunk/src/org/apache/roller/ui/core/tasks/TagSummariesTask.java

------------------------------------------------------------------------------

    svn:mime-type = text/plain

Modified:
incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java

URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

---
incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java
(original)
+++
incubator/roller/trunk/src/org/apache/roller/ui/rendering/model/SiteModel.java
Wed Sep 27 21:38:07 2006
@@ -33,6 +33,7 @@
 import org.apache.roller.model.RefererManager;
 import org.apache.roller.model.Roller;
 import org.apache.roller.model.RollerFactory;
+import org.apache.roller.model.TagManager;
 import org.apache.roller.model.UserManager;
 import org.apache.roller.model.WeblogManager;
 import org.apache.roller.pojos.PermissionsData;
@@ -491,8 +492,8 @@
         Date startDate = cal.getTime();
         try {                         Roller roller =
RollerFactory.getRoller();
-            WeblogManager wmgr = roller.getWeblogManager();
-            results = wmgr.getTags(
+            TagManager tmgr = roller.getTagManager();
+            results = tmgr.getTags(
                     startDate, new Date(), null, null, false, -1);
         } catch (Exception e) {
             log.error("ERROR: fetching site tags list", e);
@@ -513,8 +514,8 @@
         Date startDate = cal.getTime();
         try {                         Roller roller =
RollerFactory.getRoller();
-            WeblogManager wmgr = roller.getWeblogManager();
-            results = wmgr.getTags(
+            TagManager tmgr = roller.getTagManager();
+            results = tmgr.getTags(
                     startDate, new Date(), null, null, true, length);
         } catch (Exception e) {
             log.error("ERROR: fetching site tags list", e);

Modified:
incubator/roller/trunk/testdata/WEB-INF/classes/hibernate.cfg.xml
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/testdata/WEB-INF/classes/hibernate.cfg.xml?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

--- incubator/roller/trunk/testdata/WEB-INF/classes/hibernate.cfg.xml
(original)
+++ incubator/roller/trunk/testdata/WEB-INF/classes/hibernate.cfg.xml
Wed Sep 27 21:38:07 2006
@@ -65,7 +65,9 @@
         <mapping
resource="org/apache/roller/pojos/RefererData.hbm.xml" />
<mapping
resource="org/apache/roller/pojos/WeblogEntryData.hbm.xml" />
-        <mapping
resource="org/apache/roller/pojos/WeblogEntryTagData.hbm.xml"
/>        +        <mapping
resource="org/apache/roller/pojos/WeblogEntryTagData.hbm.xml" /> + <mapping
resource="org/apache/roller/pojos/WeblogTagAggregateData.hbm.xml"
/>    +        <mapping
resource="org/apache/roller/pojos/SiteTagAggregateData.hbm.xml"
/>                                         <mapping
resource="org/apache/roller/pojos/EntryAttributeData.hbm.xml" />
         <mapping
resource="org/apache/roller/pojos/WeblogCategoryData.hbm.xml" />
         <mapping
resource="org/apache/roller/pojos/WeblogCategoryAssoc.hbm.xml" />

Modified: incubator/roller/trunk/web/WEB-INF/classes/roller.properties
URL:
http://svn.apache.org/viewvc/incubator/roller/trunk/web/WEB-INF/classes/roller.properties?view=diff&rev=450690&r1=450689&r2=450690

==============================================================================

--- incubator/roller/trunk/web/WEB-INF/classes/roller.properties
(original)
+++ incubator/roller/trunk/web/WEB-INF/classes/roller.properties Wed
Sep 27 21:38:07 2006
@@ -241,7 +241,7 @@
 #,org.apache.roller.ui.core.tasks.SyncWebsitesTask
# Comma separated list of task classnames to be executed hourly
-tasks.hourly=\
+tasks.hourly=org.apache.roller.ui.core.tasks.TagSummariesTask\
# Hourly Planet task: refresh latest entry list from all weblogs in
list
 #org.apache.roller.ui.core.tasks.RefreshEntriesTask


Reply via email to