roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r519104 - in /incubator/roller/branches/roller_4.0_newbackend/apps/planet: nbproject/ src/java/org/apache/roller/planet/business/datamapper/ src/java/org/apache/roller/planet/business/datamapper/jpa/ src/java/org/apache/roller/planet/busine...
Date Fri, 16 Mar 2007 19:09:57 GMT
Author: snoopdave
Date: Fri Mar 16 12:09:54 2007
New Revision: 519104

URL: http://svn.apache.org/viewvc?view=rev&rev=519104
Log:
Implementations for new methods added in trunk

Added:
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetManagerImpl.java
Modified:
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/nbproject/project.xml
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/DatamapperPlanetManagerImpl.java
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetImpl.java
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetEntryData.orm.xml
    incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetSubscriptionData.orm.xml

Modified: incubator/roller/branches/roller_4.0_newbackend/apps/planet/nbproject/project.xml
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/nbproject/project.xml?view=diff&rev=519104&r1=519103&r2=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/nbproject/project.xml (original)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/nbproject/project.xml Fri Mar 16 12:09:54 2007
@@ -74,7 +74,7 @@
         <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2">
             <compilation-unit>
                 <package-root>src/java</package-root>
-                <classpath mode="compile">../../tools/lib/activation.jar:../../tools/lib/log4j-1.2.11.jar:../../tools/lib/mail.jar:../../tools/lib/rome-0.9.jar:../../tools/lib/rome-fetcher-0.9.jar:../../tools/lib/commons-codec-1.3.jar:../../tools/lib/jdom.jar:../../tools/struts-1.2.4/lib/commons-lang-2.0.jar:../../tools/struts-1.2.4/lib/commons-logging.jar:../../tools/hibernate-3.1/hibernate3.jar:../../tools/hibernate-3.1/lib/asm-attrs.jar:../../tools/hibernate-3.1/lib/asm.jar:../../tools/hibernate-3.1/lib/cglib-2.1.3.jar:../../tools/hibernate-3.1/lib/dom4j-1.6.1.jar:../../tools/hibernate-3.1/lib/ehcache-1.1.jar:../../tools/hibernate-3.1/lib/jdbc2_0-stdext.jar:../../tools/hibernate-3.1/lib/jta.jar:../../tools/struts-1.2.4/lib/antlr.jar:../../tools/roller-core/roller-core.jar:../../tools/struts-2.0.1/lib/antlr-2.7.2.jar:../../tools/struts-2.0.1/lib/commons-beanutils-1.6.jar:../../tools/struts-2.0.1/lib/commons-chain-1.1.jar:../../tools/struts-2.0.1/lib/commons-validator-1.3.0
 .jar:../../tools/struts-2.0.1/lib/freemarker-2.3.4.jar:../../tools/struts-2.0.1/lib/ognl-2.6.7.jar:../../tools/struts-2.0.1/lib/oro-2.0.8.jar:../../tools/struts-2.0.1/lib/spring-aop-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-beans-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-context-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-core-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-web-1.2.8.jar:../../tools/struts-2.0.1/lib/struts2-api-2.0.1.jar:../../tools/struts-2.0.1/lib/struts2-core-2.0.1.jar:../../tools/struts-2.0.1/lib/xwork-2.0-beta-1.jar:../../tools/jpa/toplink-essentials.jar</classpath>
+                <classpath mode="compile">../../tools/lib/activation.jar:../../tools/lib/log4j-1.2.11.jar:../../tools/lib/mail.jar:../../tools/lib/rome-0.9.jar:../../tools/lib/rome-fetcher-0.9.jar:../../tools/lib/commons-codec-1.3.jar:../../tools/lib/jdom.jar:../../tools/struts-1.2.4/lib/commons-lang-2.0.jar:../../tools/struts-1.2.4/lib/commons-logging.jar:../../tools/hibernate-3.1/hibernate3.jar:../../tools/hibernate-3.1/lib/asm-attrs.jar:../../tools/hibernate-3.1/lib/asm.jar:../../tools/hibernate-3.1/lib/cglib-2.1.3.jar:../../tools/hibernate-3.1/lib/dom4j-1.6.1.jar:../../tools/hibernate-3.1/lib/ehcache-1.1.jar:../../tools/hibernate-3.1/lib/jdbc2_0-stdext.jar:../../tools/hibernate-3.1/lib/jta.jar:../../tools/struts-1.2.4/lib/antlr.jar:../../tools/roller-core/roller-core.jar:../../tools/struts-2.0.1/lib/antlr-2.7.2.jar:../../tools/struts-2.0.1/lib/commons-beanutils-1.6.jar:../../tools/struts-2.0.1/lib/commons-chain-1.1.jar:../../tools/struts-2.0.1/lib/commons-validator-1.3.0
 .jar:../../tools/struts-2.0.1/lib/freemarker-2.3.4.jar:../../tools/struts-2.0.1/lib/ognl-2.6.7.jar:../../tools/struts-2.0.1/lib/oro-2.0.8.jar:../../tools/struts-2.0.1/lib/spring-aop-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-beans-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-context-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-core-1.2.8.jar:../../tools/struts-2.0.1/lib/spring-web-1.2.8.jar:../../tools/struts-2.0.1/lib/struts2-api-2.0.1.jar:../../tools/struts-2.0.1/lib/struts2-core-2.0.1.jar:../../tools/struts-2.0.1/lib/xwork-2.0-beta-1.jar:../../tools/toplink-essentials-9.1/toplink-essentials.jar</classpath>
                 <source-level>1.4</source-level>
             </compilation-unit>
             <compilation-unit>

Modified: incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/DatamapperPlanetManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/DatamapperPlanetManagerImpl.java?view=diff&rev=519104&r1=519103&r2=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/DatamapperPlanetManagerImpl.java (original)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/DatamapperPlanetManagerImpl.java Fri Mar 16 12:09:54 2007
@@ -1,4 +1,3 @@
-package org.apache.roller.planet.business.datamapper;
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  *  contributor license agreements.  The ASF licenses this file to You
@@ -17,25 +16,13 @@
  * directory of this distribution.
  */
 
