Package org.apache.roller.weblogger.pojos

Examples of org.apache.roller.weblogger.pojos.WeblogHitCount


        testUser = TestUtils.getManagedUser(testUser);
        Weblog blog1 = TestUtils.setupWeblog("hitCntHotTest1", testUser);
        Weblog blog2 = TestUtils.setupWeblog("hitCntHotTest2", testUser);
        Weblog blog3 = TestUtils.setupWeblog("hitCntHotTest3", testUser);
       
        WeblogHitCount cnt1 = TestUtils.setupHitCount(blog1, 10);
        WeblogHitCount cnt2 = TestUtils.setupHitCount(blog2, 20);
        WeblogHitCount cnt3 = TestUtils.setupHitCount(blog3, 30);
       
        TestUtils.endSession(true);
       
        // make sure data was properly initialized
        WeblogHitCount testCount = null;
        testCount = mgr.getHitCount(cnt1.getId());
        assertEquals(10, testCount.getDailyHits());
        testCount = mgr.getHitCount(cnt2.getId());
        assertEquals(20, testCount.getDailyHits());
        testCount = mgr.getHitCount(cnt3.getId());
        assertEquals(30, testCount.getDailyHits());
       
        // get hot weblogs
        List hotBlogs = mgr.getHotWeblogs(1, 0, 5);
        assertNotNull(hotBlogs);
        assertEquals(3, hotBlogs.size());
       
        // also check ordering and values
        WeblogHitCount hitCount = null;
        Iterator it = hotBlogs.iterator();
        for(int i=3; it.hasNext(); i--) {
            hitCount = (WeblogHitCount) it.next();
           
            assertEquals(i*10, hitCount.getDailyHits());
        }
       
        // cleanup
        TestUtils.teardownHitCount(cnt1.getId());
        TestUtils.teardownHitCount(cnt2.getId());
View Full Code Here


            throw new WebloggerException("Website cannot be NULL.");
        }
       
        Query q = strategy.getNamedQuery("WeblogHitCount.getByWeblog");
        q.setParameter(1, weblog);
        WeblogHitCount hitCount = null;
        try {
            hitCount = (WeblogHitCount)q.getSingleResult();
        } catch (NoResultException e) {
            hitCount = null;
        }
       
        // create it if it doesn't exist
        if(hitCount == null && amount > 0) {
            hitCount = new WeblogHitCount();
            hitCount.setWeblog(weblog);
            hitCount.setDailyHits(amount);
            strategy.store(hitCount);
        } else if(hitCount != null) {
            hitCount.setDailyHits(hitCount.getDailyHits() + amount);
            strategy.store(hitCount);
        }
    }
