Class HibernateBlogPostDao

All Implemented Interfaces:
BlogPostDao, org.springframework.beans.factory.InitializingBean

public class HibernateBlogPostDao extends VersionedHibernateObjectDao<BlogPost> implements BlogPostDao
Hibernate implementation of the BlogPost DAO
  • Constructor Details

    • HibernateBlogPostDao

      public HibernateBlogPostDao()
  • Method Details

    • getPersistentClass

      public Class<BlogPost> getPersistentClass()
      Specified by:
      getPersistentClass in class HibernateObjectDao<BlogPost>
    • getById

      public BlogPost getById(long id)
      Description copied from interface: BlogPostDao
      Get a blog post by id. Will return null if the post does not exist
      Specified by:
      getById in interface BlogPostDao
    • getByClassId

      protected BlogPost getByClassId(long id)
      Description copied from class: HibernateObjectDao
      Retrieve the object with a particular id from the database. The object must be of the same class as the DAO's getPersistentClass() method returns.
      Overrides:
      getByClassId in class HibernateObjectDao<BlogPost>
      Parameters:
      id - the id of the object to look up
      Returns:
      the corresponding object, or null if the object does not exist with the appropriate class and id.
    • getBlogPostByTitle

      public BlogPost getBlogPostByTitle(String spaceKey, String title)
      Description copied from interface: BlogPostDao
      Get a blog post by name. If there is no blog post by that name, or if the name is ambiguous (there are multiple blog posts by that name on different dates), the method will return null
      Specified by:
      getBlogPostByTitle in interface BlogPostDao
      Parameters:
      spaceKey - the space
      title - the title
      Returns:
      the blog post in that key with that title, or null if there is no such post, or the title does not unambiguously refer to a single blog entry.
    • getBlogPostsInTrash

      public List<BlogPost> getBlogPostsInTrash(String spaceKey, String title)
      Description copied from interface: BlogPostDao
      Gets a blog post that is in the trash for a given space that matches the given title.
      Specified by:
      getBlogPostsInTrash in interface BlogPostDao
      Parameters:
      spaceKey - The space key (case-insensitive) in which to look for the blog
      title - The title (case-insensitive) of the blog to look for
      Returns:
      a list of blog posts in the trash that have the given title and space key.
    • getBlogPost

      public @Nullable BlogPost getBlogPost(@NonNull Space space, @NonNull String title, @NonNull Calendar day, boolean eagerLoadComments)
      Description copied from interface: BlogPostDao
      Get the blog post by name and date. If there is no blog post by that name on that date, the method will return null
      Specified by:
      getBlogPost in interface BlogPostDao
      Parameters:
      space - the space to look for the post in
      title - the title of the post we are looking for
      day - the DAY the post was created on. Any part of the calendar more specific than a day will be ignored
    • getBlogPosts

      public List<BlogPost> getBlogPosts(@NonNull Space space, @NonNull Calendar date, int period)
      Description copied from interface: BlogPostDao
      Get the blog posts in a space for a particular period.

      TODO: add Calendar.WEEK range support.

      Specified by:
      getBlogPosts in interface BlogPostDao
      Parameters:
      space - the space to look for posts in
      date - a calendar object representing the date range we are looking for. Any part of the calendar more specific than the supplied period will be ignored.
      period - one of the Calendar constants specifying the granularity of the search. currently, only Calendar.MONTH and Calendar.DATE are supported
      Returns:
      a list of blog posts in that time-range. The list may be empty but will never be null
    • getBlogPosts

      public List<BlogPost> getBlogPosts(@NonNull Space space, @NonNull Calendar date, int period, int startIndex, int maxResultCount)
      Description copied from interface: BlogPostDao
      Get list of blogPost by Date.
      Specified by:
      getBlogPosts in interface BlogPostDao
      Parameters:
      space - the space to look for posts in
      date - a calendar object representing the date range we are looking for. Any part of the calendar more specific than the supplied period will be ignored.
      period - one of the Calendar constants specifying the granularity of the search. currently, only Calendar.MONTH and Calendar.DATE are supported
      startIndex - start number of posts
      maxResultCount - Maximum number of posts to return
      Returns:
      a list of blogPost
    • getBlogPostCount

      public long getBlogPostCount(String spaceKey, Calendar date, int period)
      Description copied from interface: BlogPostDao
      Get total number of blogPost.
      Specified by:
      getBlogPostCount in interface BlogPostDao
      Parameters:
      spaceKey - the space to look for posts in
      date - a calendar object representing the date range we are looking for. Any part of the calendar more specific than the supplied period will be ignored.
      period - one of the Calendar constants specifying the granularity of the search. currently, only Calendar.MONTH and Calendar.DATE are supported
      Returns:
      a count number of blogPosts
    • getBlogPostDates

      public List<Date> getBlogPostDates(@NonNull Space space)
      Description copied from interface: BlogPostDao
      Returns a list of creation dates for all the blog posts in a space.
      Specified by:
      getBlogPostDates in interface BlogPostDao
    • getBlogPostDates

      public List<Date> getBlogPostDates(String spaceKey, Calendar date, int period)
      Description copied from interface: BlogPostDao
      Returns a list of creation dates for all the blog posts in a space for a particular period.
      Specified by:
      getBlogPostDates in interface BlogPostDao
      Parameters:
      spaceKey - the space to look for posts in.
      date - a calendar object representing the date range we are looking for. Any part of the calendar more specific than the supplied period will be ignored.
      period - one of the Calendar constants specifying the granularity of the search. currently, only Calendar.YEAR, Calendar.MONTH and Calendar.DATE are supported
      Returns:
      a list creation dates for the blog posts created in the time-range. The list may be empty but will never be null
    • getBlogPosts

      public List<BlogPost> getBlogPosts(Space space, boolean currentOnly)
      Description copied from interface: BlogPostDao
      Return an iterator for the specified space. This is an efficient alternative to space.getBlogPosts
      Specified by:
      getBlogPosts in interface BlogPostDao
    • getCurrentBlogPostIds

      public List<Long> getCurrentBlogPostIds()
      Description copied from interface: BlogPostDao
      Return a list of ids for all current blog posts.
      Specified by:
      getCurrentBlogPostIds in interface BlogPostDao
    • getRecentlyAddedBlogPosts

      public List<BlogPost> getRecentlyAddedBlogPosts(int maxCount, @Nullable String spaceKey)
      Description copied from interface: BlogPostDao
      Get list of recently created blog posts.
      Specified by:
      getRecentlyAddedBlogPosts in interface BlogPostDao
      Parameters:
      maxCount - Maximum number of posts to return
      spaceKey - the spaceKey to look for the posts in. If this key is null, we look acrosns all spaces
      Returns:
      a list of the most recently added blog posts. The list can be empty but will never be null.
    • getFirstPostBefore

      public BlogPost getFirstPostBefore(String spaceKey, Date creationDate)
      Description copied from interface: BlogPostDao
      Used for finding the "previous" post to an existing post
      Specified by:
      getFirstPostBefore in interface BlogPostDao
      Parameters:
      spaceKey - the space to look in
      creationDate - the date the post must be before
      Returns:
      the first post created before that date, or null if there are none.
    • getFirstPostAfter

      public BlogPost getFirstPostAfter(String spaceKey, Date creationDate)
      Description copied from interface: BlogPostDao
      Used for finding the "previous" post to an existing post
      Specified by:
      getFirstPostAfter in interface BlogPostDao
      Parameters:
      spaceKey - the space to look in
      creationDate - the date the post must be after
      Returns:
      the first post created after that date, or null if there are none
    • getFirstPostBefore

      public BlogPost getFirstPostBefore(BlogPost post)
      Description copied from interface: BlogPostDao
      Used for finding the "previous" post to an existing post. If you are comparing blog posts, you should always prefer this over the method that takes a date, because this method will avoid date comparison bugs that can sneak in with certain databases. (*cough* Oracle)
      Specified by:
      getFirstPostBefore in interface BlogPostDao
      Parameters:
      post - the blog post that this must preceed
      Returns:
      the first post created before the given blog post, or null if there are none.
    • getFirstPostAfter

      public BlogPost getFirstPostAfter(BlogPost post)
      Description copied from interface: BlogPostDao
      Used for finding the "previous" post to an existing post. If you are comparing blog posts, you should always prefer this over the method that takes a date, because this method will avoid date comparison bugs that can sneak in with certain databases. (*cough* Oracle)
      Specified by:
      getFirstPostAfter in interface BlogPostDao
      Parameters:
      post - the blog post that this must be after
      Returns:
      the first post created after the given blog post, or null if there are none.
    • getRecentlyAddedBlogPosts

      public List getRecentlyAddedBlogPosts(int maxPosts, Date timeSince, String spaceKey)
      Specified by:
      getRecentlyAddedBlogPosts in interface BlogPostDao
    • getMostRecentBlogPost

      public BlogPost getMostRecentBlogPost(String spaceKey)
      Specified by:
      getMostRecentBlogPost in interface BlogPostDao
    • getBlogPostCount

      public int getBlogPostCount()
      Description copied from interface: BlogPostDao
      Counts the total number of blog posts, for all spaces and posting dates.
      Specified by:
      getBlogPostCount in interface BlogPostDao
      Returns:
      the number of blog posts
    • countCurrentBlogs

      public int countCurrentBlogs()
      Description copied from interface: BlogPostDao
      Counts the total number of current blog posts across all spaces
      Specified by:
      countCurrentBlogs in interface BlogPostDao
      Returns:
      the number of current blog posts
    • countDraftBlogs

      public int countDraftBlogs()
      Description copied from interface: BlogPostDao
      Counts the number of blog posts that are drafts. This does not include drafts of blog posts that have already been published (i.e. blog posts with unpublished changes).
      Specified by:
      countDraftBlogs in interface BlogPostDao
      Returns:
      the number of draft blog posts
    • countBlogsWithUnpublishedChanges

      public int countBlogsWithUnpublishedChanges()
      Description copied from interface: BlogPostDao
      Counts the number of published blog posts that have unpublished changes.
      Specified by:
      countBlogsWithUnpublishedChanges in interface BlogPostDao
      Returns:
      the number of blog posts with unpublished changes.
    • getBlogPostStatistics

      public Optional<BlogPostStatisticsDTO> getBlogPostStatistics()
      Description copied from interface: BlogPostDao
      Fetches statistics about blog posts
      Specified by:
      getBlogPostStatistics in interface BlogPostDao
      Returns:
      a BlogPostStatisticsDTO with statistics about blogs such as total, current, and draft count
    • getCommentCountOnBlog

      public int getCommentCountOnBlog(long blogId)
      Description copied from interface: BlogPostDao
      Get count of comments on a blogpost.
      Specified by:
      getCommentCountOnBlog in interface BlogPostDao
      Parameters:
      blogId - id of the blogpost
      Returns:
      the number of comments on the blogpost
    • setEventPublisher

      public void setEventPublisher(com.atlassian.event.api.EventPublisher eventPublisher)
    • publishEvent

      protected void publishEvent(IndexerEventListener.VisitorEvent event)
      Overrides:
      publishEvent in class HibernateObjectDao<BlogPost>