-import com.sun.syndication.feed.synd.SyndEntry;
-import com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.fetcher.FeedFetcher;
-import com.sun.syndication.fetcher.impl.FeedFetcherCache;
-import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
-import com.sun.syndication.fetcher.impl.SyndFeedInfo;
-import java.io.File;
-import java.net.URL;
-import java.sql.Timestamp;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
+package org.apache.roller.planet.business.datamapper;
+
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
@@ -44,9 +31,8 @@
 import org.apache.roller.planet.pojos.PlanetEntryData;
 import org.apache.roller.planet.pojos.PlanetGroupData;
 import org.apache.roller.planet.pojos.PlanetSubscriptionData;
-import org.apache.roller.planet.util.rome.DiskFeedInfoCache;
-import org.apache.roller.business.datamapper.DatamapperQuery;
 import org.apache.roller.business.datamapper.DatamapperPersistenceStrategy;
+import org.apache.roller.business.datamapper.DatamapperQuery;
 import org.apache.roller.planet.business.AbstractManagerImpl;
 
 
@@ -55,13 +41,13 @@
  * 
  * @author Dave Johnson
  */
-public class DatamapperPlanetManagerImpl extends AbstractManagerImpl implements PlanetManager {
+public abstract class DatamapperPlanetManagerImpl extends AbstractManagerImpl implements PlanetManager {
 
     private static Log log = LogFactory.getLog(
         DatamapperPlanetManagerImpl.class);
 
     /** The strategy for this manager. */
-    private DatamapperPersistenceStrategy strategy;
+    protected DatamapperPersistenceStrategy strategy;
 
     protected Map lastUpdatedByGroup = new HashMap();
     protected static final String NO_GROUP = "zzz_nogroup_zzz";
@@ -119,16 +105,6 @@
                 PlanetSubscriptionData.class, id);
     }
 
-    public Iterator getAllSubscriptions() {
-        try {
-            return ((List)strategy.newQuery(PlanetSubscriptionData.class, 
-                    "PlanetSubscriptionData.getAll").execute()).iterator(); 
-        } catch (Throwable e) {
-            throw new RuntimeException(
-                    "ERROR fetching subscription collection", e);
-        }
-    }
-
     public int getSubscriptionCount() throws RollerException {
         return ((List)strategy.newQuery(PlanetSubscriptionData.class, 
                 "PlanetSubscriptionData.getAll").execute()).size(); 
@@ -138,21 +114,19 @@
             throws RollerException {
         return getTopSubscriptions(null, offset, length);
     }
-    
+        
     /**
      * Get top X subscriptions, restricted by group.
      */
     public List getTopSubscriptions(
-            String groupHandle, int offset, int len) throws RollerException {
+            PlanetGroupData group, int offset, int len) throws RollerException {
         List result = null;
-        if (groupHandle != null) {
+        if (group != null) {
             result = (List) strategy.newQuery(PlanetSubscriptionData.class,
-                "PlanetSubscriptionData.getByGroupHandleOrderByInboundBlogsDesc")
-            .execute(groupHandle);
+                "PlanetSubscriptionData.getByGroupOrderByInboundBlogsDesc").execute(group);
         } else {
             result = (List) strategy.newQuery(PlanetSubscriptionData.class,
-                "PlanetSubscriptionData.getAllOrderByInboundBlogsDesc")
-                .execute();
+                "PlanetSubscriptionData.getAllOrderByInboundBlogsDesc").execute();
         }
         // TODO handle offset and length
         return result;
@@ -171,307 +145,6 @@
         return (PlanetGroupData) strategy.load(PlanetGroupData.class, id);
     }
 
