Package net.sourceforge.pebble

Examples of net.sourceforge.pebble.ContentCache


   * @return  a Page instance, or null if the page couldn't be found
   * @throws  StaticPageServiceException if something goes wrong
   */
  public StaticPage getStaticPageById(Blog blog, String pageId) throws StaticPageServiceException {
    StaticPage staticPage;
    ContentCache cache = ContentCache.getInstance();

    try {
      staticPage = cache.getStaticPage(blog, pageId);
      if (staticPage != null) {
        log.debug("Got static page " + pageId+ " from cache");
      } else {
        log.debug("Loading static page " + pageId+ " from disk");

        DAOFactory factory = DAOFactory.getConfiguredFactory();
        StaticPageDAO dao = factory.getStaticPageDAO();
        staticPage = dao.loadStaticPage(blog, pageId);
        if (staticPage != null) {
          staticPage.setPersistent(true);
          cache.putStaticPage(staticPage);
        }
      }
    } catch (PersistenceException pe) {
      throw new StaticPageServiceException(blog, pe);
    }
View Full Code Here


   *
   * @param   staticPage    the StaticPage instance to store
   * @throws  StaticPageServiceException if something goes wrong
   */
  public void putStaticPage(StaticPage staticPage) throws StaticPageServiceException {
    ContentCache cache = ContentCache.getInstance();
    DAOFactory factory = DAOFactory.getConfiguredFactory();
    StaticPageDAO dao = factory.getStaticPageDAO();
    Blog blog = staticPage.getBlog();

    synchronized (blog) {
      try {
        StaticPage sp = getStaticPageById(blog, staticPage.getId());

        if (!staticPage.isPersistent() && sp != null) {
          // the static page is new but one exists with the same ID already
          // - increment the date/ID and try again
          staticPage.setDate(new Date(staticPage.getDate().getTime() + 1));
          putStaticPage(staticPage);
        } else {
          dao.storeStaticPage(staticPage);
          staticPage.setPersistent(true);
          cache.removeStaticPage(staticPage);
        }

        staticPage.getBlog().getSearchIndex().index(staticPage);
        staticPage.getBlog().getStaticPageIndex().index(staticPage);
      } catch (PersistenceException pe) {
View Full Code Here

   *
   * @param staticPage    the StaticPage instance to remove
   * @throws  StaticPageServiceException if something goes wrong
   */
  public void removeStaticPage(StaticPage staticPage) throws StaticPageServiceException {
    ContentCache cache = ContentCache.getInstance();
    DAOFactory factory = DAOFactory.getConfiguredFactory();
    StaticPageDAO dao = factory.getStaticPageDAO();
    Blog blog = staticPage.getBlog();

    try {
      dao.removeStaticPage(staticPage);
      cache.removeStaticPage(staticPage);

      staticPage.getBlog().getSearchIndex().unindex(staticPage);
      staticPage.getBlog().getStaticPageIndex().unindex(staticPage);
    } catch (PersistenceException pe) {
      // remove from the cache so that it's picked up from storage when accessed next
      cache.removeStaticPage(staticPage);

      throw new StaticPageServiceException(staticPage.getBlog(), pe);
    }
  }
View Full Code Here

   * @param blogEntryId   the id of the blog entry
   * @return  a BlogEntry instance, or null if the entry couldn't be found
   */
  public BlogEntry getBlogEntry(Blog blog, String blogEntryId) throws BlogServiceException {
    BlogEntry blogEntry = null;
    ContentCache cache = ContentCache.getInstance();

    // is the blog entry already in the cache?                                                 
    blogEntry = cache.getBlogEntry(blog, blogEntryId);
    if (blogEntry != null) {
      log.debug("Got blog entry " + blogEntryId + " from cache");
    } else {
      log.debug("Loading blog entry " + blogEntryId + " from disk");
      BlogEntryDAO dao = DAOFactory.getConfiguredFactory().getBlogEntryDAO();
      try {
        blogEntry = dao.loadBlogEntry(blog, blogEntryId);

        if (blogEntry != null) {
          // place in the cache for faster lookup next time
          cache.putBlogEntry(blogEntry);
        }
      } catch (PersistenceException pe) {
        throw new BlogServiceException(blog, pe);
      }
    }
View Full Code Here

   */
  public void putBlogEntry(BlogEntry blogEntry) throws BlogServiceException {
    DAOFactory factory = DAOFactory.getConfiguredFactory();
    BlogEntryDAO dao = factory.getBlogEntryDAO();
    Blog blog = blogEntry.getBlog();
    ContentCache cache = ContentCache.getInstance();

    synchronized (blog) {
      try {
        BlogEntry be = getBlogEntry(blog, blogEntry.getId());

        if (!blogEntry.isPersistent() && be != null) {
          // the blog entry is new but one exists with the same ID already
          // - increment the date/ID and try again
          blogEntry.setDate(new Date(blogEntry.getDate().getTime() + 1));
          putBlogEntry(blogEntry);
        } else {
          if (!blogEntry.isPersistent()) {
            dao.storeBlogEntry(blogEntry);
            blogEntry.insertEvent(new BlogEntryEvent(blogEntry, BlogEntryEvent.BLOG_ENTRY_ADDED));

            for (Comment comment : blogEntry.getComments()) {
              blogEntry.addEvent(new CommentEvent(comment, CommentEvent.COMMENT_ADDED));
            }
            for (TrackBack trackBack : blogEntry.getTrackBacks()) {
              blogEntry.addEvent(new TrackBackEvent(trackBack, TrackBackEvent.TRACKBACK_ADDED));
            }
          } else {
            dao.storeBlogEntry(blogEntry);
            if (blogEntry.isDirty()) {
              blogEntry.insertEvent(new BlogEntryEvent(blogEntry, blogEntry.getPropertyChangeEvents()));
            }
          }

          blogEntry.getBlog().getEventDispatcher().fireEvents(blogEntry);

          // and store the blog entry now that listeners have been fired
          dao.storeBlogEntry(blogEntry);
          cache.removeBlogEntry(blogEntry);
        }

        blogEntry.setPersistent(true);
      } catch (PersistenceException pe) {
        throw new BlogServiceException(blog, pe);
View Full Code Here

  /**
   * Removes this blog entry.
   */
  public void removeBlogEntry(BlogEntry blogEntry) throws BlogServiceException {
    Blog blog = blogEntry.getBlog();
    ContentCache cache = ContentCache.getInstance();

    try {
      DAOFactory factory = DAOFactory.getConfiguredFactory();
      BlogEntryDAO dao = factory.getBlogEntryDAO();
      dao.removeBlogEntry(blogEntry);
      blogEntry.setPersistent(false);

      // remove from cache
      cache.removeBlogEntry(blogEntry);

      blogEntry.insertEvent(new BlogEntryEvent(blogEntry, BlogEntryEvent.BLOG_ENTRY_REMOVED));

      // and remove all of the responses, so the appropriate events are raised
      // and the responses get unindexed
View Full Code Here

TOP

Related Classes of net.sourceforge.pebble.ContentCache

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.