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.HashSet; import java.util.List; import javax.sql.DataSource; import model.Hdlogin; import model.Photo; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.cache.Fqn; import san.FileSystemImpl; import san.SanException; import util.*; // Certified for heap efficiency 3/31/2005 /** * <B>CarryonDaoDb</B> * This object implements CarryonDaoDb * Carryon table is partitioned based on loginId * * @author Smitha Gudur (smitha@redbasin.com) * @version $Revision: 1.1 $ */ public class CarryonDaoDb extends BaseDao implements CarryonDao { protected final Log logger = LogFactory.getLog(getClass()); private volatile CarryonUpdateQuery updateQuery; private volatile CarryonDeleteQuery deleteQuery; private volatile CarryonBlobUpdate addBlobQuery; private volatile CarryonDefaultAddQuery addDefQuery; private volatile CarryonDefaultDeleteQuery deleteDefQuery; //private volatile PhotoQuery pQuery; //private volatile PhotoOneQuery oneQuery; //private volatile CarryonQuery cQuery; //private volatile CarryonDefaultQuery defaultQuery; //private volatile CarryonByCategoryQuery getQuery; //private volatile CarryonBlobDataQuery getBlobDataQuery; //private volatile PhotoTagOneQuery photoTagOneQuery; //private volatile PhotoTagBizAwareQuery photoTagBizAwareQuery; private volatile BasicQuery pQuery; private volatile BasicQuery photoTagOneQuery; private volatile BasicQuery photoTagBizAwareQuery; private volatile BasicQuery oneQuery; private volatile BasicQuery cQuery; private volatile BasicQuery defaultQuery; private volatile BasicQuery getQuery; private volatile BasicQuery getBlobDataQuery; private volatile BasicQuery CarryonHitsCountQuery; private volatile BasicQuery CarryonHitsEntryExistsQuery; private volatile BasicQuery getRecentQuery; private volatile CarryonTagsAddQuery addTagsQuery; private volatile CarryonTagsUpdateQuery updateTagsQuery; private volatile CarryonTagsQuery tagsQuery; private volatile CarryonTagsAllQuery tagsAllQuery; private volatile CarryonEntryIdQuery entryIdQuery; // private volatile CarryonTagsCaptionUpdateQuery updateTagsCaptionQuery; /* for caption update only */ private volatile CarryonTagCaptionUpdateQuery carryonTagCaptionUpdateQuery; private volatile CarryonUpdateCaptionQuery updateCaptionQuery; /** delete in a transaction */ private volatile CarryonDeleteEntryQuery deleteCarryonQuery; private volatile CarryonTagsDeleteQuery deleteTagsQuery; private volatile CarryonHitsQuery getCarryonHitsQuery; private volatile CarryonIncrementHitsQuery incrementHitsQuery; private volatile CarryonHitsAddQuery addCarryonHitsQuery; private volatile CarryonHitsDeleteQuery deleteCarryonHitsQuery; private volatile CarryonHitsDeleteEntryQuery deleteCarryonHitsEntryQuery; private volatile CarryonHitsMinQuery getCarryonMinHitsQuery; private volatile CarryonHitsUpdateTitleQuery updateTitleCarryonHitsQuery; private volatile CarryonHitsUpdateQuery updateCarryonHitsQuery; private volatile CarryonHitsBizAwareQuery getCarryonHitsBizAwareQuery; private volatile CarryonRecentAddQuery addRecentQuery; private volatile CarryonRecentDeleteQuery deleteRecentQuery; private volatile CarryonRecentUpdateQuery updateRecentQuery; // private volatile CarryonRecentQuery getRecentQuery; private static int NUM_ROWS = 50; /** * Given a loginid and category return the carryon blobs with data * @param loginid - the login id * @param category - the category * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public List getCarryonBlobs(String loginid, String category, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginid) || RegexStrUtil.isNull(category)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the list stream blobs already set in the cache * If it exists, return the list from the cache. */ /** * Set the jdbc source from scalability */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteBlobScalability(loginid); } else { sourceName = scalabilityManager.getReadBlobScalability(loginid); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for " + sourceName); } // get carryon information List pResult = null; Object[] params = { (Object) loginid, (Object) category }; try { pResult = getBlobDataQuery.execute(params); if (pResult != null && pResult.size() > 0) { Photo photo = (Photo) pResult.get(0); if (photo != null) { if (WebUtil.isSanEnabled()) { logger.info("san is enabled"); Hdlogin hdlogin = getLogin(loginid); if (hdlogin != null) { logger.info("setting the blob from file"); photo.setBlob(getSanBlobCarryon(hdlogin.getValue(DbConstants.LOGIN), photo.getValue(DbConstants.BTITLE))); } } } } } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing getCarryonBlobs() "); sb.append(getBlobDataQuery.getSql()); sb.append("params (2) "); sb.append(params[0]); sb.append(params[1]); throw new BaseDaoException(sb.toString(), e); } return pResult; } /** * Given a loginid and category return the carryon blobs without the data * @param loginid - the login id * @param category - the category * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public List getCarryonByCategory(String loginid, String category, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginid) || RegexStrUtil.isNull(category)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the list stream blobs already set in the cache * If it exists, return the list from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOBS_CAT); StringBuffer buf = new StringBuffer(loginid); buf.append("-"); buf.append(category); String key = buf.toString(); Object obj = treeCache.get(fqn, key); if (obj != null) { return (List) obj; } /** * Set the jdbc source from scalability */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteBlobScalability(loginid); } else { sourceName = scalabilityManager.getReadBlobScalability(loginid); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for " + sourceName); } // get carryon information List pResult = null; Object[] params = { (Object) loginid, (Object) category }; try { pResult = getQuery.execute(params); } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing carryonbycategory() "); sb.append(getQuery.getSql()); sb.append("params (2) "); sb.append(params[0]); sb.append(params[1]); throw new BaseDaoException(sb.toString(), e); } if ((pResult != null) && (pResult.size() > 0)) { treeCache.put(fqn, key, pResult); } return pResult; } /** * Given a loginid and category return the carryon tags * @param loginid - the login id * @param accessFlag - the access flag * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public List getTags(String loginId, int accessFlag) { if (RegexStrUtil.isNull(loginId)) { throw new BaseDaoException("params (loginId) is null"); } /** * carryon tags are not partitioned */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for " + sourceName); } List tagResult = null; try { Object[] myparams = { (Object) loginId }; tagResult = tagsAllQuery.execute(myparams); } catch (Exception e) { StringBuffer sb = new StringBuffer( "error occured while executing carryontag Query() " + tagsAllQuery.getSql()); throw new BaseDaoException(sb.toString(), e); } return tagResult; } /** * Given a login return the list of stream blobs * @param loginid - the loginid * @param accessFlag - the source to get information from * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect * @return List */ public List getCarryon(String loginid, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginid)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the list stream blobs already set in the cache * If it exists, return the list from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB); Object obj = treeCache.get(fqn, loginid); if (obj != null) { return (List) obj; } Object[] params = { (Object) loginid }; List pResult = null; /** * Set the jdbc source from scalability **/ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteBlobScalability(loginid); } else { sourceName = scalabilityManager.getReadBlobScalability(loginid); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for " + sourceName); } // get carryon information try { pResult = pQuery.execute(params); } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing getCarryon() "); sb.append(pQuery.getSql()); sb.append("params (1) "); sb.append(params[0]); throw new BaseDaoException(sb.toString(), e); } if ((pResult != null) && (pResult.size() > 0)) { treeCache.put(fqn, loginid, pResult); } return pResult; } /** * This method returns all the information about the entry except the blob stream * @param entryid * @param loginid * @return List * @throws BaseDaoException */ public Photo getCarryon(String entryid, String loginid) throws BaseDaoException { if (RegexStrUtil.isNull(loginid) || RegexStrUtil.isNull(entryid)) { throw new BaseDaoException("params are null"); } /** Jboss methods * key is generated for stream blob with (loginid + entryid) * fqn - full qualified name * check if the list stream blobs already set in the cache * If it exists, return the list from the cache. */ Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_ENTRY); StringBuffer buf = new StringBuffer(loginid); buf.append("-"); buf.append(entryid); String key = buf.toString(); Object obj = treeCache.get(fqn, key); if (obj != null) { return (Photo) obj; } Object[] params = { (Object) entryid }; List result = null; List tagResult = null; String sourceName = scalabilityManager.getReadBlobScalability(loginid); this.ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } // get carryon information without the blob try { //cQuery = new CarryonQuery(ds); result = cQuery.execute(params); Object[] myparams = { (Object) loginid, (Object) entryid }; tagResult = tagsQuery.execute(myparams); } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing CarryonQuery() for "); sb.append(cQuery.getSql()); sb.append(" params (0) entryid = "); sb.append(entryid); sb.append(" for loginid = "); sb.append(loginid); throw new BaseDaoException(sb.toString(), e); } /** * add it to cache, based on the key */ if ((result != null) && (result.size() > 0)) { if ((tagResult != null) && (tagResult.size() > 0)) { if (result.get(0) != null && tagResult.get(0) != null) { ((Photo) result.get(0)).setValue(DbConstants.USER_TAGS, ((Photo) tagResult.get(0)).getValue(DbConstants.USER_TAGS)); } } treeCache.put(fqn, key, (Photo) result.get(0)); return (Photo) result.get(0); } return null; } /** * add user stream blobs in carryon. * @param bsize - stream blob size * @param category - category of this stream blob * @param mimetype - the mime type of this stream blob * @param btitle - stream blob title * @param blob - the stream blob byte array data * @param zoom - the zoom * @param memberId - the member id to whom this blob belongs to * @param usertags - the usertags * @param caption - the caption * @param displayPhotos - photos are published * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void addCarryon(long bsize, String category, String mimetype, String btitle, byte[] blob, int zoom, String memberId, String member, String usertags, String caption, boolean displayPhotos) throws BaseDaoException { if (RegexStrUtil.isNull(memberId) || RegexStrUtil.isNull(mimetype) || RegexStrUtil.isNull(btitle) || RegexStrUtil.isNull(member) || (bsize == 0) || (blob == null) || (blob.length == 0) || (zoom < 0) || (zoom > 200) || RegexStrUtil.isNull(category)) { throw new BaseDaoException("params are null"); } int catVal = new Integer(category).intValue(); if (catVal < GlobalConst.categoryMinSize || catVal > GlobalConst.categoryMaxSize) { throw new BaseDaoException("category values are incorrect, " + catVal); } /** * Set the source based on scalability **/ String sourceName = scalabilityManager.getWriteBlobScalability(memberId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } Connection conn = null; List entryIdResult = null; try { conn = ds.getConnection(); if (RegexStrUtil.isNull(caption)) { caption = btitle; } if (WebUtil.isSanEnabled()) { byte[] noBlob = { ' ' }; logger.info("isSanEnabled(), not adding blob"); addBlobQuery.run(conn, noBlob, catVal, mimetype, btitle, memberId, bsize, zoom, caption); } else { logger.info("adding blob query"); addBlobQuery.run(conn, blob, catVal, mimetype, btitle, memberId, bsize, zoom, caption); } conn.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); entryIdResult = entryIdQuery.run(conn, memberId); } catch (Exception e) { StringBuffer sb = new StringBuffer( "error occured while executing in Carryon, addBlob(), params (8) including blob category = "); sb.append(category); sb.append(" mimetype= "); sb.append(mimetype); sb.append(" btitle= "); sb.append(btitle); sb.append(" memberId= "); sb.append(memberId); sb.append(" bsize= "); sb.append(bsize); sb.append(" zoom = "); sb.append(zoom); try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException(sb.toString(), e1); } throw new BaseDaoException(sb.toString(), e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.commit() error for addBlobQuery", e); } /** * Data connection for non partioned table */ sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } boolean addHitsEntry = false; try { conn = ds.getConnection(); if (entryIdResult != null && entryIdResult.size() > 0) { if ((Photo) entryIdResult.get(0) != null) { String entryId = ((Photo) entryIdResult.get(0)).getValue(DbConstants.ENTRYID); addTagsQuery.run(conn, memberId, usertags, caption, entryId, catVal); /* just add the entries if there are less than 10 entries in the top10 */ if (displayPhotos && (catVal != DbConstants.FILE_CATEGORY_INT)) { List numRowsList = getCarryonHits(); if (numRowsList != null && numRowsList.size() < NUM_ROWS) { addCarryonHitsQuery.run(conn, memberId, entryId, caption, "0"); addHitsEntry = true; } } addRecentQuery.run(conn, memberId, entryId, catVal, btitle, mimetype, bsize, zoom, caption); } } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error addTagQuery/addCarryonHitsQuery failed", e1); } throw new BaseDaoException("addTagQuery/addCarryonHitsQuery failed", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error for addTagsQuery/addCarryonHits", e); } if (WebUtil.isSanEnabled()) { try { SanUtils sanUtils = new SanUtils(); sanUtils.addSanFile(member, btitle, SanConstants.sanUserPath, blob); } catch (SanException e) { throw new BaseDaoException("addSanFile, CarryonDaoDb error," + member + " " + btitle + e); } } /** * delete it from cache, get the new list */ Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } if (addHitsEntry) { fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); if (treeCache.exists(fqn, DbConstants.TOP_CARRYON)) { treeCache.remove(fqn, DbConstants.TOP_CARRYON); } } fqn = cacheUtil.fqn(DbConstants.RECENT_CARRYON); if (treeCache.exists(fqn, DbConstants.RECENT_CARRYON)) { treeCache.remove(fqn, DbConstants.RECENT_CARRYON); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, member)) { treeCache.remove(fqn, member); } fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOBS_CAT); StringBuffer buf = new StringBuffer(memberId); buf.append("-"); buf.append(category); String key = buf.toString(); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } } /** * Given a entryid, delete carryon info for the user. * @param entryid - the entry id * @param memberId - the member id * @param category - the category * @param member - the member * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void deleteCarryon(String entryid, String memberId, String category, String member) throws BaseDaoException { if (RegexStrUtil.isNull(memberId) || RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(member)) { throw new BaseDaoException("null parameters passed"); } if (WebUtil.isSanEnabled()) { Photo photo = getPhoto(memberId, entryid, DbConstants.READ_FROM_SLAVE); String btitle = null; if (photo != null) { btitle = photo.getValue(DbConstants.BTITLE); } try { SanUtils sanUtils = new SanUtils(); sanUtils.deleteSanFile(member, SanConstants.sanUserPath, btitle); } catch (SanException e) { throw new BaseDaoException("deleteSanFile() in CarryonDaoDb " + member + " destFileName " + btitle, e); } } /** * Set the source based on scalability */ String sourceName = scalabilityManager.getWriteBlobScalability(memberId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } boolean exists = false; try { Object[] params = { (Object) entryid }; List result = defaultQuery.execute(params); if (result != null && result.size() > 0) { exists = true; } } catch (Exception e) { throw new BaseDaoException("error while" + defaultQuery.getSql()); } /** * if this is a default blob, delete blob and default entry in a transaction * if this is anot a default blob, delete the blob in the regular way. */ if (exists) { Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); deleteCarryonQuery.run(conn, entryid, memberId); deleteDefQuery.run(conn, memberId); } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException( "error in deleting carryon entry, conn.close() while deleting carryonentry in transaction" + member + " entryid = " + entryid, e2); } throw new BaseDaoException( "error in rollback() carryon delete entry" + member + " entryid = " + entryid, e1); } throw new BaseDaoException("error in carryondelete entry" + member + " entryid = " + entryid, e); } try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("commit exception", e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { try { if (conn != null) { conn.close(); } } catch (Exception e5) { throw new BaseDaoException("connection close exception", e5); } throw new BaseDaoException("setAutoCommit(true)/connection close exception", e4); } } else { // not a default entry try { deleteQuery.run(entryid, memberId); } catch (Exception e) { StringBuffer sb = new StringBuffer( "error occured while executing in CarryonDeleteQuery(), entryid = "); sb.append(entryid); sb.append(" memberId = "); sb.append(memberId); throw new BaseDaoException(sb.toString(), e); } } /* remove this entry from carryon hits, if this entry exists */ try { deleteCarryonHits(entryid, memberId); } catch (Exception e) { throw new BaseDaoException("deleteCarryonHits error"); } /** * deleteTagsQuery */ sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } try { deleteTagsQuery.run(memberId, entryid); deleteRecentQuery.run(memberId, entryid); } catch (Exception e) { throw new BaseDaoException("deleteTagsQuery error " + deleteTagsQuery.getSql() + " recent Query = " + deleteRecentQuery.getSql(), e); } /** * remove from userstreamblob based on the key (memberId+entryid) */ StringBuffer sb = new StringBuffer(memberId); sb.append("-"); sb.append(entryid); String key = sb.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_ENTRY); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_DATA); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.RECENT_CARRYON); if (treeCache.exists(fqn, DbConstants.RECENT_CARRYON)) { treeCache.remove(fqn, DbConstants.RECENT_CARRYON); } /* remove all entries for this user, key based on memberId */ fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } /** * get stream blobs */ fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOBS_CAT); sb.delete(0, sb.length()); sb.append(memberId); sb.append("-"); sb.append(category); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, member)) { treeCache.remove(fqn, member); } } /** * updates caption for the blob in carryon. * @param btitle - the btitle * @param zoom - zoom applies to photos * @param entryid - the entry id * @param memberId - the member id * @param category - the category * @param member - the member * @param def - the default * @param usertags - usertags * @param caption - caption * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void updateCaption(String btitle, String zoom, String entryid, String memberId, String category, String member, boolean def, String usertags, String caption) throws BaseDaoException { if (RegexStrUtil.isNull(memberId) || RegexStrUtil.isNull(btitle) || RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(member)) { throw new BaseDaoException("null parameters passed"); } boolean isFile = true; // zoom applies only to photos currently if ((category != null) && (category.equalsIgnoreCase("1"))) { isFile = false; if (RegexStrUtil.isNull(zoom)) { throw new BaseDaoException("zoom parameter is null"); } } /** * Set the source based on scalability */ String sourceName = scalabilityManager.getWriteBlobScalability(memberId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } boolean exists = false; try { Object[] params = { (Object) entryid }; List result = defaultQuery.execute(params); if (result != null && result.size() > 0) { exists = true; } } catch (Exception e) { throw new BaseDaoException("error while" + defaultQuery.getSql()); } if (WebUtil.isSanEnabled()) { Photo photo = getPhoto(memberId, entryid, DbConstants.READ_FROM_SLAVE); if (photo != null) { String srcFileName = photo.getValue(DbConstants.BTITLE); if (!RegexStrUtil.isNull(srcFileName) && !srcFileName.equals(btitle)) { try { SanUtils sanUtils = new SanUtils(); sanUtils.renameSanFile(member, SanConstants.sanUserPath, srcFileName, btitle); } catch (SanException e) { throw new BaseDaoException("renameSanFile() in CarryonDaoDb " + member + " srcFileName " + srcFileName + " destFileName " + btitle, e); } } } } Connection conn = null; try { conn = ds.getConnection(); if (conn != null) { /* delete the photo, if this entry exists */ conn.setAutoCommit(false); if (RegexStrUtil.isNull(caption)) { caption = btitle; } updateQuery.run(conn, btitle, zoom, entryid, memberId, isFile, caption); /** if this is the default photo and this photo does not exist, add this entry */ if (def) { if (!exists) { deleteDefQuery.run(conn, memberId); addDefQuery.run(conn, entryid, memberId); } } else { /** no more a default photo, delete this entry */ if (exists) { deleteDefQuery.run(conn, memberId); } } } } catch (Exception e) { try { conn.rollback(); } catch (Exception e1) { try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e2) { throw new BaseDaoException("connection close exception", e2); } throw new BaseDaoException("error occured while rollingback entries from carryon/defcarryon", e1); } } try { conn.commit(); } catch (Exception e3) { throw new BaseDaoException("commit exception", e3); } try { if (conn != null) { conn.setAutoCommit(true); conn.close(); } } catch (Exception e4) { throw new BaseDaoException("connection close exception", e4); } // update the blob title updateTitleCarryonHits(entryid, memberId, caption); /** * updateTags */ sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } conn = null; try { conn = ds.getConnection(); if (conn != null) { updateTagsQuery.run(conn, caption, entryid, memberId, usertags); updateRecentQuery.run(conn, btitle, zoom, entryid, memberId, isFile, caption); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("connection close exception for updateTagsQuery()", e1); } StringBuffer sb = new StringBuffer("error occured while executing in updateCaption() caption = "); sb.append(caption); sb.append(" zoom = "); sb.append(zoom); sb.append(" entryid = "); sb.append(entryid); sb.append(" memberId = "); sb.append(memberId); throw new BaseDaoException(sb.toString(), e); } // close the connection try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("connection close exception", e1); } /** * remove from userstreamblob based on the key (memberId+entryid) */ StringBuffer sb = new StringBuffer(memberId); sb.append("-"); sb.append(entryid); String key = sb.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_ENTRY); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_DATA); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } /** * uses memberid-category key */ sb.delete(0, sb.length()); sb.append(memberId); sb.append("-"); sb.append(category); fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOBS_CAT); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } /** * remove all entries for this user, key based on memberId */ fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, member)) { treeCache.remove(fqn, member); } fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } /* remove this from cache only when the blogger matches one of the recent blog entry matches */ /* Fqn fqn = cacheUtil.fqn(DbConstants.RECENT_BLOGS); if (treeCache.exists(fqn, DbConstants.RECENT_BLOG_KEY)) { treeCache.remove(fqn, DbConstants.RECENT_BLOG_KEY); } */ } /** * This method returns a blob data and the entire blob stream information given the entryid * @param entryid - the entryid * @param loginid - the login id * @return Photo - the photo bean * @throws BaseDaoException */ public Photo getOneCarryon(String entryid, String loginid) throws BaseDaoException { if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(loginid)) { throw new BaseDaoException("entryid, is 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. */ StringBuffer buf = new StringBuffer(loginid); buf.append("-"); buf.append(entryid); String key = buf.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_DATA); Object obj = treeCache.get(fqn, key); if (obj != null) { logger.info("getOneCarryon(), getting it from cache" + key); return (Photo) obj; } Object[] params = { (Object) entryid }; List result = null; String sourceName = scalabilityManager.getReadBlobScalability(loginid); this.ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } try { result = oneQuery.execute(params); } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing CarryonQuery() for "); sb.append(oneQuery.getSql()); sb.append(" params (1) entryid = "); sb.append(entryid); sb.append(" loginid = "); sb.append(loginid); throw new BaseDaoException(sb.toString(), e); } if ((result != null) && (result.size() > 0)) { Photo photo = (Photo) result.get(0); if (photo != null) { /** * When san is enabled */ if (WebUtil.isSanEnabled()) { Hdlogin hdlogin = getLogin(loginid); if (hdlogin != null) { photo.setBlob(getSanBlobCarryon(hdlogin.getValue(DbConstants.LOGIN), photo.getValue(DbConstants.BTITLE))); } } treeCache.put(fqn, key, (Photo) result.get(0)); return (Photo) result.get(0); } else { return null; } } else { return null; } } /** * This method updates the carryon hits entry that matches the entryid and memberid * @param entryid - the entryid * @param loginid - the login id * @throws BaseDaoException - when error occurs */ public void updateTitleCarryonHits(String entryid, String memberid, String caption) { if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(memberid)) { throw new BaseDaoException("params are null"); } /** * update the caption if this entry exists in the carryonhits */ boolean exists = false; Fqn fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); Object obj = treeCache.get(fqn, DbConstants.TOP_CARRYON); if (obj != null) { List result = (List) obj; if (result != null && result.size() > 0) { for (int i = 0; i < result.size(); i++) { if ((Photo) result.get(i) != null) { if ((entryid.equals(((Photo) result.get(i)).getValue(DbConstants.ENTRYID))) && (memberid.equals(((Photo) result.get(i)).getValue(DbConstants.LOGIN_ID)))) { exists = true; } } } } } Connection conn = null; if (exists) { /** * Get scalability carryonhits - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, updateTitleCarryonHits " + sourceName); } try { conn = ds.getConnection(); updateTitleCarryonHitsQuery.run(conn, memberid, entryid, caption); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("updateTitleCarryonHits is null", e1); } throw new BaseDaoException("updateTitleCarryonHits is null", e); } fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); if (treeCache.exists(fqn, DbConstants.TOP_CARRYON)) { treeCache.remove(fqn, DbConstants.TOP_CARRYON); } } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("updateTitleCarryonHits is null", e); } } /** * This method deletes the carryon hits entry that matches the entryid and memberid * @param entryid - the entryid * @param loginid - the login id * @throws BaseDaoException - when error occurs */ public void deleteCarryonHits(String entryid, String memberid) { if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(memberid)) { throw new BaseDaoException("params are null"); } /** * delete this entry if it exists in the cache. */ boolean exists = false; Fqn fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); Object obj = treeCache.get(fqn, DbConstants.TOP_CARRYON); if (obj != null) { List result = (List) obj; if (result != null && result.size() > 0) { for (int i = 0; i < result.size(); i++) { if ((Photo) result.get(i) != null) { if ((entryid.equals(((Photo) result.get(i)).getValue(DbConstants.ENTRYID))) && (memberid.equals(((Photo) result.get(i)).getValue(DbConstants.LOGIN_ID)))) { exists = true; } } } } } else { exists = true; } if (!exists) { return; } /** * Get scalability carryonhits - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteCarryonHits " + sourceName); } try { deleteCarryonHitsQuery.run(memberid, entryid); } catch (Exception e) { throw new BaseDaoException("deleteCarryonHits is null" + deleteCarryonHitsQuery.getSql()); } fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); if (treeCache.exists(fqn, DbConstants.TOP_CARRYON)) { treeCache.remove(fqn, DbConstants.TOP_CARRYON); } } /** * This method increments hits for the photo * @param entryid - entryid * @param memberid - memberid * @param btitle - btitle * @param displayPhotos - photos are published * @throws BaseDaoException */ public void incrementCarryonHits(String entryid, String memberid, String btitle, boolean displayPhotos) { if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(memberid)) { throw new BaseDaoException("params are null"); } /** * carryon - partitioned */ String sourceName = scalabilityManager.getWriteBlobScalability(memberid); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, carryon datasource " + sourceName); } boolean entryExists = carryonHitsEntryExists(memberid, entryid); Connection conn = null; if (entryExists) { try { conn = ds.getConnection(); incrementHitsQuery.run(conn, memberid, entryid); } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error in incrementHitsQuery", e1); } throw new BaseDaoException("error in incrementHitsQuery() ", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close error", e); } } int numResultRow = 0; String hits = "0"; try { numResultRow = getCarryonHitsCount(); logger.info("getCarryonHitsCount 2, numrows = " + numResultRow); Photo photo = getCarryon(entryid, memberid); if (photo != null) { hits = photo.getValue(DbConstants.HITS); if (RegexStrUtil.isNull(hits)) { hits = "0"; } } } catch (Exception e) { throw new BaseDaoException("getCarryonHits()/getCarryon() error", e); } /** * Get scalability carryonhits - not partitioned */ sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, incrementCarryonHits " + sourceName); } /** * if there are more than NUM_ROWS entries in the carryonhits table. * check if this entry qualifies to be in the top10 entries. * The number of hits of this entry should be greater * than the minimum hits of the top10 entries * if they are, then delete the existing least hits entry from top10 * add this entry to top10 */ try { conn = ds.getConnection(); if (entryExists) { updateCarryonHitsQuery.run(conn, memberid, entryid, hits); } else { if (numResultRow < NUM_ROWS) { if (displayPhotos) { addCarryonHitsQuery.run(conn, memberid, entryid, btitle, hits); } } else { Photo minResult = getCarryonMinHits(conn, hits); if (minResult != null) { String minMemberId = minResult.getValue(DbConstants.ENTRYID); String minEntryId = minResult.getValue(DbConstants.LOGIN_ID); deleteCarryonHitsQuery.run(minMemberId, minEntryId); if (displayPhotos) { addCarryonHitsQuery.run(conn, memberid, entryid, btitle, hits); } } } } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error in updateCarryonHitsQuery/addCarryonHitsQuery", e1); } throw new BaseDaoException("updateCarryonHitsQuery is null", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close in updateCarryonHitsQuery/addCarryonHitsQuery error", e); } Fqn fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); if (treeCache.exists(fqn, DbConstants.TOP_CARRYON)) { treeCache.remove(fqn, DbConstants.TOP_CARRYON); } } private boolean carryonHitsEntryExists(String loginid, String entryid) { if (RegexStrUtil.isNull(loginid) || RegexStrUtil.isNull(entryid)) { throw new BaseDaoException("params are null"); } /** * Set the jdbc source from scalability */ String queryName = scalabilityManager.getWriteZeroScalability("carryonhitsentryexistsQuery"); CarryonHitsEntryExistsQuery = getQueryMapper().getQuery(queryName); if (CarryonHitsEntryExistsQuery == null) { throw new BaseDaoException("CarryonHitsEntryExistsQuery is null "); } Object[] params = { (Object) entryid, (Object) loginid }; try { List pResult = CarryonHitsEntryExistsQuery.execute(params); if (pResult != null && pResult.size() > 0) { return true; } } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing CarryonHitsEntryExistsQuery() "); sb.append(CarryonHitsEntryExistsQuery.getSql()); throw new BaseDaoException(sb.toString(), e); } return false; } /** * This method returns carryon hits bizaware hits query * @param bid * @param accessFlag * @return List - carryon top entries * @throws BaseDaoException - when error occurs */ public List getCarryonHitsBizAware(String bid, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(bid)) { throw new BaseDaoException("params are null"); } Fqn fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); Object obj = treeCache.get(fqn, DbConstants.TOP_CARRYON); if (obj != null) { return (List) (obj); } /** * Get scalability carryonhits */ String sourceName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { sourceName = scalabilityManager.getWriteZeroScalability(); } else { sourceName = scalabilityManager.getReadZeroScalability(); } ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getCarryonHitsBizAware " + sourceName); } List result = null; Connection conn = null; try { conn = ds.getConnection(); result = getCarryonHitsBizAwareQuery.run(conn, bid); if (result != null && result.size() > 0) { treeCache.put(fqn, DbConstants.TOP_CARRYON, result); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error in getCarryonHitsBizAwareQuery", e1); } throw new BaseDaoException("getCarryonHitsBizAwareQuery error()", e); } return result; } /** * This method returns carryon top hits * @return List - carryon top entries * @throws BaseDaoException - when error occurs */ public List getCarryonHits() { Fqn fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); Object obj = treeCache.get(fqn, DbConstants.TOP_CARRYON); if (obj != null) { return (List) (obj); } /** * Get scalability carryonhits - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, getCarryonHits " + sourceName); } List result = null; Connection conn = null; try { conn = ds.getConnection(); result = getCarryonHitsQuery.run(conn); if (result != null && result.size() > 0) { treeCache.put(fqn, DbConstants.TOP_CARRYON, result); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error in getCarryonHitsQuery", e1); } throw new BaseDaoException("getCarryonHitsQuery error()", e); } try { if (conn != null) { conn.close(); } } catch (Exception e) { throw new BaseDaoException("conn.close() error in getCarryonHitsQuery", e); } return result; } public HashSet getUniqueTags(List photos) { HashSet allSet = new HashSet(); if (photos != null && photos.size() > 0) { for (int i = 0; i < photos.size(); i++) { if ((Photo) photos.get(i) != null) { String usertags = ((Photo) photos.get(i)).getValue(DbConstants.USER_TAGS); String[] yourkeys = usertags.split(","); if (i == 0) { for (int k = 0; k < yourkeys.length; k++) { if (!RegexStrUtil.isNull(yourkeys[k])) { allSet.add(yourkeys[k]); } } } else { HashSet h1 = new HashSet(); for (int k = 0; k < yourkeys.length; k++) { if (!RegexStrUtil.isNull(yourkeys[k])) { h1.add(yourkeys[k]); } } allSet.removeAll(h1); //logger.info("removeAll h1 = " + h1.toString()); //logger.info("removeAll allSet = " + allSet.toString()); allSet.addAll(h1); //logger.info("addAll h1 = " + h1.toString()); //logger.info("addAll allSet = " + allSet.toString()); } //else } //if } // for } // if return allSet; } /** * This method returns a photo bean that is less than the number of hits * @param conn - connection * @param hits - hits * @return Photo - returns a bean that has minimum hits * @throws BaseDaoException - when error occurs */ private Photo getCarryonMinHits(Connection conn, String hits) { Fqn fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); Object obj = treeCache.get(fqn, DbConstants.TOP_CARRYON); if (obj != null) { List result = (List) obj; if (result != null && result.size() > 0) { return ((Photo) result.get(result.size() - 1)); } } if (conn == null || RegexStrUtil.isNull(hits)) { throw new BaseDaoException("conn is null or hits params null"); } try { List result = getCarryonMinHitsQuery.run(conn, hits); if (result != null && result.size() > 0) { return ((Photo) result.get(0)); } } catch (Exception e) { throw new BaseDaoException("error in getCarryonMinHitsQuery", e); } return null; } /** * updates only caption for the blob in carryon. * @param entryid - the entry id * @param memberId - the member id * @param category - the category * @param member - the member * @param caption - caption * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect */ public void updateOnlyCaption(String entryid, String memberId, String category, String member, String caption) throws BaseDaoException { if (RegexStrUtil.isNull(memberId) || RegexStrUtil.isNull(caption) || RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(member)) { throw new BaseDaoException("null parameters passed"); } /** * Set the source based on scalability */ String sourceName = scalabilityManager.getWriteBlobScalability(memberId); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } Connection conn = null; try { conn = ds.getConnection(); if (conn != null) { updateCaptionQuery.run(conn, entryid, memberId, caption); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("conn.close() error in updateCaptionQuery() carryon", e1); } throw new BaseDaoException("error occured in updateCaptionQuery() carryon", e); } try { if (conn != null) { conn.close(); } } catch (Exception e4) { throw new BaseDaoException("connection close exception in updateCaptionQuery", e4); } /** * update only caption for tags */ sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds is null for sourceName = " + sourceName); } conn = null; try { conn = ds.getConnection(); if (conn != null) { carryonTagCaptionUpdateQuery.run(conn, caption, entryid, memberId); } } catch (Exception e) { try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("connection close exception for carryonTagCaptionUpdateQuery()", e1); } StringBuffer sb = new StringBuffer("error occured while executing in updateOnlyCaption() caption = "); sb.append(caption); sb.append(" entryid = "); sb.append(entryid); sb.append(" memberId = "); sb.append(memberId); throw new BaseDaoException(sb.toString(), e); } // close the connection try { if (conn != null) { conn.close(); } } catch (Exception e1) { throw new BaseDaoException("connection close exception", e1); } /** * remove from userstreamblob based on the key (memberId+entryid) */ StringBuffer sb = new StringBuffer(memberId); sb.append("-"); sb.append(entryid); String key = sb.toString(); Fqn fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_ENTRY); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOB_DATA); if (treeCache.exists(fqn, key)) { treeCache.remove(fqn, key); } /** * uses memberid-category key */ sb.delete(0, sb.length()); sb.append(memberId); sb.append("-"); sb.append(category); fqn = cacheUtil.fqn(DbConstants.USER_STREAM_BLOBS_CAT); if (treeCache.exists(fqn, sb.toString())) { treeCache.remove(fqn, sb.toString()); } /** * remove all entries for this user, key based on memberId */ if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } fqn = cacheUtil.fqn(DbConstants.USER_PAGE); if (treeCache.exists(fqn, member)) { treeCache.remove(fqn, member); } fqn = cacheUtil.fqn(DbConstants.DEFAULT_PHOTO); if (treeCache.exists(fqn, memberId)) { treeCache.remove(fqn, memberId); } } /** * This method deletes the carryon hits entry of a memberid * @param loginid - the login id * @throws BaseDaoException - when error occurs */ public void deleteCarryonHits(String memberid) throws BaseDaoException { if (RegexStrUtil.isNull(memberid)) { throw new BaseDaoException("params are null"); } /** * delete this entry if it exists in the cache. */ boolean exists = false; Fqn fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); Object obj = treeCache.get(fqn, DbConstants.TOP_CARRYON); if (obj != null) { List result = (List) obj; if (result != null && result.size() > 0) { for (int i = 0; i < result.size(); i++) { if ((Photo) result.get(i) != null) { if (memberid.equals(((Photo) result.get(i)).getValue(DbConstants.LOGIN_ID))) { exists = true; } } } } } else { exists = true; } if (!exists) { return; } /** * Get scalability carryonhits - not partitioned */ String sourceName = scalabilityManager.getWriteZeroScalability(); ds = scalabilityManager.getSource(sourceName); if (ds == null) { throw new BaseDaoException("ds null, deleteCarryonHitsEntry " + sourceName); } try { deleteCarryonHitsEntryQuery.run(memberid); } catch (Exception e) { throw new BaseDaoException("deleteCarryonHitsEntry is null" + deleteCarryonHitsEntryQuery.getSql()); } fqn = cacheUtil.fqn(DbConstants.TOP_CARRYON); if (treeCache.exists(fqn, DbConstants.TOP_CARRYON)) { treeCache.remove(fqn, DbConstants.TOP_CARRYON); } } /** * Given a loginid, entryid return the photo and tags without blob data.h * @param loginid - the loginid * @param entryid - the entryid * @param accessFlag - the accessFlag * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect * @return Photo */ public Photo getPhoto(String loginid, String entryid, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginid) || RegexStrUtil.isNull(entryid)) { throw new BaseDaoException("params are null"); } /** Jboss methods * fqn - full qualified name * check if the list stream blobs already set in the cache * If it exists, return the list from the cache. */ /* Fqn fqn = cacheUtil.fqn(DbConstants.USER_PHOTO_BLOB); Object obj = treeCache.get(fqn, loginid); if (obj != null) { return (List)obj; } */ /** * Set the jdbc source from scalability */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteBlobScalability(loginid, "phototagoneQuery"); } else { queryName = scalabilityManager.getReadBlobScalability(loginid, "phototagoneQuery"); } photoTagOneQuery = getQueryMapper().getQuery(queryName); if (photoTagOneQuery == null) { throw new BaseDaoException("photoTagOneQuery is null "); } Object[] params = { (Object) entryid, (Object) loginid }; List pResult = null; // get carryon information try { pResult = photoTagOneQuery.execute(params); } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing getCarryon() "); sb.append(photoTagOneQuery.getSql()); sb.append("entryid="); sb.append(params[0]); sb.append("loginid="); sb.append(params[1]); throw new BaseDaoException(sb.toString(), e); } /* if ((pResult != null) && (pResult.size() > 0)) { treeCache.put(fqn, loginid, pResult); } */ if ((pResult != null) && (pResult.size() > 0)) { return (Photo) pResult.get(0); } else { return null; } } /** * Given bid, loginid, entryid return the photo and tags without blob data.h * @param bid - the bid * @param loginid - the loginid * @param entryid - the entryid * @param accessFlag - the accessFlag * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect * @return Photo */ public Photo getPhotoBizAware(String bid, String loginid, String entryid, int accessFlag) throws BaseDaoException { if (RegexStrUtil.isNull(loginid) || RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(bid)) { throw new BaseDaoException("params are null"); } /** * Set the jdbc source from scalability */ String queryName = null; if (accessFlag == DbConstants.READ_FROM_MASTER) { queryName = scalabilityManager.getWriteBlobScalability(loginid, "phototagbizawareQuery"); } else { queryName = scalabilityManager.getReadBlobScalability(loginid, "phototagbizawareQuery"); } photoTagBizAwareQuery = getQueryMapper().getQuery(queryName); if (photoTagBizAwareQuery == null) { throw new BaseDaoException("photoTagBizAwareQuery is null "); } // get carryon information Object[] params = { (Object) entryid, (Object) loginid, (Object) bid }; List pResult = null; try { pResult = photoTagBizAwareQuery.execute(params); } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing getPhotoTagBizAwareQuery() "); sb.append(photoTagBizAwareQuery.getSql()); sb.append("entryid="); sb.append(params[0]); sb.append(" loginid="); sb.append(params[1]); sb.append(" bid="); sb.append(params[2]); throw new BaseDaoException(sb.toString(), e); } /* if ((pResult != null) && (pResult.size() > 0)) { treeCache.put(fqn, loginid, pResult); } */ if ((pResult != null) && (pResult.size() > 0)) { return (Photo) pResult.get(0); } else { return null; } } /** * @param accessFlag - the accessFlag * @throws BaseDaoException If we have a problem interpreting the data * @return int */ private int getCarryonHitsCount() throws BaseDaoException { /** * Set the jdbc source from scalability */ String queryName = scalabilityManager.getWriteZeroScalability("carryonhitscountQuery"); CarryonHitsCountQuery = getQueryMapper().getQuery(queryName); if (CarryonHitsCountQuery == null) { throw new BaseDaoException("CarryonHitsCountQuery is null "); } try { List pResult = CarryonHitsCountQuery.execute(); if (pResult != null && pResult.size() > 0) { if (!RegexStrUtil.isNull(((Photo) pResult.get(0)).getValue(DbConstants.COUNT_SUM))) { return (new Integer(((Photo) pResult.get(0)).getValue(DbConstants.COUNT_SUM)).intValue()); } } } catch (Exception e) { StringBuffer sb = new StringBuffer("error occured while executing CarryonHitsCountQuery() "); sb.append(CarryonHitsCountQuery.getSql()); throw new BaseDaoException(sb.toString(), e); } return 0; } /** * Return carryon recent entries * @param accessFlag - the access flag * @throws BaseDaoException problem interpreting the data or the data is missing or incorrect */ public List getRecentCarryon(int accessFlag, String category) { if (RegexStrUtil.isNull(category)) { throw new BaseDaoException("params (category) is null"); } String queryName = scalabilityManager.getWriteZeroScalability("carryonrecentQuery"); getRecentQuery = getQueryMapper().getQuery(queryName); if (getRecentQuery == null) { throw new BaseDaoException("getRecentQuery is null "); } try { Object[] myparams = { (Object) category }; return (getRecentQuery.execute(myparams)); } catch (Exception e) { StringBuffer sb = new StringBuffer( "error occured while executing getRecentQuery() " + getRecentQuery.getSql()); throw new BaseDaoException(sb.toString(), e); } } /** * getSanBlobCarryon - should work on if san is enabled * @param login - user login * @param btitle - btitle * @return byte[] - byte stream */ public byte[] getSanBlobCarryon(String login, String btitle) { if (WebUtil.isSanEnabled()) { if (RegexStrUtil.isNull(login) || RegexStrUtil.isNull(btitle)) { throw new BaseDaoException("params are null"); } try { FileSystemImpl fApi = new FileSystemImpl(); if (fApi != null) { return fApi.readFile(login, SanConstants.sanUserPath, btitle); } } catch (SanException e) { throw new BaseDaoException("readFile(), getSanBlobCarryon error", e); } } else { throw new BaseDaoException("san is not enabled, but is trying to retrieve it from SAN."); } return null; } /** * This property is setby spring automatically at web.xml startup * @param ds - this is JDBC datasource bean that is connection from the pool */ public void setJdbcSource(DataSource ds) { this.ds = ds; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcarryonupdateQuery(CarryonUpdateQuery daq) { this.updateQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcarryonbycategoryQuery(BasicQuery daq) { this.getQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setphotooneQuery(BasicQuery daq) { this.oneQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setphotoQuery(BasicQuery daq) { this.pQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcarryonQuery(BasicQuery daq) { this.cQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcarryondeleteQuery(CarryonDeleteQuery daq) { this.deleteQuery = daq; } /** * This property is setby spring automatically at web.xml startup. * @param daq */ public void setcarryonblobUpdate(CarryonBlobUpdate daq) { this.addBlobQuery = daq; } public void setcarryonblobdataQuery(BasicQuery daq) { this.getBlobDataQuery = daq; } public void setcarryonadddefaultQuery(CarryonDefaultAddQuery daq) { this.addDefQuery = daq; } public void setpersonaldefaultdeleteQuery(CarryonDefaultDeleteQuery daq) { this.deleteDefQuery = daq; } public void setcarryondefaultQuery(BasicQuery daq) { this.defaultQuery = daq; } public void setdeletecarryonQuery(CarryonDeleteEntryQuery daq) { this.deleteCarryonQuery = daq; } public void setcarryontagsaddQuery(CarryonTagsAddQuery daq) { this.addTagsQuery = daq; } public void setcarryontagsupdateQuery(CarryonTagsUpdateQuery daq) { this.updateTagsQuery = daq; } public void setcarryontagsQuery(CarryonTagsQuery daq) { this.tagsQuery = daq; } public void setcarryonalltagsQuery(CarryonTagsAllQuery daq) { this.tagsAllQuery = daq; } public void setcarryontagsdeleteQuery(CarryonTagsDeleteQuery daq) { this.deleteTagsQuery = daq; } public void setcarryonentryidQuery(CarryonEntryIdQuery daq) { this.entryIdQuery = daq; } /* carryon hits */ public void setcarryonhitsQuery(CarryonHitsQuery daq) { this.getCarryonHitsQuery = daq; } public void setcarryonincrementhitsQuery(CarryonIncrementHitsQuery daq) { this.incrementHitsQuery = daq; } public void setcarryonhitsaddQuery(CarryonHitsAddQuery daq) { this.addCarryonHitsQuery = daq; } public void setcarryonhitsdeleteQuery(CarryonHitsDeleteQuery daq) { this.deleteCarryonHitsQuery = daq; } public void setcarryonhitsdeleteentryQuery(CarryonHitsDeleteEntryQuery daq) { this.deleteCarryonHitsEntryQuery = daq; } public void setcarryonminhitsQuery(CarryonHitsMinQuery daq) { this.getCarryonMinHitsQuery = daq; } public void setcarryonhitsupdatetitleQuery(CarryonHitsUpdateTitleQuery daq) { this.updateTitleCarryonHitsQuery = daq; } public void setupdatecarryonhitsQuery(CarryonHitsUpdateQuery daq) { this.updateCarryonHitsQuery = daq; } public void setcarryonhitsbizawareQuery(CarryonHitsBizAwareQuery daq) { this.getCarryonHitsBizAwareQuery = daq; } public void setcarryoncaptionupdateQuery(CarryonUpdateCaptionQuery daq) { this.updateCaptionQuery = daq; } public void setcarryontagcaptionupdateQuery(CarryonTagCaptionUpdateQuery daq) { this.carryonTagCaptionUpdateQuery = daq; } public void setcarryonrecentaddQuery(CarryonRecentAddQuery daq) { this.addRecentQuery = daq; } public void setcarryonrecentdeleteQuery(CarryonRecentDeleteQuery daq) { this.deleteRecentQuery = daq; } public void setcarryonrecentupdateQuery(CarryonRecentUpdateQuery daq) { this.updateRecentQuery = daq; } }