*/
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);