-    public List getGroups() throws RollerException {
-        return (List) strategy.newQuery(PlanetGroupData.class, 
-            "PlanetGroupData.getAll").execute(); 
-    }
-
-    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;
-    }
-
-    /**
-     * Get entries in a single feed as list of PlanetEntryData objects.
-     */
-    public List getFeedEntries(
-            String feedUrl, int offset, int len) throws RollerException {      
-        List result = (List) strategy.newQuery(PlanetEntryData.class, 
-                "PlanetEntryData.getByFeedURL").execute(feedUrl); 
-        // TODO handle offset and length
-        return result;
-    }
-
-    public List getAggregation(
-            int offset, int len) throws RollerException {
-        return getAggregation(null, null, null, offset, len);
-    }
-    
-    /**
-     * Get agggration from cache, enries in reverse chonological order.
-     * @param offset    Offset into results (for paging)
-     * @param len       Maximum number of results to return (for paging)
-     */
-    public List getAggregation(Date startDate, Date endDate,
-            int offset, int len) throws RollerException {
-        return getAggregation(null, startDate, endDate, offset, len);
-    }
-    
-    public List getAggregation(
-            PlanetGroupData group, int offset, int len) 
-            throws RollerException {
-        return getAggregation(group, null, null, offset, len);
-    }
-    
-    /**
-     * Get agggration for group from cache, enries in reverse chonological order.
-     * Respects category constraints of group.
-     * @param group Restrict to entries from one subscription group.
-     * @param offset    Offset into results (for paging)
-     * @param length    Maximum number of results to return (for paging)
-     */
-    public List getAggregation(
-            PlanetGroupData group, Date startDate, Date endDate,
-            int offset, int length) throws RollerException {
-        List result = null;
-        if (endDate == null) endDate = new Date();
-        try {
-            String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
-            long startTime = System.currentTimeMillis();
-            DatamapperQuery query;
-            Object[] params;
-            if (group != null) {
-                if (startDate != null) {
-                    params = new Object[] {groupHandle, endDate, startDate};
-                    query = strategy.newQuery(PlanetEntryData.class,
-                            "PlanetEntryData.getByGroup&EndDate&StartDateOrderByPubTimeDesc");
-                } else {
-                    params = new Object[] {groupHandle, endDate};
-                    query = strategy.newQuery(PlanetEntryData.class,
-                            "PlanetEntryData.getByGroup&EndDateOrderByPubTimeDesc");
-                }
-                // TODO handle offset and length
-            } else {
-                if (startDate != null) {
-                    params = new Object[] {endDate, startDate};
-                    query = strategy.newQuery(PlanetEntryData.class,
-                            "PlanetEntryData.getByExternalOrInternalGroup&EndDate&StartDateOrderByPubTimeDesc");
-                } else {
-                    params = new Object[] {endDate};
-                    query = strategy.newQuery(PlanetEntryData.class,
-                            "PlanetEntryData.getByExternalOrInternalGroup&EndDateOrderByPubTimeDesc");
-                }
-                // TODO handle offset and length
-            }
-            result = (List) query.execute(params);
-            Date retLastUpdated;
-            if (result.size() > 0) {
-                PlanetEntryData entry = (PlanetEntryData)result.get(0);
-                retLastUpdated = entry.getPubTime();
-            } else {
-                retLastUpdated = new Date();
-            }
-            lastUpdatedByGroup.put(groupHandle, retLastUpdated);
-            
-            long endTime = System.currentTimeMillis();
-            log.debug("Generated aggregation in "
-                    + ((endTime-startTime)/1000.0) + " seconds");
-            
-        } catch (Throwable e) {
-            log.error("ERROR: building aggregation for: " + group, e);
-            throw new RollerException(e);
-        }
-        return result;
-    }
-    
-    public synchronized void clearCachedAggregations() {
-        lastUpdatedByGroup.clear();
-    }
-                                                                                        
-    public Date getLastUpdated() {
-        return (Date) lastUpdatedByGroup.get(NO_GROUP);
-    }
-
-    public Date getLastUpdated(PlanetGroupData group) {
-        return (Date) lastUpdatedByGroup.get(group);
-    }
-
-    public void refreshEntries(String cacheDirPath) throws RollerException {
-        
-        Date now = new Date();
-        long startTime = System.currentTimeMillis();
-        
-        // can't continue without cache dir
-        if (cacheDirPath == null) {
-            log.warn("Planet cache directory not set, aborting refresh");
-            return;
-        }
-        
-        // allow ${user.home} in cache dir property
-        String cacheDirName = cacheDirPath.replaceFirst(
-                "\\$\\{user.home}",System.getProperty("user.home"));
-        
-        // allow ${catalina.home} in cache dir property
-        if (System.getProperty("catalina.home") != null) {
-            cacheDirName = cacheDirName.replaceFirst(
-                "\\$\\{catalina.home}",System.getProperty("catalina.home"));
-        }
-        
-        // create cache  dir if it does not exist
-        File cacheDir = null;
-        try {
-            cacheDir = new File(cacheDirName);
-            if (!cacheDir.exists()) cacheDir.mkdirs();
-        } catch (Exception e) {
-            log.error("Unable to create planet cache directory");
-            return;
-        }
-        
-        // abort if cache dir is not writable
-        if (!cacheDir.canWrite()) {
-            log.error("Planet cache directory is not writable");
-            return;
-        }
-        
-        FeedFetcherCache feedInfoCache =
-                new DiskFeedInfoCache(cacheDirName);
-        
-        /*if (config.getProxyHost()!=null && config.getProxyPort() > 0) {
-            System.setProperty("proxySet", "true");
-            System.setProperty("http.proxyHost", config.getProxyHost());
-            System.setProperty("http.proxyPort",
-                    Integer.toString(config.getProxyPort()));
-        }*/
-        
-        /** a hack to set 15 sec timeouts for java.net.HttpURLConnection */
-        System.setProperty("sun.net.client.defaultConnectTimeout", "15000");
-        System.setProperty("sun.net.client.defaultReadTimeout", "15000");
-        
-        FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
-        //FeedFetcher feedFetcher = new HttpClientFeedFetcher(feedInfoCache);
-        feedFetcher.setUsingDeltaEncoding(false);
-        feedFetcher.setUserAgent("RollerPlanetAggregator");
-        
-        // Loop through all subscriptions in the system
-        Iterator subs = getAllSubscriptions();
-        while (subs.hasNext()) {
-            
-            long subStartTime = System.currentTimeMillis();
-            
-            PlanetSubscriptionData sub = (PlanetSubscriptionData)subs.next();
-            
-            // reattach sub.  sub gets detached as we iterate
-            sub = this.getSubscriptionById(sub.getId());
-            
-            Set newEntries = this.getNewEntries(sub, feedFetcher, feedInfoCache);
-            int count = newEntries.size();
-            
-            log.debug("   Entry count: " + count);
-            if (count > 0) {
-                this.deleteEntries(sub);
-                sub.addEntries(newEntries);
-                this.saveSubscription(sub);
-                this.strategy.flush();
-            }
-            long subEndTime = System.currentTimeMillis();
-            log.info("   " + count + " - "
-                    + ((subEndTime-subStartTime)/1000.0)
-                    + " seconds to process (" + count + ") entries of "
-                    + sub.getFeedURL());
-        }
-        // Clear the aggregation cache
-        clearCachedAggregations();
-        
-        long endTime = System.currentTimeMillis();
-        log.info("--- DONE --- Refreshed entries in "
-                + ((endTime-startTime)/1000.0) + " seconds");
-    }
-        
-    protected Set getNewEntries(PlanetSubscriptionData sub,
-                                FeedFetcher feedFetcher,
-                                FeedFetcherCache feedInfoCache)
-            throws RollerException {
-
-        Set newEntries = new TreeSet();
-        SyndFeed feed = null;
-        URL feedURL = null;
-        Date lastUpdated = new Date();
-        try {
-            feedURL = new URL(sub.getFeedURL());
-            log.debug("Get feed from cache "+sub.getFeedURL());
-            feed = feedFetcher.retrieveFeed(feedURL);
-            SyndFeedInfo feedInfo = feedInfoCache.getFeedInfo(feedURL);
-            if (feedInfo.getLastModified() != null) {
-                long lastUpdatedLong =
-                        ((Long)feedInfo.getLastModified()).longValue();
-                if (lastUpdatedLong != 0) {
-                    lastUpdated = new Date(lastUpdatedLong);
-                }
-            }
-            Thread.sleep(100); // be nice
-        } catch (Exception e) {
-            log.warn("ERROR parsing " + sub.getFeedURL()
-            + " : " + e.getClass().getName() + " : " + e.getMessage());
-            log.debug(e);
-            return newEntries; // bail out
-        }
-        if (lastUpdated!=null && sub.getLastUpdated()!=null) {
-            Calendar feedCal = Calendar.getInstance();
-            feedCal.setTime(lastUpdated);
-
-            Calendar subCal = Calendar.getInstance();
-            subCal.setTime(sub.getLastUpdated());
-
-            if (!feedCal.after(subCal)) {
-                if (log.isDebugEnabled()) {
-                    String msg = MessageFormat.format(
-                            "   Skipping ({0} / {1})",
-                            new Object[] {
-                        lastUpdated, sub.getLastUpdated()});
-                    log.debug(msg);
-                }
-                return newEntries; // bail out
-            }
-        }
-        if (feed.getPublishedDate() != null) {
-            sub.setLastUpdated(feed.getPublishedDate());
-            // saving sub here causes detachment issues, so we save it later
-        }
-
-        // Horrible kludge for Feeds without entry dates: most recent entry is
-        // given feed's last publish date (or yesterday if none exists) and
-        // earler entries are placed at once day intervals before that.
-        Calendar cal = Calendar.getInstance();
-        if (sub.getLastUpdated() != null) {
-            cal.setTime(sub.getLastUpdated());
-        } else {
-            cal.setTime(new Date());
-            cal.add(Calendar.DATE, -1);
-        }
-
-        // Populate subscription object with new entries
-        Iterator entries = feed.getEntries().iterator();
-        while (entries.hasNext()) {
-            try {
-                SyndEntry romeEntry = (SyndEntry) entries.next();
-                PlanetEntryData entry =
-                        new PlanetEntryData(feed, romeEntry, sub);
-                log.debug("Entry title=" + entry.getTitle() + " content size=" + entry.getContent().length());
-                if (entry.getPubTime() == null) {
-                    log.debug("No published date, assigning fake date for "+feedURL);
-                    entry.setPubTime(new Timestamp(cal.getTimeInMillis()));
-                }
-                if (entry.getPermalink() == null) {
-                    log.warn("No permalink, rejecting entry from "+feedURL);
-                } else {
-                    newEntries.add(entry);
-                }
-                cal.add(Calendar.DATE, -1);
-            } catch (Exception e) {
-                log.error("ERROR processing subscription entry", e);
-            }
-        }
-        return newEntries;
-    }
-
-    public void release() {}
-    
-
     public void savePlanet(PlanetData planet) throws RollerException {
         strategy.store(planet);
     }
