You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@roller.apache.org by sn...@apache.org on 2005/06/09 05:19:20 UTC
svn commit: r189695 [19/67] - in /incubator/roller/trunk: ./ contrib/
contrib/lib/ contrib/plugins/ contrib/plugins/src/ contrib/plugins/src/org/
contrib/plugins/src/org/roller/ contrib/plugins/src/org/roller/presentation/
contrib/plugins/src/org/roller/presentation/velocity/
contrib/plugins/src/org/roller/presentation/velocity/plugins/
contrib/plugins/src/org/roller/presentation/velocity/plugins/acronyms/
contrib/plugins/src/org/roller/presentation/velocity/plugins/bookmarks/
contrib/plugins/src/org/roller/presentation/velocity/plugins/email/
contrib/plugins/src/org/roller/presentation/velocity/plugins/jspwiki/
contrib/plugins/src/org/roller/presentation/velocity/plugins/radeox/
contrib/plugins/src/org/roller/presentation/velocity/plugins/readmore/
contrib/plugins/src/org/roller/presentation/velocity/plugins/smileys/
contrib/plugins/src/org/roller/presentation/velocity/plugins/textile/
contrib/plugins/src/org/roller/presentation/velocity/plugins/topictag/
custom/ custom/src/ custom/web/ docs/ docs/images/ docs/installguide/
docs/installguide/old/ docs/userguide/ docs/userguide/images/
docs/userguide/old/ metadata/ metadata/database/
metadata/database/hibernate/ metadata/xdoclet/ nbproject/ personal/
personal/eclipse/ personal/testing/ sandbox/ sandbox/planetroller/
sandbox/planetroller/metadata/ sandbox/planetroller/metadata/database/
sandbox/planetroller/src/ sandbox/planetroller/src/org/
sandbox/planetroller/src/org/roller/
sandbox/planetroller/src/org/roller/tools/
sandbox/planetroller/src/org/roller/tools/planet/
sandbox/planetroller/templates/ sandbox/planetroller/test/
sandbox/planetroller/test/org/ sandbox/planetroller/test/org/roller/
sandbox/planetroller/test/org/roller/model/
sandbox/planetroller/test/org/roller/tools/
sandbox/planetroller/test/org/roller/tools/planet/
sandbox/planetroller/testdata/ sandbox/planetroller/testdata/cache/
sandbox/planetroller/testdata/output/ sandbox/standalone/
sandbox/standalone/jspwiki/ sandbox/standalone/jspwiki/default/
sandbox/standalone/jspwiki/default/images/ sandbox/standalone/lib/
sandbox/standalone/src/ sandbox/standalone/src/org/
sandbox/standalone/src/org/roller/ sandbox/standalone/src/org/roller/jspwiki/
sandbox/standalone/src/org/roller/tomcat/
sandbox/standalone/src/org/roller/util/ sandbox/standalone/tests/
sandbox/standalone/tests/org/ sandbox/standalone/tests/org/roller/
sandbox/standalone/tests/org/roller/util/ sandbox/standalone/tomcat/ src/
src/org/ src/org/roller/ src/org/roller/business/
src/org/roller/business/hibernate/ src/org/roller/business/search/
src/org/roller/business/search/operations/ src/org/roller/business/utils/
src/org/roller/config/ src/org/roller/config/runtime/ src/org/roller/model/
src/org/roller/pojos/ src/org/roller/presentation/
src/org/roller/presentation/atomapi/ src/org/roller/presentation/bookmarks/
src/org/roller/presentation/bookmarks/actions/
src/org/roller/presentation/bookmarks/formbeans/
src/org/roller/presentation/bookmarks/tags/
src/org/roller/presentation/filters/ src/org/roller/presentation/forms/
src/org/roller/presentation/newsfeeds/ src/org/roller/presentation/pagecache/
src/org/roller/presentation/pagecache/rollercache/
src/org/roller/presentation/pings/ src/org/roller/presentation/planet/
src/org/roller/presentation/tags/ src/org/roller/presentation/tags/calendar/
src/org/roller/presentation/tags/menu/ src/org/roller/presentation/util/
src/org/roller/presentation/velocity/ src/org/roller/presentation/weblog/
src/org/roller/presentation/weblog/actions/
src/org/roller/presentation/weblog/formbeans/
src/org/roller/presentation/weblog/tags/ src/org/roller/presentation/website/
src/org/roller/presentation/website/actions/
src/org/roller/presentation/website/formbeans/
src/org/roller/presentation/website/tags/
src/org/roller/presentation/xmlrpc/ src/org/roller/util/
src/org/roller/util/rome/ tests/ tests/org/ tests/org/roller/
tests/org/roller/ant/ tests/org/roller/business/
tests/org/roller/presentation/ tests/org/roller/presentation/atomapi/
tests/org/roller/presentation/bookmarks/
tests/org/roller/presentation/filters/
tests/org/roller/presentation/velocity/
tests/org/roller/presentation/velocity/plugins/
tests/org/roller/presentation/velocity/plugins/smileys/
tests/org/roller/presentation/velocity/plugins/textile/
tests/org/roller/presentation/weblog/ tests/org/roller/presentation/xmlrpc/
tests/org/roller/util/ tests/org/roller/util/rome/ tools/ tools/buildtime/
tools/buildtime/ant-1.6.2/ tools/buildtime/findbugs/
tools/buildtime/findbugs/lib/ tools/buildtime/findbugs/plugin/
tools/buildtime/mockrunner-0.3/ tools/buildtime/mockrunner-0.3/lib/
tools/buildtime/mockrunner-0.35/ tools/buildtime/mockrunner-0.35/lib/
tools/buildtime/tomcat-4.1.24/ tools/buildtime/xdoclet-1.2/
tools/buildtime/xdoclet-1.2/lib/ tools/hibernate-2.1/
tools/hibernate-2.1/lib/ tools/lib/ tools/standard-1.0.3/
tools/standard-1.0.3/lib/ tools/standard-1.0.3/tld/ tools/struts-1.2.4/
tools/struts-1.2.4/lib/ web/ web/WEB-INF/ web/WEB-INF/classes/
web/WEB-INF/classes/flavors/ web/WEB-INF/classes/themes/ web/bookmarks/
web/editor/ web/editor/images/ web/images/ web/images/editor/
web/images/midas/ web/images/preview/ web/images/smileys/ web/planet/
web/tags/ web/templates/ web/theme/ web/theme/images/ web/theme/lavender/
web/theme/scripts/ web/theme/scripts/classes/ web/themes/ web/themes/basic/
web/themes/berkley/ web/themes/berkley/images/ web/themes/brushedmetal/
web/themes/brushedmetal/images/ web/themes/cheb/ web/themes/cheb/images/
web/themes/cheb/scripts/ web/themes/clean/ web/themes/currency-i18n/
web/themes/currency-i18n/images/ web/themes/currency/
web/themes/currency/images/ web/themes/grey2/ web/themes/moonshine/
web/themes/movablemanila/ web/themes/movablemanila/images/
web/themes/pacifica/ web/themes/robot/ web/themes/rolling/
web/themes/rolling/images/ web/themes/sotto/ web/themes/sotto/images/
web/themes/sotto/styles/ web/themes/sunsets/ web/themes/sunsets/images/
web/themes/sunsets/scripts/ web/themes/sunsets/styles/ web/themes/werner/
web/themes/x2/ web/themes/x2/images/ web/themes/x2/scripts/
web/themes/x2/styles/ web/weblog/ web/website/
Added: incubator/roller/trunk/src/org/roller/business/WeblogManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/WeblogManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/WeblogManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/WeblogManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,513 @@
+/*
+ * Created on Feb 24, 2003
+ */
+package org.roller.business;
+
+import org.apache.commons.collections.comparators.ReverseComparator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.model.Roller;
+import org.roller.model.WeblogManager;
+import org.roller.pojos.CommentData;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WeblogCategoryAssoc;
+import org.roller.pojos.WeblogCategoryData;
+import org.roller.pojos.WeblogEntryData;
+import org.roller.pojos.WebsiteData;
+import org.roller.util.DateUtil;
+import org.roller.util.Utilities;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import org.roller.model.RollerFactory;
+
+/**
+ * Abstract base implementation using PersistenceStrategy.
+ * @author Dave Johnson
+ * @author Lance Lavandowska
+ */
+public abstract class WeblogManagerImpl implements WeblogManager
+{
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(WeblogManagerImpl.class);
+
+ protected PersistenceStrategy mStrategy;
+
+ /* inline creation of reverse comparator, anonymous inner class */
+ private Comparator reverseComparator = new ReverseComparator();
+ /*
+ new Comparator()
+ {
+ public int compare(Object o1, Object o2)
+ {
+ return -1 * ((Date) o1).compareTo((Date)o2);
+ }
+ };
+ */
+
+ private SimpleDateFormat formatter = DateUtil.get8charDateFormat();
+
+ public abstract List getWeblogEntries(
+ WebsiteData website,
+ Date startDate,
+ Date endDate,
+ String catName,
+ String status,
+ Integer maxEntries,
+ Boolean pinned) throws RollerException;
+
+ public abstract List getNextPrevEntries(
+ WeblogEntryData current,
+ String catName,
+ int maxEntries,
+ boolean next) throws RollerException;
+
+ public WeblogManagerImpl(PersistenceStrategy strategy)
+ {
+ mStrategy = strategy;
+ }
+
+ public void release()
+ {
+ }
+
+ //------------------------------------------------ WeblogCategoryData CRUD
+
+ /**
+ * @see org.roller.model.WeblogManager#createWeblogCategory()
+ */
+ public WeblogCategoryData createWeblogCategory()
+ {
+ return new WeblogCategoryData();
+ }
+
+ /**
+ * @see org.roller.model.WeblogManager#createWeblogCategory(
+ * org.roller.pojos.WebsiteData, org.roller.pojos.WeblogCategoryData,
+ * java.lang.String, java.lang.String, java.lang.String)
+ */
+ public WeblogCategoryData createWeblogCategory(
+ WebsiteData website,
+ WeblogCategoryData parent,
+ String name,
+ String description,
+ String image) throws RollerException
+ {
+ return new WeblogCategoryData(
+ null, website, parent, name, description, image);
+ }
+
+ public WeblogCategoryData retrieveWeblogCategory(String id)
+ throws RollerException
+ {
+ return (WeblogCategoryData) mStrategy.load(
+ id,
+ WeblogCategoryData.class);
+ }
+
+ //--------------------------------------------- WeblogCategoryData Queries
+
+ public WeblogCategoryData getWeblogCategoryByPath(
+ WebsiteData website, String categoryPath) throws RollerException
+ {
+ return getWeblogCategoryByPath(website, null, categoryPath);
+ }
+
+ public String getPath(WeblogCategoryData category) throws RollerException
+ {
+ if (null == category.getParent())
+ {
+ return "/";
+ }
+ else
+ {
+ String parentPath = getPath(category.getParent());
+ parentPath = "/".equals(parentPath) ? "" : parentPath;
+ return parentPath + "/" + category.getName();
+ }
+ }
+
+ public WeblogCategoryData getWeblogCategoryByPath(
+ WebsiteData website, WeblogCategoryData category, String path)
+ throws RollerException
+ {
+ final Iterator cats;
+ final String[] pathArray = Utilities.stringToStringArray(path, "/");
+
+ if (category == null && (null == path || "".equals(path.trim())))
+ {
+ throw new RollerException("Bad arguments.");
+ }
+
+ if (path.trim().equals("/"))
+ {
+ return getRootWeblogCategory(website);
+ }
+ else if (category == null || path.trim().startsWith("/"))
+ {
+ cats = getRootWeblogCategory(website).getWeblogCategories().iterator();
+ }
+ else
+ {
+ cats = category.getWeblogCategories().iterator();
+ }
+
+ while (cats.hasNext())
+ {
+ WeblogCategoryData possibleMatch = (WeblogCategoryData)cats.next();
+ if (possibleMatch.getName().equals(pathArray[0]))
+ {
+ if (pathArray.length == 1)
+ {
+ return possibleMatch;
+ }
+ else
+ {
+ String[] subpath = new String[pathArray.length - 1];
+ System.arraycopy(pathArray, 1, subpath, 0, subpath.length);
+
+ String pathString= Utilities.stringArrayToString(subpath,"/");
+ return getWeblogCategoryByPath(website, possibleMatch, pathString);
+ }
+ }
+ }
+
+ // The category did not match and neither did any sub-categories
+ return null;
+ }
+
+ //----------------------------------------------- WeblogCategoryAssoc CRUD
+
+ public WeblogCategoryAssoc createWeblogCategoryAssoc()
+ {
+ return new WeblogCategoryAssoc();
+ }
+
+ public WeblogCategoryAssoc createWeblogCategoryAssoc(
+ WeblogCategoryData category,
+ WeblogCategoryData ancestor,
+ String relation) throws RollerException
+ {
+ return new WeblogCategoryAssoc(null, category, ancestor, relation);
+ }
+
+ public WeblogCategoryAssoc retrieveWeblogCategoryAssoc(String id) throws RollerException
+ {
+ return (WeblogCategoryAssoc)mStrategy.load(id, WeblogCategoryAssoc.class);
+ }
+
+ //------------------------------------------------------- CommentData CRUD
+
+ public void removeComment(String id) throws RollerException
+ {
+ mStrategy.remove(id, CommentData.class);
+ }
+
+ public void removeComments(String[] ids) throws RollerException
+ {
+ for (int i = 0; i < ids.length; i++)
+ {
+ removeComment(ids[i]);
+ }
+ }
+
+ public void removeCommentsForEntry(String entryId) throws RollerException
+ {
+ List comments = getComments(entryId, false); // get all Comments
+ Iterator it = comments.iterator();
+ while (it.hasNext())
+ {
+ removeComment( ((CommentData)it.next()).getId() );
+ }
+ }
+
+ //---------------------------------------------------- CommentData Queries
+
+ public CommentData retrieveComment(String id) throws RollerException
+ {
+ return (CommentData) mStrategy.load(id, CommentData.class);
+ }
+
+ public List getComments(String entryId) throws RollerException
+ {
+ return getComments(entryId, true);
+ }
+
+ //--------------------------------------------------- WeblogEntryData CRUD
+
+ public WeblogEntryData retrieveWeblogEntry(String id)
+ throws RollerException
+ {
+ return (WeblogEntryData) mStrategy.load(
+ id, WeblogEntryData.class);
+ }
+
+ public void removeWeblogEntry(String id) throws RollerException
+ {
+ Roller mRoller = RollerFactory.getRoller();
+ mRoller.getRefererManager().removeReferersForEntry(id);
+ removeCommentsForEntry( id );
+ mStrategy.remove(id, WeblogEntryData.class);
+ }
+
+ //------------------------------------------------ WeblogEntryData Queries
+
+ /**
+ * Gets the Date of the latest Entry publish time, before the end of today,
+ * for all WeblogEntries
+ *
+ * @param userName
+ * @return Date
+ * @throws RollerException
+ */
+ public Date getWeblogLastPublishTime(String userName)
+ throws RollerException
+ {
+ return getWeblogLastPublishTime(userName, null);
+ }
+
+ //--------------------------------------------------------- Implementation
+
+ /**
+ * Get weblog entries.
+ * @see org.roller.model.WeblogManager#getWeblogEntries(
+ * java.lang.String,
+ * java.util.Date,
+ * java.util.Date,
+ * java.lang.String,
+ * java.lang.String,
+ * java.lang.Integer)
+ */
+ public List getWeblogEntries(
+ WebsiteData website,
+ Date startDate,
+ Date endDate,
+ String catName,
+ String status,
+ Integer maxEntries) throws RollerException
+ {
+ return getWeblogEntries(
+ website,
+ startDate,
+ endDate,
+ catName,
+ status,
+ maxEntries,
+ null);
+ }
+
+ /**
+ * Get webloog entries in range specified by offset and length.
+ * @see org.roller.model.WeblogManager#getWeblogEntries(
+ * java.lang.String,
+ * java.util.Date,
+ * java.util.Date,
+ * java.lang.String,
+ * java.lang.String,
+ * int offset,
+ * int length)
+ */
+ public List getWeblogEntries(
+ WebsiteData website,
+ Date startDate,
+ Date endDate,
+ String catName,
+ String status,
+ int offset,
+ int range) throws RollerException
+ {
+ List filtered = new ArrayList();
+ List entries = getWeblogEntries(
+ website,
+ startDate,
+ endDate,
+ catName,
+ status,
+ new Integer(offset + range),
+ null);
+ if (entries.size() < offset)
+ {
+ return filtered;
+ }
+ for (int i=offset; i<entries.size(); i++)
+ {
+ filtered.add(entries.get(i));
+ }
+ return filtered;
+ }
+
+ /**
+ * @see org.roller.model.WeblogManager#getWeblogEntryDayMap(
+ * java.lang.String,
+ * java.util.Date,
+ * java.util.Date,
+ * java.lang.String,
+ * java.lang.String,
+ * java.lang.Integer)
+ */
+ public Map getWeblogEntryObjectMap(
+ WebsiteData website,
+ Date startDate,
+ Date endDate,
+ String catName,
+ String status,
+ Integer maxEntries) throws RollerException
+ {
+ return getWeblogEntryMap(
+ website,
+ startDate,
+ endDate,
+ catName,
+ status,
+ maxEntries,
+ false);
+ }
+
+ /**
+ * @see org.roller.model.WeblogManager#getWeblogEntryDayMap(
+ * java.lang.String,
+ * java.util.Date,
+ * java.util.Date,
+ * java.lang.String,
+ * java.lang.String,
+ * java.lang.Integer)
+ */
+ public Map getWeblogEntryStringMap(
+ WebsiteData website,
+ Date startDate,
+ Date endDate,
+ String catName,
+ String status,
+ Integer maxEntries) throws RollerException
+ {
+ return getWeblogEntryMap(
+ website,
+ startDate,
+ endDate,
+ catName,
+ status,
+ maxEntries,
+ true);
+ }
+
+ private Map getWeblogEntryMap(
+ WebsiteData website,
+ Date startDate,
+ Date endDate,
+ String catName,
+ String status,
+ Integer maxEntries,
+ boolean stringsOnly) throws RollerException
+ {
+ TreeMap map = new TreeMap(reverseComparator);
+
+ List entries = getWeblogEntries(
+ website,
+ startDate,
+ endDate,
+ catName,
+ status,
+ maxEntries);
+
+ Calendar cal = Calendar.getInstance();
+ if (website != null)
+ {
+ cal.setTimeZone(website.getTimeZoneInstance());
+ }
+
+ for (Iterator wbItr = entries.iterator(); wbItr.hasNext();)
+ {
+ WeblogEntryData entry = (WeblogEntryData) wbItr.next();
+ Date sDate = DateUtil.getNoonOfDay(entry.getPubTime(), cal);
+ if (stringsOnly)
+ {
+ if (map.get(sDate) == null)
+ map.put(sDate, formatter.format(sDate));
+ }
+ else
+ {
+ List dayEntries = (List) map.get(sDate);
+ if (dayEntries == null)
+ {
+ dayEntries = new ArrayList();
+ map.put(sDate, dayEntries);
+ }
+ dayEntries.add(entry);
+ }
+ }
+ return map;
+ }
+
+ /*
+ * @see org.roller.model.WeblogManager#getNextEntry(org.roller.pojos.WeblogEntryData)
+ */
+ public List getNextEntries(
+ WeblogEntryData current, String catName, int maxEntries)
+ throws RollerException
+ {
+ return getNextPrevEntries(current, catName, maxEntries, true);
+ }
+
+ /*
+ * @see org.roller.model.WeblogManager#getPreviousEntry(org.roller.pojos.WeblogEntryData)
+ */
+ public List getPreviousEntries(
+ WeblogEntryData current, String catName, int maxEntries)
+ throws RollerException
+ {
+ return getNextPrevEntries(current, catName, maxEntries, false);
+ }
+
+ public WeblogEntryData getNextEntry(WeblogEntryData current, String catName)
+ throws RollerException
+ {
+ WeblogEntryData entry = null;
+ List entryList = getNextEntries(current, catName, 1);
+ if (entryList != null && entryList.size() > 0)
+ {
+ entry = (WeblogEntryData)entryList.get(entryList.size()-1);
+ }
+ return entry;
+ }
+
+ public WeblogEntryData getPreviousEntry(WeblogEntryData current, String catName)
+ throws RollerException
+ {
+ WeblogEntryData entry = null;
+ List entryList = getPreviousEntries(current, catName, 1);
+ if (entryList != null && entryList.size() > 0)
+ {
+ entry = (WeblogEntryData)entryList.get(0);
+ }
+ return entry;
+ }
+
+ /**
+ * @see org.roller.model.WeblogManager#getWeblogEntriesPinnedToMain(int)
+ */
+ public List getWeblogEntriesPinnedToMain(Integer max) throws RollerException
+ {
+ return getWeblogEntries(
+ null, null, new Date(), null, null, max, Boolean.TRUE);
+ }
+
+ /**
+ * Get absolute URL to this website.
+ * @return Absolute URL to this website.
+ */
+ public String getUrl(UserData user, String contextUrl)
+ {
+ String url =
+ Utilities.escapeHTML(contextUrl + "/page/" + user.getUserName());
+ return url;
+ }
+
+}
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateAutoPingManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateAutoPingManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateAutoPingManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateAutoPingManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2005
+ * Anil R. Gangolli. All rights reserved.
+ *
+ * Distributed with the Roller Weblogger Project under the terms of the Roller Software
+ * License
+ */
+
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import org.roller.RollerException;
+import org.roller.business.PersistenceStrategy;
+import org.roller.business.AutoPingManagerImpl;
+import org.roller.pojos.AutoPingData;
+import org.roller.pojos.PingTargetData;
+import org.roller.pojos.WeblogEntryData;
+import org.roller.pojos.WebsiteData;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+public class HibernateAutoPingManagerImpl extends AutoPingManagerImpl
+{
+ static final long serialVersionUID = 5420615676256979199L;
+
+ public HibernateAutoPingManagerImpl(PersistenceStrategy persistenceStrategy)
+ {
+ super(persistenceStrategy);
+ }
+
+ public void removeAutoPing(PingTargetData pingTarget, WebsiteData website) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(AutoPingData.class);
+ // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
+ // website.
+ criteria.add(Expression.eq("pingTarget", pingTarget));
+ criteria.add(Expression.eq("website", website));
+ List matches = criteria.list();
+ // This should have at most one element, but we remove them all regardless.
+ for (Iterator i = matches.iterator(); i.hasNext(); ) {
+ ((AutoPingData) i.next()).remove();
+ }
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public List getAutoPingsByWebsite(WebsiteData website) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(AutoPingData.class);
+ // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
+ // website.
+ criteria.add(Expression.eq("website", website));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public List getAutoPingsByTarget(PingTargetData pingTarget) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(AutoPingData.class);
+ // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
+ // website.
+ criteria.add(Expression.eq("pingTarget", pingTarget));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public void removeAllAutoPings() throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(AutoPingData.class);
+ List allAutoPings = criteria.list();
+ removeAutoPings(allAutoPings);
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public List getCategoryRestrictions(AutoPingData autoPing) throws RollerException
+ {
+ return Collections.EMPTY_LIST;
+ }
+
+ public void setCategoryRestrictions(AutoPingData autoPing, Collection newCategories)
+ {
+ // NOT YET IMPLEMENTED
+ return;
+ }
+
+ public List getApplicableAutoPings(WeblogEntryData changedWeblogEntry) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(AutoPingData.class);
+ // Currently category restrictions are not yet implemented, so we return all auto ping configs for the
+ // website.
+ criteria.add(Expression.eq("website", changedWeblogEntry.getWebsite()));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+}
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateBookmarkManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,326 @@
+/*
+ * Created on Jun 18, 2004
+ */
+package org.roller.business.hibernate;
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import org.roller.RollerException;
+import org.roller.business.BookmarkManagerImpl;
+import org.roller.business.PersistenceStrategy;
+import org.roller.pojos.Assoc;
+import org.roller.pojos.BookmarkData;
+import org.roller.pojos.FolderAssoc;
+import org.roller.pojos.FolderData;
+import org.roller.pojos.WebsiteData;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Hibernate queries.
+ *
+ * @author David M Johnson
+ */
+public class HibernateBookmarkManagerImpl extends BookmarkManagerImpl
+{
+ static final long serialVersionUID = 5286654557062382772L;
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(HibernateBookmarkManagerImpl.class);
+
+ /**
+ * @param pstrategy
+ * @param roller
+ */
+ public HibernateBookmarkManagerImpl(PersistenceStrategy pstrategy)
+ {
+ super(pstrategy);
+ mLogger.debug("Instantiating Bookmark Manager");
+ }
+
+ /**
+ * @see org.roller.model.BookmarkManager#retrieveBookmarks(
+ * org.roller.pojos.FolderData, boolean)
+ */
+ public List retrieveBookmarks(FolderData folder, boolean subfolders)
+ throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) mStrategy).getSession();
+ List bookmarks = new LinkedList();
+ if (subfolders)
+ {
+ // get bookmarks in subfolders
+ Criteria assocsQuery = session
+ .createCriteria(FolderAssoc.class);
+ assocsQuery.add(Expression.eq("ancestorFolder", folder));
+ Iterator assocs = assocsQuery.list().iterator();
+ while (assocs.hasNext())
+ {
+ FolderAssoc assoc = (FolderAssoc) assocs.next();
+ Criteria bookmarksQuery = session
+ .createCriteria(BookmarkData.class);
+ bookmarksQuery.add(Expression.eq("folder", assoc
+ .getFolder()));
+ Iterator bookmarkIter = bookmarksQuery.list().iterator();
+ while (bookmarkIter.hasNext())
+ {
+ BookmarkData entry = (BookmarkData) bookmarkIter.next();
+ bookmarks.add(entry);
+ }
+ }
+ }
+ // get bookmarks in folder
+ Criteria bookmarksQuery = session
+ .createCriteria(BookmarkData.class);
+ bookmarksQuery.add(Expression.eq("folder", folder));
+ Iterator bookmarkIter = bookmarksQuery.list().iterator();
+ while (bookmarkIter.hasNext())
+ {
+ BookmarkData bookmark = (BookmarkData) bookmarkIter.next();
+ bookmarks.add(bookmark);
+ }
+ return bookmarks;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public FolderData getRootFolder(WebsiteData website) throws RollerException
+ {
+ if (website == null)
+ throw new RollerException("website is null");
+ try
+ {
+ Session session = ((HibernateStrategy) mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderAssoc.class);
+ criteria.createAlias("folder", "f");
+ criteria.add(Expression.eq("f.website", website));
+ criteria.add(Expression.isNull("ancestorFolder"));
+ criteria.add(Expression.eq("relation", FolderAssoc.PARENT));
+ List results = criteria.list();
+ if (results.size() > 1)
+ {
+ // Should not have more than one root
+ throw new RollerException(
+ "More than one root folder found for website "
+ + website.getId());
+ }
+ else if (results.size() == 1)
+ {
+ // Return root
+ return ((FolderAssoc) results.get(0)).getFolder();
+ }
+ return null;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public List getAllFolders(WebsiteData website) throws RollerException
+ {
+ if (website == null)
+ throw new RollerException("Website is null");
+
+ try
+ {
+ Session session = ((HibernateStrategy) mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderData.class);
+ criteria.add(Expression.eq("website", website));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+
+ }
+
+ /**
+ * @see org.roller.model.BookmarkManager#isDuplicateFolderName(org.roller.pojos.FolderData)
+ */
+ public boolean isDuplicateFolderName(FolderData folder) throws RollerException
+ {
+ // ensure that no sibling folders share the same name
+ boolean isNewFolder = (folder.getId() == null);
+ FolderData parent =
+ isNewFolder ? (FolderData)folder.getNewParent() : folder.getParent();
+
+ if (null != parent)
+ {
+ List sameNames;
+ try
+ {
+ Session session = ((HibernateStrategy) mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderAssoc.class);
+ criteria.createAlias("folder", "f");
+ criteria.add(Expression.eq("f.name", folder.getName()));
+ criteria.add(Expression.eq("ancestorFolder", parent));
+ criteria.add(Expression.eq("relation", Assoc.PARENT));
+ sameNames = criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ // If we got some matches
+ if (sameNames.size() > 0)
+ {
+ // if we're saving a new folder, any matches are dups
+ if (isNewFolder) return true;
+ // otherwise it's a dup it isn't the same one (one match with the same id).
+ if (!(sameNames.size() == 1 && folder.getId().equals(((FolderAssoc)sameNames.get(0)).getFolder().getId())))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @see org.roller.model.BookmarkManager#getFolderParentAssoc(
+ * org.roller.pojos.FolderData)
+ */
+ public Assoc getFolderParentAssoc(FolderData folder) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderAssoc.class);
+ criteria.add(Expression.eq("folder", folder));
+ criteria.add(Expression.eq("relation", Assoc.PARENT));
+ List parents = criteria.list();
+ if (parents.size() > 1)
+ {
+ throw new RollerException("ERROR: more than one parent");
+ }
+ else if (parents.size() == 1)
+ {
+ return (Assoc) parents.get(0);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ /**
+ * @see org.roller.model.BookmarkManager#getFolderChildAssocs(
+ * org.roller.pojos.FolderData)
+ */
+ public List getFolderChildAssocs(FolderData folder) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderAssoc.class);
+ criteria.add(Expression.eq("ancestorFolder", folder));
+ criteria.add(Expression.eq("relation", Assoc.PARENT));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ /**
+ * @see org.roller.model.BookmarkManager#getAllFolderDecscendentAssocs(
+ * org.roller.pojos.FolderData)
+ */
+ public List getAllFolderDecscendentAssocs(FolderData folder) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderAssoc.class);
+ criteria.add(Expression.eq("ancestorFolder", folder));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ /**
+ * @see org.roller.model.BookmarkManager#getFolderAncestorAssocs(
+ * org.roller.pojos.FolderData)
+ */
+ public List getFolderAncestorAssocs(FolderData folder) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderAssoc.class);
+ criteria.add(Expression.eq("folder", folder));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ /**
+ * @see org.roller.model.BookmarkManager#isFolderInUse(org.roller.pojos.FolderData)
+ */
+ public boolean isFolderInUse(FolderData folder) throws RollerException
+ {
+ try
+ {
+ // We consider a folder to be "in use" if it contains any bookmarks or has
+ // any children.
+
+ // We first determine the number of bookmark entries.
+ // NOTE: This seems to be an attempt to optimize, rather than just use getBookmarks(),
+ // but I'm not sure that this optimization is really worthwhile, and it ignores
+ // caching in the case that the (lazy) getBookmarks has been done already. --agangolli
+ // TODO: condider changing to just use getBookmarks().size()
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(BookmarkData.class);
+ criteria.add(Expression.eq("folder", folder));
+ criteria.setMaxResults(1);
+ int entryCount = criteria.list().size();
+
+ // Return true if we have bookmarks or (, failing that, then checking) if we have children
+ return (entryCount > 0 || folder.getFolders().size() > 0);
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public boolean isDescendentOf(FolderData child, FolderData ancestor)
+ throws RollerException
+ {
+ boolean ret = false;
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(FolderAssoc.class);
+ criteria.add(Expression.eq("folder", child));
+ criteria.add(Expression.eq("ancestorFolder", ancestor));
+ ret = criteria.list().size() > 0;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ return ret;
+ }
+}
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateConfigManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,67 @@
+/*
+ * Created on Jun 18, 2004
+ */
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+
+import org.roller.RollerException;
+import org.roller.business.ConfigManagerImpl;
+import org.roller.business.PersistenceStrategy;
+import org.roller.pojos.RollerConfigData;
+
+import java.util.List;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author David M Johnson
+ */
+public class HibernateConfigManagerImpl extends ConfigManagerImpl
+{
+ static final long serialVersionUID = -3674252864091781177L;
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(HibernateConfigManagerImpl.class);
+
+ /**
+ * @param strategy
+ * @param roller
+ */
+ public HibernateConfigManagerImpl(PersistenceStrategy strategy)
+ {
+ super(strategy);
+ mLogger.debug("Instantiating Config Manager");
+ }
+
+ /**
+ * Fetch all RollerConfigs and return the first one, if any.
+ * Note: there should only be one!
+ * @see org.roller.model.ConfigManager#getRollerConfig()
+ */
+ public RollerConfigData getRollerConfig() throws RollerException
+ {
+ mLogger.error("Someone is trying to use the old config!!\n"+
+ "This configuration mechanism has been deprecated\n"+
+ "You should see this message only once when you first upgrade\n"+
+ "your installation to roller 1.2\n\n"+
+ "If you continue to see this message please shoot us an email\n"+
+ "at roller-development@lists.sourceforge.net with some output\n"+
+ "from your log files.\n");
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RollerConfigData.class);
+ criteria.setMaxResults(1);
+ List list = criteria.list();
+ return list.size()!=0 ? (RollerConfigData)list.get(0) : null;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+}
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePersistenceSession.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePersistenceSession.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePersistenceSession.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePersistenceSession.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,38 @@
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.Session;
+
+import org.roller.model.PersistenceSession;
+import org.roller.pojos.UserData;
+
+/**
+ * @author David M Johnson
+ */
+public class HibernatePersistenceSession implements PersistenceSession
+{
+ private Session session = null;
+ private UserData user = null;
+ public HibernatePersistenceSession(UserData user, Session session)
+ {
+ this.user = user;
+ this.session = session;
+ }
+ public Object getSessionObject()
+ {
+ return session;
+ }
+ public void setSessionObject(Object newSession)
+ {
+ this.session = (Session)session;
+ }
+ public UserData getUser()
+ {
+ return user;
+ }
+ public void setUser(UserData user)
+ {
+ this.user = user;
+ }
+}
+
+
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingQueueManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2005
+ * Anil R. Gangolli. All rights reserved.
+ *
+ * Distributed with the Roller Weblogger Project under the terms of the Roller Software
+ * License
+ */
+
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import net.sf.hibernate.expression.Order;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.business.PersistenceStrategy;
+import org.roller.business.PingQueueManagerImpl;
+import org.roller.pojos.AutoPingData;
+import org.roller.pojos.PingQueueEntryData;
+import org.roller.pojos.WebsiteData;
+import org.roller.pojos.PingTargetData;
+
+import java.sql.Timestamp;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Collection;
+
+public class HibernatePingQueueManagerImpl extends PingQueueManagerImpl
+{
+ static final long serialVersionUID = -7660638707453106615L;
+
+ private static Log logger = LogFactory.getLog(HibernatePingQueueManagerImpl.class);
+
+ public HibernatePingQueueManagerImpl(PersistenceStrategy persistenceStrategy)
+ {
+ super(persistenceStrategy);
+ }
+
+ public void addQueueEntry(AutoPingData autoPing) throws RollerException
+ {
+ if (logger.isDebugEnabled()) logger.debug("Creating new ping queue entry for auto ping configuration: " + autoPing);
+
+ // First check if there is an existing ping queue entry for the same target and website
+ if (isAlreadyQueued(autoPing))
+ {
+ if (logger.isDebugEnabled()) logger.debug("A ping queue entry is already present for this ping target and website: " + autoPing);
+ return;
+ }
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ PingQueueEntryData pingQueueEntry =
+ new PingQueueEntryData(null, now, autoPing.getPingTarget(), autoPing.getWebsite(), 0);
+ storeQueueEntry(pingQueueEntry);
+ }
+
+ public void dropQueue() throws RollerException
+ {
+ logger.info("NOTICE Dropping all ping queue entries.");
+ List queueEntries = getAllQueueEntries();
+ removeEntries(queueEntries);
+ }
+
+ public List getAllQueueEntries() throws RollerException
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(PingQueueEntryData.class);
+ criteria.addOrder(Order.asc("entryTime"));
+ try
+ {
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException("ERROR retrieving queue entries.", e);
+ }
+ }
+
+ public void removeQueueEntriesByPingTarget(PingTargetData pingTarget) throws RollerException {
+ try
+ {
+ if (logger.isDebugEnabled()) logger.debug("Removing all ping queue entries for ping target " + pingTarget);
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(PingQueueEntryData.class);
+ criteria.add(Expression.eq("pingTarget", pingTarget));
+ List queueEntries = criteria.list();
+ removeEntries(queueEntries);
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException("ERROR removing queue entries for ping target " + pingTarget, e);
+ }
+ }
+
+ public void removeQueueEntriesByWebsite(WebsiteData website) throws RollerException {
+ try
+ {
+ if (logger.isDebugEnabled()) logger.debug("Removing all ping queue entries for website " + website);
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(PingQueueEntryData.class);
+ criteria.add(Expression.eq("website", website));
+ List queueEntries = criteria.list();
+ removeEntries(queueEntries);
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException("ERROR removing queue entries for website " + website, e);
+ }
+ }
+
+ // private helper to determine if an has already been queued for the same website and ping target.
+ private boolean isAlreadyQueued(AutoPingData autoPing) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(PingQueueEntryData.class);
+ criteria.add(Expression.eq("pingTarget", autoPing.getPingTarget()));
+ criteria.add(Expression.eq("website", autoPing.getWebsite()));
+ return !criteria.list().isEmpty();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException("ERROR determining if preexisting queue entry is present.",e);
+ }
+ }
+
+ // Private helper to remove a collection of queue entries
+ private void removeEntries(Collection queueEntries) throws RollerException {
+ for (Iterator i = queueEntries.iterator(); i.hasNext();)
+ {
+ PingQueueEntryData pqe = (PingQueueEntryData) i.next();
+ pqe.remove();
+ }
+ }
+}
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePingTargetManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2005
+ * Anil R. Gangolli. All rights reserved.
+ *
+ * Distributed with the Roller Weblogger Project under the terms of the Roller Software
+ * License
+ */
+
+package org.roller.business.hibernate;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import net.sf.hibernate.expression.Order;
+import org.roller.RollerException;
+import org.roller.business.PersistenceStrategy;
+import org.roller.business.PingTargetManagerImpl;
+import org.roller.pojos.PingTargetData;
+import org.roller.pojos.WebsiteData;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Collection;
+
+public class HibernatePingTargetManagerImpl extends PingTargetManagerImpl
+{
+ static final long serialVersionUID = 121008492583382718L;
+
+ public HibernatePingTargetManagerImpl(PersistenceStrategy persistenceStrategy)
+ {
+ super(persistenceStrategy);
+ }
+
+ /**
+ * @see org.roller.model.PingTargetManager#getCommonPingTargets()
+ */
+ public List getCommonPingTargets() throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(PingTargetData.class);
+ criteria.add(Expression.isNull("website"));
+ criteria.addOrder(Order.asc("name"));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+
+ }
+
+ /**
+ * @see org.roller.model.PingTargetManager#getCustomPingTargets(org.roller.pojos.WebsiteData)
+ */
+ public List getCustomPingTargets(WebsiteData website) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(PingTargetData.class);
+ criteria.add(Expression.eq("website", website));
+ criteria.addOrder(Order.asc("name"));
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ /**
+ * @see org.roller.model.PingTargetManager#removeCustomPingTargets(org.roller.pojos.WebsiteData)
+ */
+ public void removeCustomPingTargets(WebsiteData website) throws RollerException
+ {
+ List customTargets = getCustomPingTargets(website);
+ removeTargets(customTargets);
+ }
+
+ /**
+ * @see org.roller.model.PingTargetManager#removeAllCustomPingTargets()
+ */
+ public void removeAllCustomPingTargets() throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy) persistenceStrategy).getSession();
+ Criteria criteria = session.createCriteria(PingTargetData.class);
+ criteria.add(Expression.isNotNull("website"));
+ List allCustomTargets = criteria.list();
+ removeTargets(allCustomTargets);
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ // Private helper to remove a collection of targets.
+ private void removeTargets(Collection customTargets)
+ throws RollerException
+ {
+ for (Iterator i = customTargets.iterator(); i.hasNext();)
+ {
+ PingTargetData pt = (PingTargetData) i.next();
+ pt.remove();
+ }
+ }
+
+}
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePlanetManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,371 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.
+ *
+ * Licensed 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.
+ */
+
+package org.roller.business.hibernate;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Query;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import net.sf.hibernate.expression.Order;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.business.PersistenceStrategy;
+import org.roller.business.PlanetManagerImpl;
+import org.roller.model.Roller;
+import org.roller.pojos.PlanetConfigData;
+import org.roller.pojos.PlanetEntryData;
+import org.roller.pojos.PlanetGroupData;
+import org.roller.pojos.PlanetGroupSubscriptionAssoc;
+import org.roller.pojos.PlanetSubscriptionData;
+
+
+/**
+ * Manages Planet Roller objects and entry aggregations in a database.
+ * @author Dave Johnson
+ */
+public class HibernatePlanetManagerImpl extends PlanetManagerImpl
+{
+ private List topSubscriptions;
+
+ private static Log logger =
+ LogFactory.getFactory().getInstance(HibernatePlanetManagerImpl.class);
+
+ public HibernatePlanetManagerImpl(
+ PersistenceStrategy strategy, Roller roller)
+ {
+ super(strategy, roller);
+ }
+
+ public void saveConfiguration(PlanetConfigData config)
+ throws RollerException
+ {
+ config.save();
+ }
+
+ public void saveGroup(PlanetGroupData group) throws RollerException
+ {
+ Iterator assocs = group.getGroupSubscriptionAssocs().iterator();
+ while (assocs.hasNext())
+ {
+ PlanetGroupSubscriptionAssoc assoc =
+ (PlanetGroupSubscriptionAssoc)assocs.next();
+ assoc.save();
+ }
+ group.save();
+ }
+
+ public void saveEntry(PlanetEntryData entry) throws RollerException
+ {
+ entry.save();
+ }
+
+ public void saveSubscription(PlanetSubscriptionData sub)
+ throws RollerException
+ {
+ PlanetSubscriptionData existing = getSubscription(sub.getFeedUrl());
+ if (existing == null || (existing.getId().equals(sub.getId())))
+ {
+ sub.save();
+ }
+ else
+ {
+ throw new RollerException("ERROR: duplicate feed URLs not allowed");
+ }
+ }
+
+ public PlanetConfigData getConfiguration() throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Criteria criteria = session.createCriteria(PlanetConfigData.class);
+ criteria.setMaxResults(1);
+ List list = criteria.list();
+ return list.size()!=0 ? (PlanetConfigData)list.get(0) : null;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public List getGroups() throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Criteria criteria = session.createCriteria(PlanetGroupData.class);
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public List getGroupHandles() throws RollerException
+ {
+ List handles = new ArrayList();
+ Iterator list = getGroups().iterator();
+ while (list.hasNext())
+ {
+ PlanetGroupData group = (PlanetGroupData)list.next();
+ handles.add(group.getHandle());
+ }
+ return handles;
+ }
+
+ public PlanetSubscriptionData getSubscription(String feedUrl)
+ throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Criteria criteria =
+ session.createCriteria(PlanetSubscriptionData.class);
+ criteria.setMaxResults(1);
+ criteria.add(Expression.eq("feedUrl", feedUrl));
+ List list = criteria.list();
+ return list.size()!=0 ? (PlanetSubscriptionData)list.get(0) : null;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public PlanetSubscriptionData getSubscriptionById(String id)
+ throws RollerException
+ {
+ return (PlanetSubscriptionData)
+ strategy.load(id, PlanetSubscriptionData.class);
+ }
+
+ public PlanetGroupData getGroup(String handle) throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Criteria criteria = session.createCriteria(PlanetGroupData.class);
+ criteria.setMaxResults(1);
+ criteria.add(Expression.eq("handle", handle));
+ List list = criteria.list();
+ return list.size()!=0 ? (PlanetGroupData)list.get(0) : null;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ public PlanetGroupData getGroupById(String id) throws RollerException
+ {
+ return (PlanetGroupData)
+ strategy.load(id, PlanetGroupData.class);
+ }
+
+ public synchronized List getAggregation(int maxEntries) throws RollerException
+ {
+ return getAggregation(null, maxEntries);
+ }
+
+ public synchronized List getAggregation(PlanetGroupData group, int maxEntries)
+ throws RollerException
+ {
+ long startTime = System.currentTimeMillis();
+ List ret = null;
+ try
+ {
+ if (group != null)
+ {
+ ret = (List)aggregationsByGroup.get(group);
+ }
+ else
+ {
+ ret = aggregation;
+ }
+ if (ret == null)
+ {
+ Session session =
+ ((HibernateStrategy)strategy).getSession();
+ if (group != null)
+ {
+ Query query = session.createQuery(
+ "select entry from org.roller.pojos.PlanetEntryData entry "
+ +"join entry.subscription.groupSubscriptionAssocs assoc "
+ +"where assoc.group=:group order by entry.published desc");
+ query.setEntity("group", group);
+ query.setMaxResults(maxEntries);
+ ret = query.list();
+ }
+ else
+ {
+ Query query = session.createQuery(
+ "select entry from org.roller.pojos.PlanetEntryData entry "
+ +"join entry.subscription.groupSubscriptionAssocs assoc "
+ +"where "
+ +"assoc.group.handle='external' or assoc.group.handle='all'"
+ +" order by entry.published desc");
+ query.setMaxResults(maxEntries);
+ ret = query.list();
+ }
+ Date retLastUpdated = null;
+ if (ret.size() > 0)
+ {
+ PlanetEntryData entry = (PlanetEntryData)ret.get(0);
+ retLastUpdated = entry.getPublished();
+ }
+ else
+ {
+ retLastUpdated = new Date();
+ }
+ if (group != null)
+ {
+ aggregationsByGroup.put(group, ret);
+ lastUpdatedByGroup.put(group, retLastUpdated);
+ }
+ else
+ {
+ aggregation = ret;
+ lastUpdated = retLastUpdated;
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ logger.error("ERROR: building aggregation for: "+group, e);
+ throw new RollerException(e);
+ }
+ long endTime = System.currentTimeMillis();
+ logger.info("Generated aggregation in "
+ +((endTime-startTime)/1000.0)+" seconds");
+ return ret;
+ }
+
+ public void deleteEntry(PlanetEntryData entry) throws RollerException
+ {
+ entry.remove();
+ }
+
+ public void deleteGroup(PlanetGroupData group) throws RollerException
+ {
+ group.remove();
+ }
+
+ public void deleteSubscription(PlanetSubscriptionData sub)
+ throws RollerException
+ {
+ sub.remove();
+ }
+
+ public Iterator getAllSubscriptions()
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Criteria criteria =
+ session.createCriteria(PlanetSubscriptionData.class);
+ criteria.addOrder(Order.asc("feedUrl"));
+ List list = criteria.list();
+ return list.iterator();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(
+ "ERROR fetching subscription collection", e);
+ }
+ }
+
+ public int getSubscriptionCount() throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Integer count = (Integer)session.createQuery(
+ "select count(*) from org.roller.pojos.PlanetSubscriptionData").uniqueResult();
+ return count.intValue();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(
+ "ERROR fetching subscription count", e);
+ }
+ }
+
+ public synchronized List getTopSubscriptions(int max) throws RollerException
+ {
+ if (topSubscriptions == null)
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Criteria criteria =
+ session.createCriteria(PlanetSubscriptionData.class);
+ criteria.setMaxResults(max);
+ criteria.addOrder(Order.desc("inboundblogs"));
+ topSubscriptions = criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+ return topSubscriptions;
+ }
+
+ public synchronized List getTopSubscriptions(
+ PlanetGroupData group, int max) throws RollerException
+ {
+ if (topSubscriptions == null)
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)strategy).getSession();
+ Query query = session.createQuery(
+ "select sub from org.roller.pojos.PlanetSubscriptionData sub "
+ +"join sub.groupSubscriptionAssocs assoc "
+ +"where "
+ +"assoc.group.handle=:groupHandle "
+ +"order by sub.inboundblogs desc");
+ query.setString("groupHandle", group.getHandle());
+ query.setMaxResults(max);
+ topSubscriptions = query.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+ return topSubscriptions;
+ }
+
+ public synchronized void clearCachedAggregations()
+ {
+ super.clearCachedAggregations();
+ topSubscriptions = null;
+ }
+
+}
+
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePropertiesManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePropertiesManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePropertiesManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernatePropertiesManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,92 @@
+/*
+ * HibernatePropertiesManagerImpl.java
+ *
+ * Created on April 21, 2005, 10:40 AM
+ */
+
+package org.roller.business.hibernate;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.business.PersistenceStrategy;
+import org.roller.business.PropertiesManagerImpl;
+import org.roller.pojos.RollerPropertyData;
+
+/**
+ * A hibernate specific implementation of the properties manager.
+ *
+ * @author Allen Gilliland
+ */
+public class HibernatePropertiesManagerImpl extends PropertiesManagerImpl {
+
+ static final long serialVersionUID = -4326713177137796936L;
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(HibernatePropertiesManagerImpl.class);
+
+
+ /** Creates a new instance of HibernatePropertiesManagerImpl */
+ public HibernatePropertiesManagerImpl(PersistenceStrategy strategy) {
+ super(strategy);
+ mLogger.debug("Instantiating Hibernate Properties Manager");
+ }
+
+
+ /** Retrieve a single property by name */
+ public RollerPropertyData getProperty(String name) throws RollerException {
+ try
+ {
+ Session session = ((HibernateStrategy) mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RollerPropertyData.class);
+ criteria.add(Expression.eq("name", name));
+ criteria.setMaxResults(1);
+ List list = criteria.list();
+ return (list.size()!= 0) ? (RollerPropertyData)list.get(0) : null;
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+
+ /** Retrieve all properties */
+ public Map getProperties() throws RollerException {
+
+ HashMap props = new HashMap();
+
+ try
+ {
+ Session session = ((HibernateStrategy) mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RollerPropertyData.class);
+ List list = criteria.list();
+
+ // for convenience sake we are going to put the list of props
+ // into a map for users to access it. The value element of the
+ // hash still needs to be the RollerPropertyData object so that
+ // we can save the elements again after they have been updated
+ RollerPropertyData prop = null;
+ Iterator it = list.iterator();
+ while(it.hasNext()) {
+ prop = (RollerPropertyData) it.next();
+ props.put(prop.getName(), prop);
+ }
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+
+ return props;
+ }
+
+}
Added: incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java?rev=189695&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java (added)
+++ incubator/roller/trunk/src/org/roller/business/hibernate/HibernateRefererManagerImpl.java Wed Jun 8 20:18:46 2005
@@ -0,0 +1,592 @@
+/*
+ * Created on Feb 23, 2003
+ */
+package org.roller.business.hibernate;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import net.sf.hibernate.Criteria;
+import net.sf.hibernate.Hibernate;
+import net.sf.hibernate.HibernateException;
+import net.sf.hibernate.Session;
+import net.sf.hibernate.expression.Expression;
+import net.sf.hibernate.expression.Junction;
+import net.sf.hibernate.expression.Order;
+import net.sf.hibernate.type.Type;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.roller.RollerException;
+import org.roller.business.PersistenceStrategy;
+import org.roller.business.RefererManagerImpl;
+import org.roller.config.RollerRuntimeConfig;
+import org.roller.model.RefererManager;
+import org.roller.pojos.RefererData;
+import org.roller.pojos.WebsiteData;
+import org.roller.pojos.WebsiteDisplayData;
+
+
+/**
+ * Hibernate queries.
+ * @author David M Johnson
+ */
+public class HibernateRefererManagerImpl extends RefererManagerImpl
+ implements RefererManager
+{
+ static final long serialVersionUID = -4966091850482256435L;
+
+ private static Log mLogger =
+ LogFactory.getFactory().getInstance(HibernateRefererManagerImpl.class);
+
+ //-------------------------------------------------- Startup and Shutdown
+ public HibernateRefererManagerImpl(PersistenceStrategy support)
+ throws RollerException
+ {
+ super();
+ mStrategy = (HibernateStrategy)support;
+ mLogger.debug("Instantiating Referer Manager");
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Apply ignoreWord/spam filters to all referers in system.
+ */
+ public void applyRefererFilters() throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+
+ String spamwords = RollerRuntimeConfig.getProperty("spam.referers.ignorewords");
+
+ String[] ignoreWords = StringUtils.split(
+ StringUtils.deleteWhitespace(spamwords),",");
+ Junction or = Expression.disjunction();
+ for (int i=0; i<ignoreWords.length; i++)
+ {
+ String ignoreWord = ignoreWords[i].trim();
+ or.add(Expression.ilike("refererUrl","%"+ignoreWord+"%"));
+ }
+ criteria.add(Expression.conjunction()
+ .add(Expression.isNull("excerpt"))
+ .add(or)
+ );
+
+ Iterator referers = criteria.list().iterator();
+ while (referers.hasNext())
+ {
+ removeReferer( ((RefererData)referers.next()).getId() );
+ }
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Apply ignoreWord/spam filters to all referers in website.
+ */
+ public void applyRefererFilters(WebsiteData website) throws RollerException
+ {
+ if (null == website) throw new RollerException("website is null");
+ if (null == website.getIgnoreWords()) return;
+
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+
+ String[] ignoreWords = StringUtils.split(
+ StringUtils.deleteWhitespace(website.getIgnoreWords()),",");
+ Junction or = Expression.disjunction();
+ for (int i=0; i<ignoreWords.length; i++)
+ {
+ String ignoreWord = ignoreWords[i].trim();
+ or.add(Expression.ilike("refererUrl","%"+ignoreWord+"%"));
+ }
+ criteria.add(Expression.conjunction()
+ .add(Expression.isNull("excerpt"))
+ .add(Expression.eq("website",website))
+ .add(or)
+ );
+
+ Iterator referers = criteria.list().iterator();
+ while (referers.hasNext())
+ {
+ removeReferer( ((RefererData)referers.next()).getId() );
+ }
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Use Hibernate directly because Roller's Query API does too much allocation.
+ */
+ protected List getExistingReferers(WebsiteData website, String dateString,
+ String permalink) throws RollerException
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.add(Expression.conjunction()
+ .add(Expression.eq("website",website))
+ .add(Expression.eq("dateString",dateString))
+ .add(Expression.eq("refererPermalink",permalink)));
+ try
+ {
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Use Hibernate directly because Roller's Query API does too much allocation.
+ */
+ protected List getMatchingReferers(WebsiteData website, String requestUrl,
+ String refererUrl) throws RollerException
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.add(Expression.conjunction()
+ .add(Expression.eq("website",website))
+ .add(Expression.eq("requestUrl",requestUrl))
+ .add(Expression.eq("refererUrl",refererUrl)));
+ try
+ {
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Use raw SQL because Hibernate can't handle sorting by sum.
+ */
+ public List getDaysPopularWebsites(int max) throws RollerException
+ {
+ // TODO Hibernate version of getDaysPopularWebsites
+ // TODO Move to full use of mSupport
+ String msg = "Getting popular websites";
+ Session ses = null; // the session will eventually be release by RequestFilter
+ Connection con = null;
+ try
+ {
+ List list = new ArrayList();
+
+ ses = ((HibernateStrategy)mStrategy).getSession();
+ con = ses.connection();
+
+ final PreparedStatement stmt;
+ if (con.getMetaData().getDriverName().startsWith("HSQL"))
+ {
+ // special handling for HSQLDB
+ stmt = con.prepareStatement(
+ "select top ? u.username,w.name,w.name,sum(r.dayhits) as s "+
+ "from rolleruser as u, website as w, referer as r "+
+ "where r.websiteid=w.id and w.userid=u.id and w.isenabled=? " +
+ "group by u.username,w.name,w.id order by s desc");
+ stmt.setInt(1, max);
+ stmt.setBoolean(2, true);
+ }
+ else
+ {
+ stmt = con.prepareStatement(
+ "select u.username,w.name,w.name,sum(r.dayhits) as s "+
+ "from rolleruser as u, website as w, referer as r "+
+ "where r.websiteid=w.id and w.userid=u.id and w.isenabled= ? " +
+ // Ben Walding (a Postgres SQL user): Basically, you have
+ // to have all non-aggregated columns that exist in your
+ // 'SELECT' section, in the 'GROUP BY' section as well:
+ "group by u.username,w.name,w.id order by s desc limit ?");
+ // and not this: "group by w.id order by s desc");
+ stmt.setBoolean(1, true);
+ stmt.setInt(2, max);
+ }
+ ResultSet rs = stmt.executeQuery();
+ if ( rs.next() )
+ {
+ do
+ {
+ String userName = rs.getString(1);
+ String name = rs.getString(2);
+ String websiteName = rs.getString(3);
+ Integer hits = new Integer(rs.getInt(4));
+ list.add(new WebsiteDisplayData(
+ name,
+ userName,
+ websiteName,
+ hits));
+ }
+ while ( rs.next() );
+ }
+ return list;
+ }
+ catch (Throwable pe)
+ {
+ mLogger.error(msg, pe);
+ throw new RollerException(msg, pe);
+ }
+
+// Don't close connection, Hibernate is holding it
+// finally
+// {
+// try
+// {
+// if (con != null) con.close();
+// }
+// catch (Throwable t)
+// {
+// mLogger.error("Closing connection",t);
+// }
+// }
+
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Use raw SQL because Hibernate can't handle the query.
+ */
+ protected int getHits(WebsiteData website, String type)
+ throws RollerException
+ {
+ int hits = 0;
+ if (mLogger.isDebugEnabled())
+ {
+ mLogger.debug("getHits: " + website.getName());
+ }
+
+ //Question: why not use website.id instead to reduce joins?
+ Object[] args = { Boolean.TRUE, website.getUser().getUserName() };
+ Type[] types = { Hibernate.BOOLEAN, Hibernate.STRING };
+
+ // For a query like this, Hibernate returns a list of lists
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ List results;
+ try
+ {
+ results = session.find(
+ "select sum(h.dayHits),sum(h.totalHits) from h in class " +
+ "org.roller.pojos.RefererData " +
+ "where h.website.isEnabled=? and h.website.user.userName=? ",
+ args, types);
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ Object[] resultsArray = (Object[]) results.get(0);
+
+ if (resultsArray.length > 0 && type.equals(DAYHITS))
+ {
+ if ( resultsArray[0] != null )
+ {
+ hits = ((Integer) resultsArray[0]).intValue();
+ }
+ }
+ else if ( resultsArray.length > 0 )
+ {
+ if ( resultsArray[0] != null )
+ {
+ hits = ((Integer) resultsArray[1]).intValue();
+ }
+ }
+ else
+ {
+ hits = 0;
+ }
+
+ return hits;
+ }
+
+ /**
+ * @see org.roller.pojos.RefererManager#getReferers(java.lang.String)
+ */
+ public List getReferers(WebsiteData website) throws RollerException
+ {
+ if (website==null )
+ throw new RollerException("website is null");
+
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.add(Expression.eq("website",website));
+ criteria.addOrder(Order.desc("totalHits"));
+ try
+ {
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * @see org.roller.pojos.RefererManager#getTodaysReferers(String)
+ */
+ public List getTodaysReferers(WebsiteData website)
+ throws RollerException
+ {
+ if (website==null )
+ throw new RollerException("website is null");
+
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.add(Expression.eq("website", website));
+ criteria.add(Expression.gt("dayHits", new Integer(0)));
+ criteria.addOrder(Order.desc("dayHits"));
+ try
+ {
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Returns referers for a specified day. Duplicate enties are not
+ * included in this list so the hit counts may not be accurate.
+ * @see org.roller.pojos.RefererManager#getReferersToDate(
+ * org.roller.pojos.WebsiteData, java.lang.String)
+ */
+ public List getReferersToDate(WebsiteData website, String date)
+ throws RollerException
+ {
+ if (website==null )
+ throw new RollerException("website is null");
+
+ if (date==null )
+ throw new RollerException("Date is null");
+
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.add(Expression.eq("website", website));
+ criteria.add(Expression.eq("dateString", date));
+ criteria.add(Expression.eq("duplicate", Boolean.FALSE));
+ criteria.addOrder(Order.desc("totalHits"));
+ try
+ {
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * @see org.roller.pojos.RefererManager#getReferersToEntry(
+ * java.lang.String, java.lang.String)
+ */
+ public List getReferersToEntry(String entryid) throws RollerException
+ {
+ if (null == entryid)
+ throw new RollerException("entryid is null");
+
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.createAlias("weblogEntry","e");
+
+ criteria.add(Expression.eq("e.id", entryid));
+ criteria.add(Expression.isNotNull("title"));
+ criteria.add(Expression.isNotNull("excerpt"));
+
+ criteria.addOrder(Order.desc("totalHits"));
+
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * @see org.roller.pojos.RefererManager#getReferersToEntry(
+ * java.lang.String, java.lang.String)
+ */
+ public void removeReferersForEntry(String entryid) throws RollerException
+ {
+ if (null == entryid)
+ throw new RollerException("entryid is null");
+
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.createAlias("weblogEntry","e");
+ criteria.add(Expression.eq("e.id", entryid));
+
+ Iterator referers = criteria.list().iterator();
+ while (referers.hasNext())
+ {
+ removeReferer( ((RefererData)referers.next()).getId() );
+ }
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Query for collection of referers.
+ */
+ protected List getReferersToWebsite(WebsiteData website, String refererUrl)
+ throws RollerException
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.add(Expression.eq("website", website));
+ criteria.add(Expression.eq("refererUrl", refererUrl));
+ try
+ {
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+
+ /**
+ * Query for collection of referers.
+ */
+ protected List getReferersWithSameTitle(
+ WebsiteData website,
+ String requestUrl,
+ String title,
+ String excerpt)
+ throws RollerException
+ {
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+
+ Junction conjunction = Expression.conjunction();
+ conjunction.add(Expression.eq("website", website));
+ conjunction.add(Expression.eq("requestUrl", requestUrl));
+
+ Junction disjunction = Expression.conjunction();
+ disjunction.add(Expression.eq("title", title));
+ disjunction.add(Expression.eq("excerpt", excerpt));
+
+ criteria.add(conjunction);
+ criteria.add(disjunction);
+
+ return criteria.list();
+ }
+ catch (HibernateException e)
+ {
+ throw new RollerException(e);
+ }
+ }
+
+ /**
+ * Purge referers at midnight. Zero out all dayHits and remove all
+ * referers that do not have excerpts.
+ */
+ public void checkForTurnover( boolean forceTurnover, String websiteId )
+ throws RollerException
+ {
+ // Note, this method doesn't need to be synchronized anymore since
+ // it's called from the timer task now, and will never be executed
+ // by two threads simultaneously.
+ if (mLogger.isDebugEnabled())
+ {
+ mLogger.debug("checkForTurnover");
+ }
+
+ Date now = new Date();
+
+ if (forceTurnover ||
+ !mDateFormat.format(now).equals(mDateFormat.format(mRefDate)))
+ {
+ try
+ {
+ if (websiteId == null) mRefDate = now;
+
+ List refs;
+ try
+ {
+ Session session = ((HibernateStrategy)mStrategy).getSession();
+ Criteria criteria = session.createCriteria(RefererData.class);
+ criteria.add(Expression.gt("dayHits", new Integer(0)));
+ if (websiteId != null)
+ {
+ criteria.add(Expression.eq("website.id", websiteId));
+ }
+ refs = criteria.list();
+ }
+ catch (HibernateException e1)
+ {
+ throw new RollerException(e1);
+ }
+
+ Integer zero = new Integer(0);
+ for (Iterator rdItr = refs.iterator(); rdItr.hasNext();) {
+ RefererData referer = (RefererData) rdItr.next();
+
+ if ( (referer.getExcerpt() != null) &&
+ (referer.getExcerpt().trim().length() > 0))
+ {
+ // Zero out dayHits of referers with excerpts
+ referer.setDayHits(zero);
+ storeReferer(referer);
+ }
+ else
+ {
+ // Throw away referers without excerpts
+ removeReferer(referer.getId());
+ }
+ }
+ }
+ catch (RollerException e)
+ {
+ mLogger.error("EXCEPTION resetting referers",e);
+ }
+ }
+ }
+
+
+}