Java tutorial
/** * Copyright (c) 2001-2012 "Redbasin Networks, INC" [http://redbasin.org] * * This file is part of Redbasin OpenDocShare community project. * * Redbasin OpenDocShare is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package dao; import java.sql.Connection; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import javax.sql.DataSource; import model.Blog; import model.Hdlogin; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.cache.Fqn; import util.*; /** * This object implements PblogTopicDao * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ public class PblogTopicDaoDb extends BaseDao implements PblogTopicDao { protected final Log logger = LogFactory.getLog(getClass()); private DiaryAdmin diaryAdmin; private FeedRssTool rssUtil; private volatile PblogTopicAddQuery addQuery; private volatile PblogTopicDeleteQuery deleteQuery; private volatile PblogTopicAttrDeleteQuery deleteAttrQuery; private volatile PblogTopicFreezeQuery freezeQuery; private volatile PblogTopicQuery topicQuery; private volatile PblogTopicGetQuery getTopicsQuery; private volatile PblogTopicScreenQuery screenQuery; private volatile PblogMessageCountQuery msgCountQuery; private volatile PblogTopicGetOneQuery getOneBlogQuery; private volatile PblogTopicAddAttributeQuery addAttrQuery; private volatile PblogAllTopicsQuery getAllQuery; private volatile PblogTopicExistsQuery existsQuery; private volatile PblogDailyQuery getDailyQuery; private volatile PblogDateQuery getDateQuery; private volatile PblogMonthlyQuery getMonthlyQuery; private volatile PblogMsgIsThereQuery isMsgThere; private volatile PblogTopicUpdateQuery updateQuery; private volatile PblogTopicNpUpdateQuery updateNpQuery; private volatile PblogTopicUpdateAttrQuery updateAttrQuery; // private volatile PblogTagQuery getTagQuery; //private volatile PblogTagAllQuery getAllTagQuery; // private volatile PblogTopicNpQuery getNpQuery; // private volatile PblogTopicNpBizAwareQuery getBizNpQuery; private volatile BasicQuery getTagQuery; private volatile BasicQuery getTagAllQuery; private volatile BasicQuery getNpQuery; private volatile BasicQuery getBizNpQuery; private volatile PblogTagAddQuery addTagQuery; private volatile PblogTopicNpAddQuery addNpQuery; private volatile PblogTagDeleteOneQuery deleteOneTagQuery; private volatile PblogTopicNpDeleteQuery deleteNpQuery; private volatile PblogTagDeleteQuery deleteTagQuery; private volatile PblogTidQuery getTidQuery; //http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html // replyid is auto incremented in the database, this is not passed. // mid is the reply to the thread. so mid value is the rid of some entry to which it was replied to. // // ------------------------- // tid mid rid // ------------------------- // 1 null 1 // 1 1 2 // 1 2 3 // 1 1 4 // 1 1 4 // ------------------------- // 2 null 5 // 2 5 6 // ------------------------- // 1 4 7 // /** * This method checks if posts/topics exist for a personal blog * @param userId - the user id of the blogger * @return String - "1" or "0" based on the existence of the topic * @throws BaseDaoException **/ public String topicExists(String userId) throws BaseDaoException { if (RegexStrUtil.isNull(userId)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the topicexists already set in the cache * If it exists, return the topicexists from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); Object obj = treeCache.get(fqn, userId); if (obj != null) { return "1"; } /** * Get scalability datasource for pblogtopics partitioned on userId */ String sourceName = scalabilityManager.getReadScalability(userId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, topicExists() " + sourceName + " userId = " + userId); } try { Object[] params = { (Object) userId }; List result = existsQuery.execute(params); if ((result != null) && (result.size() > 0)) { return "1"; } } catch (Exception e) { throw new BaseDaoException("error occured while checking for existence of pblog topics , " + existsQuery.getSql() + " params (1) pblogid/userId = " + userId, e); } return "0"; } /** * This gets the recent personal blog * @param pblogId - pblog id (personal blog id) * @param userLogin - user login who is accessing this information * @return Blog - the blog bean * @throws BaseDaoException */ public Blog getRecentBlog(String pblogId, String userLogin) { /** * we don't check for userLogin as this can be viewed without session */ if (RegexStrUtil.isNull(pblogId)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the userpage already set in the cache * If it exists, return the userpage from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.RECENT_PBLOG); Object obj = treeCache.get(fqn, pblogId); if (obj != null) { return (Blog) obj; } /** * Get scalability datasource for pblogtopics partitioned on pblogId */ String sourceName = scalabilityManager.getReadScalability(pblogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null getRecentBlog() pblogId = " + pblogId); } try { Object[] params = { (Object) pblogId }; List result = getOneBlogQuery.execute(params); if ((result != null) && (result.size() > 0)) { Blog blog = (Blog) result.get(0); if (blog == null) { return null; } Hdlogin hdlogin = getLogin(pblogId); if (hdlogin != null) { blog.setObject(DbConstants.BLOGGER_INFO, hdlogin); } if (diaryAdmin.isDiaryAdmin(userLogin)) { blog.setValue(DbConstants.IS_ADMIN, "1"); } else { blog.setValue(DbConstants.IS_ADMIN, "0"); } treeCache.put(fqn, pblogId, blog); return blog; } return null; } catch (Exception e) { throw new BaseDaoException( "getRecentBlog()/PblogTopicGetOneQuery() error, userid = " + pblogId + getOneBlogQuery.getSql(), e); } } /** * update a topic in personal blog - allows the user to personalize the information * @param tid - topic id * @param topic - topic * @param message - message (can include HTML/digital content) * @param userId - user id of the blogger * @param userLogin - user login of the blogger * @param fontSize - font size for the topic * @param fontFace - font face for the topic * @param fontColor - font color for the topic * @param moodId - mood id for this topic * @param bgColor - background color for the topic * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void updatePblogTopic(String tid, String topic, String message, String userId, String userLogin, String fontSize, String fontFace, String fontColor, String moodId, String bgColor) throws BaseDaoException { /** * either one of them should exist */ if (RegexStrUtil.isNull(topic) && RegexStrUtil.isNull(message)) { throw new BaseDaoException("topic and message are null"); } /** * userid same as pblogid */ if (RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for pblogtopics - partition on userId (pBlogId) */ String sourceName = scalabilityManager.getWriteScalability(userId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, updatePblogTopic() " + sourceName + " userId = " + userId); } Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); updateQuery.run(conn, tid, message, topic); updateAttrQuery.run(conn, tid, fontSize, fontFace, fontColor, moodId, bgColor); } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "conn.setAutoCommit(true),conn.close(), updating pblogtopics exception", e2); } throw new BaseDaoException("conn.rollback() error, updating pblogtopics, attributes", e1); } } try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("conn.commit() error, updating pblogtopics, attributes", e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException("conn.close() error, updating pblogtopics, setAutoCommit(true) ", e4); } /* update np table */ sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, updateNpQuery() " + sourceName + " userId = " + userId); } try { conn = ds.getConnection(); updateNpQuery.run(conn, userId, tid); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close(), updating pblog np exception", e1); } throw new BaseDaoException("error updating pblog np", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("error updating pblog np", e); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC); StringBuffer sb = new StringBuffer(userId); sb.append("-"); sb.append(tid); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); if (treeCache.exists(fqn, userId)) { treeCache.remove(fqn, userId); } fqn = cacheUtil.fqn(DbConstants.PBLOG_DAILY_LIST); if (treeCache.exists(fqn, userId)) { treeCache.remove(fqn, userId); } fqn = cacheUtil.fqn(DbConstants.PERSONAL_BLOG); if (treeCache.exists(fqn, userId)) { treeCache.remove(fqn, userId); } fqn = cacheUtil.fqn(DbConstants.POPULAR_BLOGS); if (treeCache.exists(fqn, DbConstants.POPULAR_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.POPULAR_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.RECENT_BLOGS); if (treeCache.exists(fqn, DbConstants.RECENT_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.RECENT_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } fqn = cacheUtil.fqn(DbConstants.PBLOG_C_TOPICS); if (treeCache.exists(fqn, DbConstants.PBLOG_C_TOPICS)) { treeCache.remove(fqn, DbConstants.PBLOG_C_TOPICS); } fqn = cacheUtil.fqn(DbConstants.PBLOG_C_BIZ_TOPICS); if (treeCache.exists(fqn, DbConstants.PBLOG_C_BIZ_TOPICS)) { treeCache.remove(fqn, DbConstants.PBLOG_C_BIZ_TOPICS); } } /** * add a new topic in personal blog - allow the users to personalize the information * @param topic - new topic to add * @param message - new message (can include HTML/digital content) * @param userId - user id or the blogger id * @param userLogin - user login of the blogger * @param fontSize - font size for the topic * @param fontFace - font face for the topic * @param fontColor - font color for the topic * @param moodId - mood id for this topic * @param bgColor - background color for the topic * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void addPblogTopic(String topic, String message, String userId, String userLogin, String fontSize, String fontFace, String fontColor, String moodId, String bgColor, String usertags) throws BaseDaoException { /** * userid same as pblogid */ if (RegexStrUtil.isNull(message) && RegexStrUtil.isNull(topic)) { throw new BaseDaoException("message and topic are null"); } if (RegexStrUtil.isNull(userId) || RegexStrUtil.isNull(userLogin)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for pblogtopics - partition on userId (pBlogId) */ String sourceName = scalabilityManager.getWriteScalability(userId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, addPblogTopic() " + sourceName + " userId = " + userId); } List tidResult = null; Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); addQuery.run(conn, userId, message, topic); addAttrQuery.run(conn, "LAST_INSERT_ID()", fontSize, fontFace, fontColor, moodId, bgColor, userId); } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "conn.setAutoCommit(true),conn.close(), adding pblogtopics exception", e2); } throw new BaseDaoException("conn.rollback() error, adding pblogtopics, attributes", e1); } } try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("conn.commit() error, adding pblogtopics, attributes", e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException("conn.close() error, adding pblogtopics, setAutoCommit(true) ", e4); } if (!RegexStrUtil.isNull(usertags)) { try { conn = ds.getConnection(); tidResult = getTidQuery.run(conn, userId); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("conn.close() exception for getTidQuery()", e2); } throw new BaseDaoException("conn.close exeception for getTidQuery()", e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception for getTidQuery() ", e2); } if (tidResult != null && tidResult.size() > 0) { addTagsAndNp(((Blog) tidResult.get(0)).getValue(DbConstants.TID), userId, usertags, userLogin); } } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); if (treeCache.exists(fqn, userId)) { treeCache.remove(fqn, userId); } fqn = cacheUtil.fqn(DbConstants.PBLOG_DAILY_LIST); if (treeCache.exists(fqn, userId)) { treeCache.remove(fqn, userId); } fqn = cacheUtil.fqn(DbConstants.PERSONAL_BLOG); if (treeCache.exists(fqn, userId)) { treeCache.remove(fqn, userId); } fqn = cacheUtil.fqn(DbConstants.POPULAR_BLOGS); if (treeCache.exists(fqn, DbConstants.POPULAR_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.POPULAR_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.RECENT_BLOGS); if (treeCache.exists(fqn, DbConstants.RECENT_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.RECENT_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } fqn = cacheUtil.fqn(DbConstants.PBLOG_C_TOPICS); if (treeCache.exists(fqn, DbConstants.PBLOG_C_TOPICS)) { treeCache.remove(fqn, DbConstants.PBLOG_C_TOPICS); } fqn = cacheUtil.fqn(DbConstants.PBLOG_C_BIZ_TOPICS); if (treeCache.exists(fqn, DbConstants.PBLOG_C_BIZ_TOPICS)) { treeCache.remove(fqn, DbConstants.PBLOG_C_BIZ_TOPICS); } } /** * delete blog from pblogtopic * @param tid - the thread id * @param pBlogId - the blog id of the blogger * @param userLogin - the user login of the blogger * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deletePblogTopic(String tid, String pBlogId, String userLogin) throws BaseDaoException { if (RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(userLogin) || RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for pblogs, partitioned on pBlogId */ String sourceName = scalabilityManager.getWriteScalability(pBlogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deletePblogTopic() " + sourceName + " pBlogId = " + pBlogId); } Connection conn = null; try { conn = ds.getConnection(); deleteQuery.run(conn, tid, pBlogId); deleteAttrQuery.run(conn, pBlogId, tid); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception for deletePblogTopic() ", e2); } throw new BaseDaoException("error occured while deleting topic", e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception for deletePblogTopic() ", e2); } sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteOneTag() " + sourceName + " pBlogId = " + pBlogId); } try { conn = ds.getConnection(); deleteOneTagQuery.run(conn, pBlogId, tid); deleteNpQuery.run(conn, pBlogId, tid); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close(), deleting tag and nptopic", e1); } throw new BaseDaoException("error occured, deleting tag and nptopic", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("deleting tag and nptopic", e); } StringBuffer sb = new StringBuffer(pBlogId); sb.append("-"); sb.append(tid); String key = sb.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.PBLOG_MESSAGES); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.PBLOG_DAILY_LIST); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.RECENT_PBLOG); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.PERSONAL_BLOG); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.POPULAR_BLOGS); if (treeCache.exists(fqn, DbConstants.POPULAR_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.POPULAR_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.RECENT_BLOGS); if (treeCache.exists(fqn, DbConstants.RECENT_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.RECENT_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, userLogin)) { treeCache.remove(fqn, userLogin); } fqn = cacheUtil.fqn(DbConstants.PBLOG_C_TOPICS); if (treeCache.exists(fqn, DbConstants.PBLOG_C_TOPICS)) { treeCache.remove(fqn, DbConstants.PBLOG_C_TOPICS); } fqn = cacheUtil.fqn(DbConstants.PBLOG_C_BIZ_TOPICS); if (treeCache.exists(fqn, DbConstants.PBLOG_C_BIZ_TOPICS)) { treeCache.remove(fqn, DbConstants.PBLOG_C_BIZ_TOPICS); } } /** * This method retrieves the topics based on the thread id * @param pBlogId - the user id (pBlogId) * @param tid - the thread id * @param userLogin - the user login * @return <code>Blog</code> - the bean * @throws BaseDaoException - when error occurs */ public Blog getPblogTopic(String pBlogId, String tid, String userLogin) throws BaseDaoException { return getPblogTopic(pBlogId, tid, userLogin, DbConstants.READ_FROM_SLAVE); } /** * This method retrieves the personal blog for Rss * @param pBlogId - the user id (pBlogId) * @param tid - the thread id * @param accessFlag - the access flag which specifies the datasource (Master(1)/slave(0)) * @return <code>Blog</code> - the bean * @throws BaseDaoException - when error occurs */ public Blog getRssPblogTopic(String pBlogId, String tid, String userLogin, int accessFlag, String url) throws BaseDaoException { if (RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } Blog blog = null; Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC); StringBuffer sb = new StringBuffer(pBlogId); sb.append("-"); sb.append(tid); Object obj = treeCache.get(fqn, sb.toString()); if (obj != null) { blog = (Blog) obj; } else { blog = getPblogTopic(pBlogId, tid, userLogin, accessFlag); } if (blog != null) { blog.setValue(DbConstants.TITLE, blog.getValue(DbConstants.TOPIC)); blog.setValue(DbConstants.DATE, blog.getValue(DbConstants.EDATE)); blog.setValue(DbConstants.AUTHOR, userLogin); blog.setValue(DbConstants.LINK, rssUtil.createBlogLink(url, userLogin, tid)); blog.setValue(DbConstants.DESCRIPTION, blog.getValue(DbConstants.MESSAGE)); } return blog; } /** * This method retrieves the topics based on the thread id * @param pBlogId - the user id (pBlogId) * @param tid - the thread id * @param accessFlag - the access flag which specifies the datasource (Master(1)/slave(0)) * @return <code>Blog</code> - the bean * @throws BaseDaoException - when error occurs */ public Blog getPblogTopic(String pBlogId, String tid, String userLogin, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC); StringBuffer sb = new StringBuffer(pBlogId); sb.append("-"); sb.append(tid); Object obj = treeCache.get(fqn, sb.toString()); if (obj != null) { return (Blog) obj; } /** * Get scalability datasource for pblogtopics partitioned on pBlogId */ String sourceName = null; if (accessFlag == 1) { sourceName = scalabilityManager.getWriteScalability(pBlogId); } else { sourceName = scalabilityManager.getReadScalability(pBlogId); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getPblogTopic() " + sourceName + " pBlogId = " + pBlogId); } /** * get the pblogtopic */ List result = null; try { Object[] params = { (Object) tid }; result = topicQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error listing pblogtopic messages." + topicQuery.getSql(), e); } /** * retrieve the ownername (first + last) for each ownerid of the topic */ if ((result != null) && (result.size() > 0)) { Blog pTopic = (Blog) result.get(0); if (pTopic != null) { Hdlogin hdlogin = getLogin(pBlogId); pTopic.setObject(DbConstants.BLOGGER_INFO, hdlogin); if (!RegexStrUtil.isNull(userLogin)) { if (diaryAdmin.isDiaryAdmin(userLogin)) { pTopic.setValue(DbConstants.IS_ADMIN, "1"); } else { pTopic.setValue(DbConstants.IS_ADMIN, "0"); } } Object[] params = { (Object) tid }; List msgResult = isMsgThere.execute(params); if ((msgResult != null) && (msgResult.size() > 0)) { pTopic.setValue(DbConstants.MSG_EXISTS, "1"); } treeCache.put(fqn, sb.toString(), pTopic); return pTopic; } } return null; } /** * Allow users to view it, with session or without session * topics are retrieved from datasource that is based on accessFlag * Retrieves topics based on pBlogId/pBlogId from slave * @param pBlogId - the blog id */ public List getTopics(String pBlogId, boolean getLoginInfo) throws BaseDaoException { return getTopics(pBlogId, DbConstants.READ_FROM_SLAVE, getLoginInfo); } /** * Allow users to view it, with session or without session * topics are retrieved from datasource that is based on accessFlag * Retrieves topics based on pBlogId * @param pBlogId - the personal blogid * @param accessFlag - the access Flag, which indicates the datasource from which topics are retrieved. * READ_FROM_MASTER (1), READ_FROM_SLAVE(0) */ public List getTopics(String pBlogId, int accessFlag, boolean getLoginInfo) throws BaseDaoException { if (RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); Object obj = treeCache.get(fqn, pBlogId); if (obj != null) { return (List) obj; } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String sourceName = scalabilityManager.getReadScalability(pBlogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getTopics() " + sourceName + " pBlogId = " + pBlogId); } List result = null; try { Object[] params = { (Object) pBlogId }; result = getAllQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error occured while listing pblogtopics", e); } /** * set ownername, login for the first topic, as it is the same for all the topics */ if (getLoginInfo) { if ((result != null) && (result.size() > 0)) { Blog pTopic = (Blog) result.get(0); if (pTopic != null) { Hdlogin hdlogin = getLogin(pTopic.getValue(DbConstants.OWNER_ID)); pTopic.setObject(DbConstants.OWNER_INFO, hdlogin); } } } if ((result != null) && (result.size() > 0)) { for (int i = 0; i < result.size(); i++) { Blog pTopic = (Blog) result.get(i); Object[] params = { (Object) pTopic.getValue(DbConstants.TID) }; List msgResult = isMsgThere.execute(params); if ((msgResult != null) && (msgResult.size() > 0)) { pTopic.setValue(DbConstants.MSG_EXISTS, "1"); } } treeCache.put(fqn, pBlogId, result); } return result; } /** * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void freezeTopic(String pBlogId, String tid, String userLogin, String freeze) throws BaseDaoException { if (RegexStrUtil.isNull(pBlogId) || RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(userLogin) || RegexStrUtil.isNull(freeze)) { throw new BaseDaoException("params are null"); } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String sourceName = scalabilityManager.getWriteScalability(pBlogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, freezeTopic() " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); if (conn != null) { freezeQuery.run(conn, tid, freeze); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "conn.close() exception, freezeTopic(), tid =" + tid + "pBlogId=" + pBlogId, e2); } } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "connection close exception for freezeTopic(),tid=" + tid + " pBlogId=" + pBlogId, e2); } StringBuffer sb = new StringBuffer(pBlogId); sb.append("-"); sb.append(tid); Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.PBLOG_MESSAGES); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.PBLOG_DAILY_LIST); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.RECENT_PBLOG); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.PERSONAL_BLOG); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.POPULAR_BLOGS); if (treeCache.exists(fqn, DbConstants.POPULAR_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.POPULAR_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.RECENT_BLOGS); if (treeCache.exists(fqn, DbConstants.RECENT_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.RECENT_BLOG_KEY); } } /** * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void screenTopic(String pBlogId, String tid, String userLogin, String screen) throws BaseDaoException { if (RegexStrUtil.isNull(pBlogId) || RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(userLogin) || RegexStrUtil.isNull(screen)) { throw new BaseDaoException("params are null"); } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String sourceName = scalabilityManager.getWriteScalability(pBlogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, screenTopic() " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); screenQuery.run(conn, tid, screen); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "connection close exception for screenTopic(), tid =" + tid + " pBlogId=" + pBlogId, e2); } throw new BaseDaoException("error occured while screenTopic, tid=" + tid + " pBlogId = " + pBlogId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "connection close exception for screenTopic() tid =" + tid + " pBlogId=" + pBlogId, e2); } StringBuffer sb = new StringBuffer(pBlogId); sb.append("-"); sb.append(tid); Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.PBLOG_MESSAGES); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.RECENT_PBLOG); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.PBLOG_DAILY_LIST); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.PERSONAL_BLOG); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } fqn = cacheUtil.fqn(DbConstants.POPULAR_BLOGS); if (treeCache.exists(fqn, DbConstants.POPULAR_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.POPULAR_BLOG_KEY); } fqn = cacheUtil.fqn(DbConstants.RECENT_BLOGS); if (treeCache.exists(fqn, DbConstants.RECENT_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.RECENT_BLOG_KEY); } } /** * Allow users to view it, with session or without session * topics are retrieved from datasource that is based on accessFlag * Retrieves topics based on pBlogId and date * @param pBlogId - the personal blogid * @param accessFlag - the access Flag, which indicates the datasource from which topics are retrieved. * READ_FROM_MASTER (1), READ_FROM_SLAVE(0) * @param getLoginInfo - get the blogger's information * @param entrydate - the date * @return HashSet - the dates for each topic * @throws BaseDaoException - when error occurs */ public HashSet getTopicDates(String pBlogId, int accessFlag, boolean getLoginInfo, String entrydate) throws BaseDaoException { if (RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String sourceName = scalabilityManager.getReadScalability(pBlogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getTopicDates() " + sourceName + " pBlogId = " + pBlogId); } HashSet result = null; Connection conn = null; try { conn = ds.getConnection(); result = getDateQuery.run(conn, pBlogId, MyUtils.getMonthNum(entrydate), MyUtils.getYear(entrydate), MyUtils.getDay(entrydate)); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("error occured while listing pblogtopics getDateQuery()" + pBlogId, e1); } throw new BaseDaoException("error in getDateQuery(), pBlogId =" + pBlogId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("conn.close() error in getDateQuery(), pBlogId =" + pBlogId, e2); } HashSet dateSet = null; if ((result != null) && (result.size() > 0)) { Iterator it = result.iterator(); dateSet = new HashSet(); while (it.hasNext()) { Blog blog = (Blog) it.next(); dateSet.add(blog.getValue(DbConstants.ENTRY_DATE)); } } return dateSet; /* if ((result != null) && (result.size() > 0) ) { Iterator it = result.iterator(); while (it.hasNext() ) { Blog blog = (Blog)it.next(); String date = blog.getValue(DbConstants.ENTRY_DATE); if (date.equals(entrydate)) { //treeCache.put(fqn, pBlogId, result); return result; } } } */ } /** * Get blogs within a specific month * @param pBlogId - the personal blogid * @param accessFlag - the access Flag, which indicates the datasource from which topics are retrieved. * READ_FROM_MASTER (1), READ_FROM_SLAVE(0) * @param getLoginInfo - get the blogger's information * @param entrydate - the date * @return HashSet - the dates for each topic * @throws BaseDaoException - when error occurs */ public HashSet getMonthlyTopicDates(String pBlogId, int accessFlag, boolean getLoginInfo, String entrydate) throws BaseDaoException { if (RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String sourceName = scalabilityManager.getReadScalability(pBlogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getTopicDates() " + sourceName + " pBlogId = " + pBlogId); } HashSet result = null; Connection conn = null; try { conn = ds.getConnection(); result = getMonthlyQuery.run(conn, pBlogId, MyUtils.getMonthNum(entrydate), MyUtils.getYear(entrydate)); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("error occured while listing pblogtopics getMonthlyQuery()" + pBlogId, e1); } throw new BaseDaoException("error in getMonthlyQuery(), pBlogId =" + pBlogId, e); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { throw new BaseDaoException("conn.close() error in getMonthlyQuery(), pBlogId =" + pBlogId, e2); } HashSet dateSet = null; if ((result != null) && (result.size() > 0)) { Iterator it = result.iterator(); dateSet = new HashSet(); while (it.hasNext()) { Blog blog = (Blog) it.next(); dateSet.add(blog.getValue(DbConstants.ENTRY_DATE)); } } return dateSet; /* if ((result != null) && (result.size() > 0) ) { Iterator it = result.iterator(); while (it.hasNext() ) { Blog blog = (Blog)it.next(); String date = blog.getValue(DbConstants.ENTRY_DATE); if (date.equals(entrydate)) { //treeCache.put(fqn, pBlogId, result); return result; } } } */ } /** * updateTags - update existing usertags for this blog topic * @param tid - thread id * @param pBlogId - personal blog id * @param usertags - tags or keywords for this blog * @throws BaseDaoException if an error occurs */ public void updateTags(String tid, String pBlogId, String usertags) { if (RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for pblogtags - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, updateTags() " + sourceName + " pBlogId = " + pBlogId); } String myTags = getTags(tid, pBlogId, DbConstants.READ_FROM_SLAVE); Connection conn = null; try { conn = ds.getConnection(); if (!RegexStrUtil.isNull(myTags)) { deleteTagQuery.run(conn, pBlogId); } String[] mykeys = usertags.split(","); for (int i = 0; i < mykeys.length; i++) { addTagQuery.run(conn, pBlogId, tid, mykeys[i]); //addTagQuery.run(conn, pBlogId, tid, usertags); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close(), updating pblog tags exception", e1); } throw new BaseDaoException("error updating pblog tags", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error, updating pblog tags", e); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TAGS); StringBuffer sb = new StringBuffer(); sb.append(pBlogId); sb.append("-"); sb.append(tid); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.PBLOG_ALL_TAGS); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } } /** * addTagsAndNp - adds usertags and an entry into NP for this blog topic * @param tid - thread id * @param pBlogId - personal blog id * @param usertags - tags or keywords to add to this blog * @throws BaseDaoException if an error occurs */ public void addTagsAndNp(String tid, String pBlogId, String usertags, String userLogin) { /** * Nothing to add */ if (RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } /** * Get scalability datasource for pblogtags - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, addTagsAndNp() " + sourceName + " pBlogId = " + pBlogId); } Connection conn = null; try { conn = ds.getConnection(); if (!RegexStrUtil.isNull(usertags)) { String[] mykeys = usertags.split(","); for (int i = 0; i < mykeys.length; i++) { addTagQuery.run(conn, pBlogId, tid, mykeys[i]); //addTagQuery.run(conn, pBlogId, tid, usertags); } } if (!RegexStrUtil.isNull(userLogin)) { addNpQuery.run(conn, pBlogId, tid, userLogin); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close(),adding topic tags/addNpQuery exception", e1); } throw new BaseDaoException("error adding topic tags/addNpQuery", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error, adding pblog tags", e); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TAGS); StringBuffer sb = new StringBuffer(); sb.append(pBlogId); sb.append("-"); sb.append(tid); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.PBLOG_ALL_TAGS); if (treeCache.exists(fqn, pBlogId)) { treeCache.remove(fqn, pBlogId); } } /** * getCurrentTopics - gets Current Topics * @param accessFlag - access flag * @return List * @throws BaseDaoException if an error occurs */ public List getCurrentTopics(int accessFlag) { Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_C_TOPICS); Object obj = treeCache.get(fqn, DbConstants.PBLOG_C_TOPICS); if (obj != null) { return (List) obj; } /** * Get scalability ds for pblogtopics_np */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteZeroScalability("pblogtopicnpQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("pblogtopicnpQuery"); } getNpQuery = getQueryMapper().getQuery(queryName); List result = null; try { result = getNpQuery.execute(); if (result != null && result.size() > 0) { treeCache.put(fqn, DbConstants.PBLOG_C_TOPICS, result); return result; } } catch (Exception e) { throw new BaseDaoException("error, getCurrentTopics(), " + getNpQuery.getSql(), e); } return null; } /** * getBizCurrentTopics - gets Current Topics in a particular biz * @param accessFlag - access flag * @return List * @throws BaseDaoException if an error occurs */ public List getBizCurrentTopics(String bid, int accessFlag) { Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_C_BIZ_TOPICS); Object obj = treeCache.get(fqn, DbConstants.PBLOG_C_BIZ_TOPICS); if (obj != null) { return (List) obj; } /** * Get scalability ds for pblogtopics_np */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteZeroScalability("pblogtopicnpbizQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("pblogtopicnpbizQuery"); } getBizNpQuery = getQueryMapper().getQuery(queryName); List result = null; try { Object[] params = { (Object) bid }; result = getBizNpQuery.execute(params); if (result != null && result.size() > 0) { if (result != null && result.size() > 0) { treeCache.put(fqn, DbConstants.PBLOG_C_BIZ_TOPICS, result); return result; } } } catch (Exception e) { throw new BaseDaoException("error, getCurrentTopics(), " + getBizNpQuery.getSql(), e); } return null; } /** * getTags - gets usertags for this blog topic * @param tid - thread id * @param pBlogId - personal blog id * @param accessFlag - access flag * @return String - tags * @throws BaseDaoException if an error occurs */ public String getTags(String tid, String pBlogId, int accessFlag) { if (RegexStrUtil.isNull(tid) || RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TAGS); StringBuffer sb = new StringBuffer(); sb.append(pBlogId); sb.append("-"); sb.append(tid); Object obj = treeCache.get(fqn, sb.toString()); if (obj != null) { return (String) obj; } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteZeroScalability("pblogtagQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("pblogtagQuery"); } getTagQuery = getQueryMapper().getQuery(queryName); List result = null; StringBuffer tags = new StringBuffer(); try { Object[] params = { (Object) pBlogId, (Object) tid }; result = getTagQuery.execute(params); if (result != null && result.size() > 0) { for (int i = 0; i < result.size(); i++) { if ((Blog) result.get(i) != null) { tags.append(((Blog) result.get(i)).getValue(DbConstants.USER_TAGS)); if (i != result.size() - 1) { tags.append(","); } } } treeCache.put(fqn, sb.toString(), tags.toString()); return (tags.toString()); } } catch (Exception e) { throw new BaseDaoException("error occured while listing tag for" + getTagQuery.getSql(), e); } return null; } /** * getAllTags - gets all the usertags for this user * @param pBlogId - personal blog id * @param accessFlag - access flag * @return List - list of all tags for all the topics * @throws BaseDaoException if an error occurs */ public List getAllTags(String pBlogId, int accessFlag) { if (RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_ALL_TAGS); Object obj = treeCache.get(fqn, pBlogId); if (obj != null) { return (List) obj; } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteZeroScalability("pblogtagallQuery"); } else { queryName = scalabilityManager.getReadZeroScalability("pblogtagallQuery"); } getTagAllQuery = getQueryMapper().getQuery(queryName); List result = null; try { Object[] params = { (Object) pBlogId }; result = getTagAllQuery.execute(params); if (result != null && result.size() > 0) { treeCache.put(fqn, pBlogId, result); } } catch (Exception e) { throw new BaseDaoException("error occured while listing tag for" + getTagAllQuery.getSql(), e); } return result; } /** * RSS topics, viewed with session or without session * topics are retrieved from datasource that is based on accessFlag * Retrieves topics based on pBlogId * @param pBlogId - the personal blogid * @param accessFlag - the access Flag, which indicates the datasource from which topics are retrieved. * READ_FROM_MASTER (1), READ_FROM_SLAVE(0) * @param url - the url * @param Hdlogin - hdlogin * @return List - the dates for each topic * @throws BaseDaoException - when error occurs */ public List getRssTopics(String pBlogId, int accessFlag, String url, Hdlogin hdlogin) throws BaseDaoException { if (RegexStrUtil.isNull(pBlogId) || RegexStrUtil.isNull(url)) { throw new BaseDaoException("params are null"); } List topicList = null; Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_TOPIC_LIST); Object obj = treeCache.get(fqn, pBlogId); if (obj != null) { topicList = (List) obj; } /** * need not access the hdlogin information */ if (topicList == null) { topicList = getTopics(pBlogId, accessFlag, false); } if (topicList != null) { boolean added = false; String author = null; String userLogin = null; if (hdlogin != null) { author = hdlogin.getValue(DbConstants.OWNER_NAME); userLogin = hdlogin.getValue(DbConstants.LOGIN); } ArrayList rssTopicList = new ArrayList(); for (int i = 0; i < topicList.size(); i++) { Blog blog = (Blog) topicList.get(i); if (blog == null) continue; /* don't show this if this blog is screened */ if ((blog.getValue(DbConstants.SCREEN) != null) && blog.getValue(DbConstants.SCREEN).equals((Object) "1")) { continue; } blog.setValue(DbConstants.TITLE, blog.getValue(DbConstants.TOPIC)); blog.setValue(DbConstants.AUTHOR, author); if (!RegexStrUtil.isNull(userLogin)) { blog.setValue(DbConstants.LINK, rssUtil.createBlogLink(url, userLogin, blog.getValue(DbConstants.TID))); } blog.setValue(DbConstants.DESCRIPTION, blog.getValue(DbConstants.MESSAGE)); added = true; rssTopicList.add(blog); } if (added) return rssTopicList; } return null; } /* public Blog createRssChannelTopic(Blog blog, Hdlogin hdlogin, String url, String photoUrl) { Blog channel = channel(); if (channel != null) { channel.setValue(DbConstants.TITLE, blog.getValue(DbConstants.TOPIC)); channel.setValue(DbConstants.DATE, blog.getValue(DbConstants.ENTRY_DATE)); channel.setValue(DbConstants.AUTHOR, hdlogin.getValue(DbConstants.OWNER_NAME)); channel.setValue(DbConstants.LINK, rssUtil.createBlogLink(url, hdlogin.getValue(DbConstants.LOGIN), date); //channel.setValue(DbConstants.DESCRIPTION, blog.getValue(DbConstants.MESSAGE)); channel.setValue(DbConstants.IMAGE, photoUrl); } } return topicList; } */ /** * Allow users to view it, with session or without session * topics are retrieved from datasource that is based on accessFlag * Retrieves topics based on pBlogId * @param pBlogId - the personal blogid * @param accessFlag - the access Flag, which indicates the datasource from which topics are retrieved. * READ_FROM_MASTER (1), READ_FROM_SLAVE(0) * @param date - the date * @return List - the dates for each topic * @throws BaseDaoException - when error occurs */ public List getDailyTopics(String pBlogId, int accessFlag, boolean getLoginInfo, String date) throws BaseDaoException { if (RegexStrUtil.isNull(pBlogId)) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.PBLOG_DAILY_LIST); Object obj = treeCache.get(fqn, pBlogId); if (obj != null) { return (List) obj; } /** * Get scalability ds for topics, topics partitioned on pBlogId */ String sourceName = scalabilityManager.getReadScalability(pBlogId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getDailyTopics() " + sourceName + " pBlogId = " + pBlogId); } List result = null; try { //Object[] params = {(Object)pBlogId, (Object)date}; Object[] params = { (Object) pBlogId }; result = getDailyQuery.execute(params); } catch (Exception e) { throw new BaseDaoException("error occured while listing pblogtopics", e); } /** * set ownername, login for the first topic, as it is the same for all the topics */ if (getLoginInfo) { if ((result != null) && (result.size() > 0)) { Blog pTopic = (Blog) result.get(0); if (pTopic != null) { Hdlogin hdlogin = getLogin(pTopic.getValue(DbConstants.OWNER_ID)); pTopic.setObject(DbConstants.OWNER_INFO, hdlogin); } } } if ((result != null) && (result.size() > 0)) { for (int i = 0; i < result.size(); i++) { Blog pTopic = (Blog) result.get(i); Object[] params = { (Object) pTopic.getValue(DbConstants.TID) }; List msgResult = isMsgThere.execute(params); if ((msgResult != null) && (msgResult.size() > 0)) { pTopic.setValue(DbConstants.MSG_EXISTS, "1"); } } treeCache.put(fqn, pBlogId, result); } return result; } /** * Setting all the properties required for pblogtopic dao **/ public void setJdbcSource(DataSource ds) { this.ds = ds; } public void setDiaryadmin(DiaryAdmin ds) { this.diaryAdmin = ds; } public void setpblogtopicaddQuery(PblogTopicAddQuery daq) { this.addQuery = daq; } public void setpblogtopicdeleteQuery(PblogTopicDeleteQuery daq) { this.deleteQuery = daq; } public void setpblogtopicfreezeQuery(PblogTopicFreezeQuery daq) { this.freezeQuery = daq; } public void setpblogtopicQuery(PblogTopicQuery daq) { this.topicQuery = daq; } public void setpblogtopicgetQuery(PblogTopicGetQuery daq) { this.getTopicsQuery = daq; } public void setpblogmsgcountQuery(PblogMessageCountQuery daq) { this.msgCountQuery = daq; } public void setpblogtopicscreenQuery(PblogTopicScreenQuery daq) { this.screenQuery = daq; } public void setpblogtopicgetoneQuery(PblogTopicGetOneQuery daq) { this.getOneBlogQuery = daq; } public void setpblogtopicaddattributeQuery(PblogTopicAddAttributeQuery daq) { this.addAttrQuery = daq; } public void setpblogalltopicsQuery(PblogAllTopicsQuery daq) { this.getAllQuery = daq; } public void setpblogtopicexistsQuery(PblogTopicExistsQuery daq) { this.existsQuery = daq; } public void setpblogdailyQuery(PblogDailyQuery daq) { this.getDailyQuery = daq; } public void setpblogdateQuery(PblogDateQuery daq) { this.getDateQuery = daq; } public void setpblogmsgisthereQuery(PblogMsgIsThereQuery daq) { this.isMsgThere = daq; } public void setpblogtopicupdateQuery(PblogTopicUpdateQuery daq) { this.updateQuery = daq; } public void setpblogtopicattrupdateQuery(PblogTopicUpdateAttrQuery daq) { this.updateAttrQuery = daq; } public void setpblogtagaddQuery(PblogTagAddQuery daq) { this.addTagQuery = daq; } public void setpblogtagdeleteoneQuery(PblogTagDeleteOneQuery daq) { this.deleteOneTagQuery = daq; } public void setpblogtagdeleteQuery(PblogTagDeleteQuery daq) { this.deleteTagQuery = daq; } public void setpblogtopicattrdeleteQuery(PblogTopicAttrDeleteQuery daq) { this.deleteAttrQuery = daq; } public void setpblogtidQuery(PblogTidQuery daq) { this.getTidQuery = daq; } public void setrssutil(FeedRssTool daq) { this.rssUtil = daq; } public void setpblogmonthlyQuery(PblogMonthlyQuery daq) { this.getMonthlyQuery = daq; } public void setpblogtopicnpdeleteQuery(PblogTopicNpDeleteQuery daq) { this.deleteNpQuery = daq; } public void setpblogtopicnpaddQuery(PblogTopicNpAddQuery daq) { this.addNpQuery = daq; } public void setpblogtopicnpupdateQuery(PblogTopicNpUpdateQuery daq) { this.updateNpQuery = daq; } }