@@ -494,21 +167,6 @@
             "PlanetData.getAll").execute(); 
     }
 
-    public List getGroupHandles(PlanetData planet) throws RollerException { 
-        List handles = new ArrayList();
-        Iterator list = getGroups(planet).iterator();
-        while (list.hasNext()) {
-            PlanetGroupData group = (PlanetGroupData) list.next();
-            handles.add(group.getHandle());
-        }
-        return handles;
-    }
-
-    public List getGroups(PlanetData planet) throws RollerException {
-       return (List)strategy.newQuery(PlanetGroupData.class, 
-            "PlanetGroupData.getByPlanet").execute(planet.getHandle()); 
-    }
-
     public PlanetGroupData getGroup(PlanetData planet, String handle) throws RollerException {
         List results = (List) strategy.newQuery(PlanetData.class, 
             "PlanetGroupData.getByPlanetAndHandle").execute(new Object[] {planet.getHandle(), handle}); 
@@ -531,6 +189,33 @@
         
         // make sure and clear the other side of the assocation
         sub.getEntries().clear();
+    }        
+
+    public List getSubscriptions() throws RollerException {
+        return (List)strategy.newQuery(PlanetSubscriptionData.class, 
+            "PlanetSubscriptionData.getAllOrderByFeedURL").execute(); 
+    }
+
+    public PlanetEntryData getEntryById(String id) throws RollerException {
+        return (PlanetEntryData) strategy.load(PlanetEntryData.class, id);
     }
+
+    public List getEntries(PlanetSubscriptionData sub, int offset, int len) throws RollerException {            
+        if(sub == null) {
+            throw new RollerException("subscription cannot be null");
+        }
+        boolean setRange = offset != 0 || len != -1;
+        if (len == -1) {
+            len = Integer.MAX_VALUE - offset;
+        }
+        DatamapperQuery q = strategy.newQuery(PlanetData.class, "PlanetEntryData.getBySubscription");
+        if (setRange) q.setRange(offset, offset + len);
+        return (List)q.execute(new Object[] {sub});
+    }
+
+    public List getEntries(PlanetGroupData group, int offset, int len) throws RollerException {
+        return getEntries(group, null, null, offset, len);
+    }
+
 }
 

Modified: incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetImpl.java?view=diff&rev=519104&r1=519103&r2=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetImpl.java (original)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetImpl.java Fri Mar 16 12:09:54 2007
@@ -21,10 +21,9 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.RollerException;
-import org.apache.roller.planet.business.PropertiesManager;
+import org.apache.roller.planet.business.FeedFetcher;
 import org.apache.roller.planet.business.URLStrategy;
 import org.apache.roller.planet.business.datamapper.DatamapperPlanetImpl;
-import org.apache.roller.planet.business.datamapper.DatamapperPlanetManagerImpl;
 import org.apache.roller.planet.business.Planet;
 import org.apache.roller.planet.business.PlanetManager;
 import org.apache.roller.business.datamapper.jpa.JPAPersistenceStrategy;