View Full Code Here

     * @inheritDoc
     */
    public void resetHitCount(Weblog weblog) throws WebloggerException {
        Query q = strategy.getNamedQuery("WeblogHitCount.getByWeblog");
        q.setParameter(1, weblog);
        WeblogHitCount hitCount = null;
        try {
            hitCount = (WeblogHitCount)q.getSingleResult();
            hitCount.setDailyHits(0);
            strategy.store(hitCount);
        } catch (NoResultException e) {
            // ignore: no hit count for weblog
        }      

View Full Code Here

            throws Exception {
       
        WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
       
        // store
        WeblogHitCount testCount = new WeblogHitCount();
        testCount.setWeblog(getManagedWebsite(weblog));
        testCount.setDailyHits(amount);
        mgr.saveHitCount(testCount);
       
        // flush to db
        WebloggerFactory.getWeblogger().flush();
       
        // query for it
        testCount = mgr.getHitCount(testCount.getId());
       
        if(testCount == null)
            throw new WebloggerException("error setting up hit count");
       
        return testCount;
View Full Code Here

     */
    public static void teardownHitCount(String id) throws Exception {
       
        // query for it
        WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
        WeblogHitCount testCount = mgr.getHitCount(id);
       
        // remove
        mgr.removeHitCount(testCount);
       
        // flush to db
View Full Code Here

            WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
            List hotBlogs = mgr.getHotWeblogs(sinceDays, 0, length);
           
            Iterator hitCounts = hotBlogs.iterator();
            while (hitCounts.hasNext()) {
                WeblogHitCount hitCount = (WeblogHitCount) hitCounts.next();
                StatCount statCount = new StatCount(
                    hitCount.getWeblog().getId(),
                    hitCount.getWeblog().getHandle(),
                    hitCount.getWeblog().getName(),
                    "statCount.weblogDayHits",
                    hitCount.getDailyHits());
                statCount.setWeblogHandle(hitCount.getWeblog().getHandle());
                results.add(statCount);             
            }
           
        } catch (Exception e) {
            log.error("ERROR: fetching hot weblog list", e);
View Full Code Here

            throw new WebloggerException("Website cannot be NULL.");
        }
       
        Query q = strategy.getNamedQuery("WeblogHitCount.getByWeblog");
        q.setParameter(1, weblog);
        WeblogHitCount hitCount = null;
        try {
            hitCount = (WeblogHitCount)q.getSingleResult();
        } catch (NoResultException e) {
            hitCount = null;
        }
       
        // create it if it doesn't exist
        if(hitCount == null && amount > 0) {
            hitCount = new WeblogHitCount();
            hitCount.setWeblog(weblog);
            hitCount.setDailyHits(amount);
            strategy.store(hitCount);
        } else if(hitCount != null) {
            hitCount.setDailyHits(hitCount.getDailyHits() + amount);
            strategy.store(hitCount);
        }
    }
View Full Code Here

     * @inheritDoc
     */
    public void resetHitCount(Weblog weblog) throws WebloggerException {
        Query q = strategy.getNamedQuery("WeblogHitCount.getByWeblog");
        q.setParameter(1, weblog);
        WeblogHitCount hitCount = null;
        try {
            hitCount = (WeblogHitCount)q.getSingleResult();
            hitCount.setDailyHits(0);
            strategy.store(hitCount);
        } catch (NoResultException e) {
            // ignore: no hit count for weblog
        }      

View Full Code Here

     */
    public void testHitCountCRUD() throws Exception {
       
        WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
       
        WeblogHitCount testCount = new WeblogHitCount();
        testCount.setWeblog(testWeblog);
        testCount.setDailyHits(10);
       
        // create
        mgr.saveHitCount(testCount);
        String id = testCount.getId();
        TestUtils.endSession(true);
       
        // make sure it was created
        WeblogHitCount hitCount = null;
        hitCount = mgr.getHitCount(id);
        assertNotNull(hitCount);
        assertEquals(testCount, hitCount);
        assertEquals(10, hitCount.getDailyHits());
       
        // update
        hitCount.setDailyHits(25);
        mgr.saveHitCount(hitCount);
        TestUtils.endSession(true);
       
        // make sure it was updated
        hitCount = null;
        hitCount = mgr.getHitCount(id);
        assertNotNull(hitCount);
        assertEquals(testCount, hitCount);
        assertEquals(25, hitCount.getDailyHits());
       
        // delete
        mgr.removeHitCount(hitCount);
        TestUtils.endSession(true);
       
View Full Code Here

    public void testHitCountLookups() throws Exception {
       
        WeblogEntryManager mgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
       
        testWeblog = TestUtils.getManagedWebsite(testWeblog);
        WeblogHitCount testCount = new WeblogHitCount();
        testCount.setWeblog(testWeblog);
        testCount.setDailyHits(10);
       
        // create
        mgr.saveHitCount(testCount);
        String id = testCount.getId();
        TestUtils.endSession(true);
       
        // test lookup by id
        WeblogHitCount hitCount = null;
        hitCount = mgr.getHitCount(id);
        assertNotNull(hitCount);
        assertEquals(testCount, hitCount);
        assertEquals(10, hitCount.getDailyHits());
       
        // test lookup by weblog
        hitCount = null;
        testWeblog = TestUtils.getManagedWebsite(testWeblog);
        hitCount = mgr.getHitCountByWeblog(testWeblog);
        assertNotNull(hitCount);
        assertEquals(testCount, hitCount);
        assertEquals(10, hitCount.getDailyHits());
       
        // delete
        mgr.removeHitCount(hitCount);
        TestUtils.endSession(true);
       
View Full Code Here

TOP

Related Classes of org.apache.roller.weblogger.pojos.WeblogHitCount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.