@@ -47,13 +46,14 @@
     // url strategy
     protected URLStrategy urlStrategy = null;
     
-        
+    // feed fetcher
+    protected FeedFetcher feedFetcher = null;
+    
     protected JPAPlanetImpl() throws RollerException {
         // set strategy used by Datamapper
         strategy = new JPAPersistenceStrategy("PlanetPU");
     }
     
-    
     /**
      * Instantiates and returns an instance of JPAPlanetImpl.
      */
@@ -73,5 +73,14 @@
     public void setURLStrategy(URLStrategy urlStrategy) {
         this.urlStrategy = urlStrategy;
         log.info("Using URLStrategy: " + urlStrategy.getClass().getName());
+    }
+
+    public FeedFetcher getFeedFetcher() {
+        return this.feedFetcher;
+    }
+    
+    public void setFeedFetcher(FeedFetcher feedFetcher) {
+        this.feedFetcher = feedFetcher;
+        log.info("Using FeedFetcher: " + feedFetcher.getClass().getName());
     }
 }

Added: incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetManagerImpl.java?view=auto&rev=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetManagerImpl.java (added)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/datamapper/jpa/JPAPlanetManagerImpl.java Fri Mar 16 12:09:54 2007
@@ -0,0 +1,99 @@
+/*
+ * 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.planet.business.datamapper.jpa;
+
+import java.util.ArrayList;
+import java.util.Date;
+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.business.datamapper.DatamapperPersistenceStrategy;
+import org.apache.roller.business.datamapper.jpa.JPADynamicQueryImpl;
+import org.apache.roller.business.datamapper.jpa.JPAPersistenceStrategy;
+import org.apache.roller.planet.business.datamapper.DatamapperPlanetManagerImpl;
+import org.apache.roller.planet.pojos.PlanetGroupData;
+
+/**
+ * Methods that need to go straight-to-JPA.
+ */
+public class JPAPlanetManagerImpl extends DatamapperPlanetManagerImpl {
+    
+    private static Log log = LogFactory.getLog(
+        JPAPlanetManagerImpl.class);
+    
+    public JPAPlanetManagerImpl(DatamapperPersistenceStrategy strategy) {
+        super(strategy);
+    }
+    
+    public List getEntries(PlanetGroupData group, Date startDate, Date endDate, int offset, int len) throws RollerException {
+        StringBuffer queryString = new StringBuffer();
+                
+        if(group == null) {
+            throw new RollerException("group cannot be null");
+        }
+        
+        List ret = null;
+        try {
+            long startTime = System.currentTimeMillis();
+            
+            StringBuffer sb = new StringBuffer();
+            List params = new ArrayList();
+            int size = 0;
+            sb.append("SELECT e FROM PlanetEntryData e ");
+            sb.append("JOIN e.subscription.groups g ");
+            params.add(size++, group);
+            sb.append("WHERE g = ?").append(size);
+            if (startDate != null) {
+                params.add(size++, startDate);
+                sb.append("AND e.pubTime > ?").append(size);
+            }
+            if (endDate != null) {
+                params.add(size++, endDate);
+                sb.append("AND e.pubTime < :?").append(size);
+            }
+            sb.append("ORDER BY e.pubTime DESC");
+            
+            JPADynamicQueryImpl query = (JPADynamicQueryImpl)
+                ((JPAPersistenceStrategy) strategy)
+                .newDynamicQuery(queryString.toString());
+
+            if (offset != 0 || len != -1) {
+                if (len == -1) {
+                    len = Integer.MAX_VALUE - offset;
+                }
+                query.setRange(offset, len);
+            }
+            
+            ret = (List) query.execute(params.toArray());
+            
+            long endTime = System.currentTimeMillis();
+            
+            log.debug("Generated aggregation in "
+                    +((endTime-startTime)/1000.0)+" seconds");
+            
+            return ret;
+            
+        } catch (Throwable e) {
+            throw new RollerException(e);
+        }
+               
+    }
+    
+}

Modified: incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java?view=diff&rev=519104&r1=519103&r2=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java (original)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetImpl.java Fri Mar 16 12:09:54 2007
@@ -33,6 +33,7 @@
 import org.apache.roller.planet.business.PlanetManager;
 import org.apache.roller.planet.config.PlanetConfig;
 import org.apache.roller.business.jpa.JPAPersistenceStrategy;
+import org.apache.roller.planet.business.FeedFetcher;
 import org.apache.roller.planet.business.PropertiesManager;
 
 
@@ -57,6 +58,9 @@
     // url strategy
     protected URLStrategy urlStrategy = null;
     
+    // feed fetcher
+    protected FeedFetcher feedFetcher = null;
+    
         
     protected JPAPlanetImpl() throws RollerException {
         
@@ -181,6 +185,15 @@
             JPAPersistenceStrategy strategy) {
         return new JPAPropertiesManagerImpl(strategy);
     } 
+    
+    public FeedFetcher getFeedFetcher() {
+        return this.feedFetcher;
+    }
+    
+    public void setFeedFetcher(FeedFetcher feedFetcher) {
+        this.feedFetcher = feedFetcher;
+        log.info("Using FeedFetcher: " + feedFetcher.getClass().getName());
+    }
     
     /**
      * Loads properties from given resourceName using given class loader

Modified: incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java?view=diff&rev=519104&r1=519103&r2=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java (original)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/business/jpa/JPAPlanetManagerImpl.java Fri Mar 16 12:09:54 2007
@@ -149,19 +149,22 @@
      * Get top X subscriptions, restricted by group.
      */
     public List getTopSubscriptions(
-            String groupHandle, int offset, int len) throws RollerException {
+            PlanetGroupData group, int offset, int len) throws RollerException {
         List result = null;
-        if (groupHandle != null) {
+        if (group != null) {
             Query q = strategy.getNamedQuery(
-                    "PlanetSubscriptionData.getByGroupHandleOrderByInboundBlogsDesc");
-            q.setParameter(1, groupHandle);
+                    "PlanetSubscriptionData.getByGroupOrderByInboundBlogsDesc");
+            q.setParameter(1, group);
+            if (offset != 0) q.setFirstResult(offset);
+            if (len != -1) q.setMaxResults(len);
             result = q.getResultList();
         } else {
             Query q = strategy.getNamedQuery(
                     "PlanetSubscriptionData.getAllOrderByInboundBlogsDesc");
+            if (offset != 0) q.setFirstResult(offset);
+            if (len != -1) q.setMaxResults(len);
             result = q.getResultList();
         }
-        // TODO handle offset and length
         return result;
     }
     
@@ -177,310 +180,7 @@
     
     public PlanetGroupData getGroupById(String id) throws RollerException {
         return (PlanetGroupData) strategy.load(PlanetGroupData.class, id);
-    }
-    
-    public List getGroups() throws RollerException {
-        return strategy.getNamedQuery(
-                "PlanetGroupData.getAll").getResultList();
-    }
-    
-    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;
-    }
-    
-    /**
-     * Get entries in a single feed as list of PlanetEntryData objects.
-     */
-    public List getFeedEntries(
-            String feedUrl, int offset, int len) throws RollerException {
-        Query q = strategy.getNamedQuery("PlanetEntryData.getByFeedURL");
-        q.setParameter(1, feedUrl);
-        q.setFirstResult(offset);
-        if (len != -1) q.setMaxResults(len);
-        return q.getResultList();
-    }
-    
-    public List getAggregation(
-            int offset, int len) throws RollerException {
-        return getAggregation(null, null, null, offset, len);
-    }
-    
-    /**
-     * Get agggration from cache, enries in reverse chonological order.
-     * @param offset    Offset into results (for paging)
-     * @param len       Maximum number of results to return (for paging)
-     */
-    public List getAggregation(Date startDate, Date endDate,
-            int offset, int len) throws RollerException {
-        return getAggregation(null, startDate, endDate, offset, len);
-    }
-    
-    public List getAggregation(
-            PlanetGroupData group, int offset, int len)
-            throws RollerException {
-        return getAggregation(group, null, null, offset, len);
-    }
-    
-    /**
-     * Get agggration for group from cache, enries in reverse chonological order.
-     * Respects category constraints of group.
-     * @param group Restrict to entries from one subscription group.
-     * @param offset    Offset into results (for paging)
-     * @param length    Maximum number of results to return (for paging)
-     */
-    public List getAggregation(
-            PlanetGroupData group, Date startDate, Date endDate,
-            int offset, int length) throws RollerException {
-        List result = null;
-        if (endDate == null) endDate = new Date();
-        try {
-            String groupHandle = (group == null) ? NO_GROUP : group.getHandle();
-            long startTime = System.currentTimeMillis();
-            Query query;
-            Object[] params;
-            if (group != null) {
-                if (startDate != null) {
-                    params = new Object[] {groupHandle, endDate, startDate};
-                    query = strategy.getNamedQuery(
-                            "PlanetEntryData.getByGroup&EndDate&StartDateOrderByPubTimeDesc");
-                } else {
-                    params = new Object[] {groupHandle, endDate};
-                    query = strategy.getNamedQuery(
-                            "PlanetEntryData.getByGroup&EndDateOrderByPubTimeDesc");
-                }
-            } else {
-                if (startDate != null) {
-                    params = new Object[] {endDate, startDate};
-                    query = strategy.getNamedQuery(
-                            "PlanetEntryData.getByExternalOrInternalGroup&EndDate&StartDateOrderByPubTimeDesc");
-                } else {
-                    params = new Object[] {endDate};
-                    query = strategy.getNamedQuery(
-                            "PlanetEntryData.getByExternalOrInternalGroup&EndDateOrderByPubTimeDesc");
-                }
-            }
-            query.setFirstResult(offset);
-            if (length != -1) query.setMaxResults(length);
-            for (int i=0; i<params.length; i++) {
-                query.setParameter(i, params[i]);
-            }
-            result = query.getResultList();
-            Date retLastUpdated;
-            if (result.size() > 0) {
-                PlanetEntryData entry = (PlanetEntryData)result.get(0);
-                retLastUpdated = entry.getPubTime();
-            } else {
-                retLastUpdated = new Date();
-            }
-            lastUpdatedByGroup.put(groupHandle, retLastUpdated);
-            
-            long endTime = System.currentTimeMillis();
-            log.debug("Generated aggregation in "
-                    + ((endTime-startTime)/1000.0) + " seconds");
-            
-        } catch (Throwable e) {
-            log.error("ERROR: building aggregation for: " + group, e);
-            throw new RollerException(e);
-        }
-        return result;
-    }
-    
-    public synchronized void clearCachedAggregations() {
-        lastUpdatedByGroup.clear();
-    }
-    
-    public Date getLastUpdated() {
-        return (Date) lastUpdatedByGroup.get(NO_GROUP);
-    }
-    
-    public Date getLastUpdated(PlanetGroupData group) {
-        return (Date) lastUpdatedByGroup.get(group);
-    }
-    
-    public void refreshEntries(String cacheDirPath) throws RollerException {
-        
-        Date now = new Date();
-        long startTime = System.currentTimeMillis();
-        
-        // can't continue without cache dir
-        if (cacheDirPath == null) {
-            log.warn("Planet cache directory not set, aborting refresh");
-            return;
-        }
-        
-        // allow ${user.home} in cache dir property
-        String cacheDirName = cacheDirPath.replaceFirst(
-                "\\$\\{user.home}",System.getProperty("user.home"));
-        
-        // allow ${catalina.home} in cache dir property
-        if (System.getProperty("catalina.home") != null) {
-            cacheDirName = cacheDirName.replaceFirst(
-                    "\\$\\{catalina.home}",System.getProperty("catalina.home"));
-        }
-        
-        // create cache  dir if it does not exist
-        File cacheDir = null;
-        try {
-            cacheDir = new File(cacheDirName);
-            if (!cacheDir.exists()) cacheDir.mkdirs();
-        } catch (Exception e) {
-            log.error("Unable to create planet cache directory");
-            return;
-        }
-        
-        // abort if cache dir is not writable
-        if (!cacheDir.canWrite()) {
-            log.error("Planet cache directory is not writable");
-            return;
-        }
-        
-        FeedFetcherCache feedInfoCache =
-                new DiskFeedInfoCache(cacheDirName);
-        
-        String proxyHost = PlanetRuntimeConfig.getProperty("site.proxyhost");
-        int proxyPort = PlanetRuntimeConfig.getIntProperty("site.proxyport");
-        if (proxyHost != null && proxyPort > 0) {
-            System.setProperty("proxySet", "true");
-            System.setProperty("http.proxyHost", proxyHost);
-            System.setProperty("http.proxyPort", Integer.toString(proxyPort));
-        }
-        
-        /** a hack to set 15 sec timeouts for java.net.HttpURLConnection */
-        System.setProperty("sun.net.client.defaultConnectTimeout", "15000");
-        System.setProperty("sun.net.client.defaultReadTimeout", "15000");
-        
-        FeedFetcher feedFetcher = new HttpURLFeedFetcher(feedInfoCache);
-        //FeedFetcher feedFetcher = new HttpClientFeedFetcher(feedInfoCache);
-        feedFetcher.setUsingDeltaEncoding(false);
-        feedFetcher.setUserAgent("RollerPlanetAggregator");
-        
-        // Loop through all subscriptions in the system
-        Iterator subs = getAllSubscriptions();
-        while (subs.hasNext()) {
-            
-            long subStartTime = System.currentTimeMillis();
-            
-            PlanetSubscriptionData sub = (PlanetSubscriptionData)subs.next();
-            
-            // reattach sub.  sub gets detached as we iterate
-            sub = this.getSubscriptionById(sub.getId());
-            
-            Set newEntries = this.getNewEntries(sub, feedFetcher, feedInfoCache);
-            int count = newEntries.size();
-            
-            log.debug("   Entry count: " + count);
-            if (count > 0) {
-                this.deleteEntries(sub);
-                sub.addEntries(newEntries);
-                this.saveSubscription(sub);
-                this.strategy.flush();
-            }
-            long subEndTime = System.currentTimeMillis();
-            log.info("   " + count + " - "
-                    + ((subEndTime-subStartTime)/1000.0)
-                    + " seconds to process (" + count + ") entries of "
-                    + sub.getFeedURL());
-        }
-        // Clear the aggregation cache
-        clearCachedAggregations();
-        
-        long endTime = System.currentTimeMillis();
-        log.info("--- DONE --- Refreshed entries in "
-                + ((endTime-startTime)/1000.0) + " seconds");
-    }
-    
-    protected Set getNewEntries(PlanetSubscriptionData sub,
-            FeedFetcher feedFetcher,
-            FeedFetcherCache feedInfoCache)
-            throws RollerException {
-        
-        Set newEntries = new TreeSet();
-        SyndFeed feed = null;
-        URL feedURL = null;
-        Date lastUpdated = new Date();
-        try {
-            feedURL = new URL(sub.getFeedURL());
-            log.debug("Get feed from cache "+sub.getFeedURL());
-            feed = feedFetcher.retrieveFeed(feedURL);
-            SyndFeedInfo feedInfo = feedInfoCache.getFeedInfo(feedURL);
-            if (feedInfo.getLastModified() != null) {
-                long lastUpdatedLong =
-                        ((Long)feedInfo.getLastModified()).longValue();
-                if (lastUpdatedLong != 0) {
-                    lastUpdated = new Date(lastUpdatedLong);
-                }
-            }
-            Thread.sleep(100); // be nice
-        } catch (Exception e) {
-            log.warn("ERROR parsing " + sub.getFeedURL()
-            + " : " + e.getClass().getName() + " : " + e.getMessage());
-            log.debug(e);
-            return newEntries; // bail out
-        }
-        if (lastUpdated!=null && sub.getLastUpdated()!=null) {
-            Calendar feedCal = Calendar.getInstance();
-            feedCal.setTime(lastUpdated);
-            
-            Calendar subCal = Calendar.getInstance();
-            subCal.setTime(sub.getLastUpdated());
-            
-            if (!feedCal.after(subCal)) {
-                if (log.isDebugEnabled()) {
-                    String msg = MessageFormat.format(
-                            "   Skipping ({0} / {1})",
-                            new Object[] {
-                        lastUpdated, sub.getLastUpdated()});
-                    log.debug(msg);
-                }
-                return newEntries; // bail out
-            }
-        }
-        if (feed.getPublishedDate() != null) {
-            sub.setLastUpdated(feed.getPublishedDate());
-            // saving sub here causes detachment issues, so we save it later
-        }
-        
-        // Horrible kludge for Feeds without entry dates: most recent entry is
-        // given feed's last publish date (or yesterday if none exists) and
-        // earler entries are placed at once day intervals before that.
-        Calendar cal = Calendar.getInstance();
-        if (sub.getLastUpdated() != null) {
-            cal.setTime(sub.getLastUpdated());
-        } else {
-            cal.setTime(new Date());
-            cal.add(Calendar.DATE, -1);
-        }
-        
-        // Populate subscription object with new entries
-        Iterator entries = feed.getEntries().iterator();
-        while (entries.hasNext()) {
-            try {
-                SyndEntry romeEntry = (SyndEntry) entries.next();
-                PlanetEntryData entry =
-                        new PlanetEntryData(feed, romeEntry, sub);
-                log.debug("Entry title=" + entry.getTitle() + " content size=" + entry.getContent().length());
-                if (entry.getPubTime() == null) {
-                    log.debug("No published date, assigning fake date for "+feedURL);
-                    entry.setPubTime(new Timestamp(cal.getTimeInMillis()));
-                }
-                if (entry.getPermalink() == null) {
-                    log.warn("No permalink, rejecting entry from "+feedURL);
-                } else {
-                    newEntries.add(entry);
-                }
-                cal.add(Calendar.DATE, -1);
-            } catch (Exception e) {
-                log.error("ERROR processing subscription entry", e);
-            }
-        }
-        return newEntries;
-    }
+    }        
     
     public void release() {}
     
@@ -548,5 +248,86 @@
         // make sure and clear the other side of the assocation
         sub.getEntries().clear();
     }
+    
+    public List getSubscriptions() throws RollerException {
+        Query q = strategy.getNamedQuery("PlanetSubscriptionData.getAllOrderByFeedURL");
+        return q.getResultList();
+    }
+
+    public PlanetEntryData getEntryById(String id) throws RollerException {
+        return (PlanetEntryData) strategy.load(PlanetEntryData.class, id);
+    }
+
+    public List getEntries(PlanetSubscriptionData sub, int offset, int len) throws RollerException {            
+        if(sub == null) {
+            throw new RollerException("subscription cannot be null");
+        }
+        Query q = strategy.getNamedQuery("PlanetEntryData.getBySubscription");
+        q.setParameter(1, sub);
+        if (offset != 0) q.setFirstResult(offset);
+        if (len != -1) q.setMaxResults(len);
+        return q.getResultList();
+    }
+
+    public List getEntries(PlanetGroupData group, int offset, int len) throws RollerException {
+        return getEntries(group, null, null, offset, len);
+    }
+
+    public List getEntries(PlanetGroupData group, Date startDate, Date endDate, int offset, int len) throws RollerException {
+        StringBuffer queryString = new StringBuffer();
+                
+        if(group == null) {
+            throw new RollerException("group cannot be null");
+        }
+        
+        List ret = null;
+        try {
+            long startTime = System.currentTimeMillis();
+            
+            StringBuffer sb = new StringBuffer();
+            List params = new ArrayList();
+            int size = 0;
+            sb.append("SELECT e FROM PlanetEntryData e ");
+            sb.append("JOIN e.subscription.groups g ");
+            params.add(size++, group);
+            sb.append("WHERE g = ?").append(size);
+            if (startDate != null) {
+                params.add(size++, startDate);
+                sb.append("AND e.pubTime > ?").append(size);
+            }
+            if (endDate != null) {
+                params.add(size++, endDate);
+                sb.append("AND e.pubTime < :?").append(size);
+            }
+            sb.append("ORDER BY e.pubTime DESC");
+            
+            Query query = strategy.getDynamicQuery(sb.toString());
+            for (int i=0; i<params.size(); i++) {
+                query.setParameter(i+1, params.get(i));
+            }
+            if(offset > 0) {
+                query.setFirstResult(offset);
+            }
+            if (len != -1) {
+                query.setMaxResults(len);
+            }
+            
+            ret = query.getResultList();
+            
+            long endTime = System.currentTimeMillis();
+            
+            log.debug("Generated aggregation in "
+                    +((endTime-startTime)/1000.0)+" seconds");
+            
+        } catch (Throwable e) {
+            throw new RollerException(e);
+        }
+        
+        return ret;
+    }
 }
+
+
+
+
 

Modified: incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetEntryData.orm.xml
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetEntryData.orm.xml?view=diff&rev=519104&r1=519103&r2=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetEntryData.orm.xml (original)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetEntryData.orm.xml Fri Mar 16 12:09:54 2007
@@ -26,20 +26,9 @@
                 ORDER BY p.pubTime DESC
             </query>
         </named-query>
-        <named-query
-                name="PlanetEntryData.getByExternalOrInternalGroup&amp;EndDate&amp;StartDateOrderByPubTimeDesc">
-            <query>SELECT p FROM PlanetEntryData p JOIN p.subscription s JOIN s.groups g
-                WHERE (g.handle = 'external' OR g.handle = 'all')
-                AND p.pubTime &lt; ?2 AND p.pubTime &gt; ?3
-                ORDER BY p.pubTime DESC
-            </query>
-        </named-query>
-        <named-query
-                name="PlanetEntryData.getByExternalOrInternalGroup&amp;EndDateOrderByPubTimeDesc">
-            <query>SELECT p FROM PlanetEntryData p JOIN p.subscription s JOIN s.groups g
-                WHERE (g.handle = 'external' OR g.handle = 'all')
-                AND p.pubTime &lt; ?2
-                ORDER BY p.pubTime DESC
+        <named-query name="PlanetEntryData.getBySubscription">
+            <query>
+                SELECT p FROM PlanetEntryData p WHERE p.subscription = ?1 ORDER BY p.pubTime DESC
             </query>
         </named-query>
         <attributes>

Modified: incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetSubscriptionData.orm.xml
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetSubscriptionData.orm.xml?view=diff&rev=519104&r1=519103&r2=519104
==============================================================================
--- incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetSubscriptionData.orm.xml (original)
+++ incubator/roller/branches/roller_4.0_newbackend/apps/planet/src/java/org/apache/roller/planet/pojos/PlanetSubscriptionData.orm.xml Fri Mar 16 12:09:54 2007
@@ -15,10 +15,13 @@
         <named-query name="PlanetSubscriptionData.getAll">
             <query>SELECT p FROM PlanetSubscriptionData p</query>
         </named-query>
+        <named-query name="PlanetSubscriptionData.getAllOrderByFeedURL">
+            <query>SELECT p FROM PlanetSubscriptionData p ORDER BY p.feedURL DESC</query>
+        </named-query>
         <named-query name="PlanetSubscriptionData.getAllOrderByInboundBlogsDesc">
             <query>SELECT p FROM PlanetSubscriptionData p ORDER BY p.inboundblogs DESC</query>
         </named-query>
-        <named-query name="PlanetSubscriptionData.getByGroupHandleOrderByInboundBlogsDesc">
+        <named-query name="PlanetSubscriptionData.getByGroupOrderByInboundBlogsDesc">
             <query>SELECT p FROM PlanetSubscriptionData p JOIN p.groups g WHERE g.handle = ?1 ORDER
                 BY p.inboundblogs DESC
             </query>



Mime
View raw message