dao.CobrandDaoDb.java Source code

Java tutorial

Introduction

Here is the source code for dao.CobrandDaoDb.java

Source

/**
* 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.List;
import javax.sql.DataSource;
import model.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import util.DbConstants;
import util.RegexStrUtil;

/**
 * <B>CobrandDaoDb</B>
 * <BR>
 *  This object implements CobrandDao
 *  These objects are retrieved from the database
 *  @author Smitha Gudur 
 */
public class CobrandDaoDb extends BaseDao implements CobrandDao {

    private int rowIndex = 0;
    protected final Log logger = LogFactory.getLog(getClass());

    private volatile UserAddCobrandQuery addUserQuery;
    private volatile UserDeleteCobrandQuery deleteUserQuery;
    private volatile UserCobrandUpdateFooterQuery updateUserFooterQuery;
    private volatile UserCobrandUpdateHeaderQuery updateUserHeaderQuery;

    //private volatile UserCobrandQuery userCobrandQuery; 
    //private volatile UserFooterCobrandQuery getUserFooterCobrandQuery; 
    //private volatile UserHeaderCobrandQuery getUserHeaderCobrandQuery; 

    private volatile BasicQuery userCobrandQuery;
    private volatile BasicQuery getUserFooterCobrandQuery;
    private volatile BasicQuery getUserHeaderCobrandQuery;

    private volatile DirAddCobrandQuery addDirQuery;
    private volatile DirCobrandUpdateFooterQuery updateDirFooterQuery;
    private volatile DirCobrandUpdateHeaderQuery updateDirHeaderQuery;
    private volatile DirectoryDeleteCobrandQuery deleteDirectoryQuery;

    //private volatile DirectoryCobrandQuery dirCobrandQuery; 
    //private volatile DirHeaderCobrandQuery getDirHeaderQuery;
    //private volatile DirFooterCobrandQuery getDirFooterQuery;

    private volatile BasicQuery dirCobrandQuery;
    private volatile BasicQuery getDirHeaderQuery;
    private volatile BasicQuery getDirFooterQuery;

    private volatile CollabrumAddCobrandQuery addCollQuery;
    private volatile CollabrumDeleteCobrandQuery deleteCollQuery;
    private volatile ColCobrandUpdateFooterQuery updateCollFooterQuery;
    private volatile ColCobrandUpdateHeaderQuery updateCollHeaderQuery;

    //private volatile CollabrumCobrandQuery collCobrandQuery; 
    //private volatile ColHeaderCobrandQuery getColHeaderCobrandQuery;
    //private volatile ColFooterCobrandQuery getColFooterCobrandQuery;

    private volatile BasicQuery collCobrandQuery;
    private volatile BasicQuery getColHeaderCobrandQuery;
    private volatile BasicQuery getColFooterCobrandQuery;

    /**
     *  getUserCobrand method - gets the cobranding information for this user and sets it in the userpage
     *  @param loginid - the login id
     *  @return Userpage - the cobranding information for this userpage
     *  @throws BaseDaoException - when error occurs
     */
    public Userpage getUserCobrand(String loginid) throws BaseDaoException {

        if (RegexStrUtil.isNull(loginid)) {
            throw new BaseDaoException("params are null");
        }

        Fqn fqn = cacheUtil.fqn(DbConstants.USER_COBRAND);
        Object obj = treeCache.get(fqn, loginid);
        if (obj != null) {
            return (Userpage) obj;
        }

        /**
         *  Get scalability datasource for partitioned on loginid
         */
        String sourceName = scalabilityManager.getWriteScalability(loginid);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, UserpageDao getCobrand() " + sourceName);
        }
        try {
            Object[] params = { (Object) loginid };
            List result = userCobrandQuery.execute(params);
            if ((result != null) && (result.size() > 0)) {
                treeCache.put(fqn, loginid, result.get(0));
                return (Userpage) result.get(0);
            }
        } catch (Exception e) {
            throw new BaseDaoException("UserpageDao, get userCobrandQuery() " + userCobrandQuery.getSql(), e);
        }
        return null;
    }

    /**
     *  getDirCobrand method - gets the cobranding information for this directory 
     *  @param directoryId - the directory id
     *  @return Directory - the cobranding information of this directory
     *  @throws BaseDaoException - when error occurs
     */
    public Directory getDirCobrand(String directoryId) throws BaseDaoException {

        if (RegexStrUtil.isNull(directoryId)) {
            throw new BaseDaoException("params are null");
        }

        Fqn fqn = cacheUtil.fqn(DbConstants.DIR_COBRAND);
        Object obj = treeCache.get(fqn, directoryId);
        if (obj != null) {
            return (Directory) obj;
        }

        /**
         *  Get scalability datasource for partitioned on directoryid
         */
        String sourceName = scalabilityManager.getWriteScalability(directoryId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, Directory getCobrand() " + sourceName);
        }
        try {
            Object[] params = { (Object) directoryId };
            List result = dirCobrandQuery.execute(params);
            if ((result != null) && (result.size() > 0)) {
                treeCache.put(fqn, directoryId, result.get(0));
                return (Directory) result.get(0);
            }
        } catch (Exception e) {
            throw new BaseDaoException("Directory, get dirCobrandQuery() " + dirCobrandQuery.getSql(), e);
        }
        return null;
    }

    /**
     *  getCollCobrand method - gets the cobranding information for this collabrum and sets it in the collabrum
     *  @param collabrumId - the collabrumid
     *  @return collabrum - the collabrum cobranded bean
     *  @throws BaseDaoException - when error occurs
     */
    public Collabrum getCollCobrand(String collabrumId) throws BaseDaoException {

        if (RegexStrUtil.isNull(collabrumId)) {
            throw new BaseDaoException("params are null");
        }

        Fqn fqn = cacheUtil.fqn(DbConstants.COLL_COBRAND);
        Object obj = treeCache.get(fqn, collabrumId);
        if (obj != null) {
            return (Collabrum) obj;
        }

        /**
         *  Get scalability datasource for cobranded collabrum
         */
        String sourceName = scalabilityManager.getWriteScalability(collabrumId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, Collabrum getCobrand() " + sourceName);
        }
        try {
            Object[] params = { (Object) collabrumId };
            List result = collCobrandQuery.execute(params);
            if ((result != null) && (result.size() > 0)) {
                treeCache.put(fqn, collabrumId, result.get(0));
                return ((Collabrum) result.get(0));
            }
        } catch (Exception e) {
            throw new BaseDaoException("CollabrumDao, get collCobrandQuery() " + collCobrandQuery.getSql(), e);
        }
        return null;
    }

    /**
     *  addUserCobrand method - adds the cobranding information for user/star 
     *  @param blob - the byte array
     *  @param ftype - the file type (header or footer)
     *  @param loginid - the loginid
     *  @param login - the login
     *  @throws BaseDaoException - when error occurs
     */
    public void addUserCobrand(byte[] blob, String ftype, String loginid, String login) throws BaseDaoException {

        if (blob == null || RegexStrUtil.isNull(ftype) || (login == null) || RegexStrUtil.isNull(loginid)) {
            throw new BaseDaoException("params are null");
        }

        /**
         * Get scalability datasource for cobrand partitioned on loginid
         */
        String sourceName = scalabilityManager.getWriteScalability(loginid);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, addUserCobrand() " + sourceName + " loginid = " + loginid);
        }

        boolean addEntry = true;
        if (getUserCobrand(loginid) != null) {
            addEntry = false;
        }

        Connection conn = null;
        try {
            conn = ds.getConnection();
            if (addEntry) {
                if (ftype.equals("1")) {
                    byte[] mystream = { ' ' };
                    addUserQuery.run(conn, loginid, blob, mystream);
                } else {
                    byte[] mystream = { ' ' };
                    addUserQuery.run(conn, loginid, mystream, blob);
                }
            } else {
                if (ftype.equals("1")) {
                    updateUserHeaderQuery.run(conn, loginid, blob);
                } else {
                    updateUserFooterQuery.run(conn, loginid, blob);
                }
            }
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("connection close exception while adding cobrand file ", e2);
            }
            throw new BaseDaoException("error occured while adding cobrand file", e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e2) {
            throw new BaseDaoException("connection close exception while adding cobrand file ", e2);
        }

        /**
         *  delete user cobrand from cache
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.USER_COBRAND);
        if (treeCache.exists(fqn, loginid)) {
            treeCache.remove(fqn, loginid);
        }

        fqn = cacheUtil.fqn(DbConstants.USER_PAGE);
        if (treeCache.exists(fqn, login)) {
            treeCache.remove(fqn, login);
        }

        fqn = cacheUtil.fqn(DbConstants.USER_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(loginid);
        sb.append("-");
        sb.append(ftype);
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
    }

    /**
     *  addCollabrumCobrand method - adds the cobranding information for collabrum
     *  @param blob - the byte array
     *  @param collabrumId - the collabrum id
     *  @param ftype - the file type (header or footer)
     *  @param loginid - the loginid
     *  @param login - the login
     *  @throws BaseDaoException - when error occurs
     */
    public void addCollabrumCobrand(byte[] blob, String collabrumId, String ftype, String loginid, String login)
            throws BaseDaoException {

        if (blob == null || RegexStrUtil.isNull(collabrumId) || RegexStrUtil.isNull(ftype) || (login == null)
                || RegexStrUtil.isNull(loginid)) {
            throw new BaseDaoException("params are null");
        }

        /**
         *  Get scalability datasource for collabrumId cobrand partitioned on collabrumId
         */
        String sourceName = scalabilityManager.getWriteScalability(collabrumId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, addColMessage() " + sourceName + " collabrumId = " + collabrumId);
        }

        boolean addEntry = true;
        if (getCollCobrand(collabrumId) != null) {
            addEntry = false;
        }

        Connection conn = null;
        try {
            conn = ds.getConnection();
            if (addEntry) {
                //if (ftype.equals(DbConstants.HEADER)) {
                if (ftype.equals("1")) {
                    byte[] mystream = { ' ' };
                    addCollQuery.run(conn, collabrumId, blob, mystream);
                } else {
                    byte[] mystream = { ' ' };
                    addCollQuery.run(conn, collabrumId, mystream, blob);
                }
            } else {
                if (ftype.equals("1")) {
                    updateCollHeaderQuery.run(conn, collabrumId, blob);
                } else {
                    updateCollFooterQuery.run(conn, collabrumId, blob);
                }
            }
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("connection close exception while adding cobrand file ", e2);
            }
            throw new BaseDaoException("error occured while adding cobrand file", e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e2) {
            throw new BaseDaoException("connection close exception while adding cobrand file ", e2);
        }

        /**
         *  delete collabrum cobrand from cache
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.COLL_COBRAND);
        if (treeCache.exists(fqn, collabrumId)) {
            treeCache.remove(fqn, collabrumId);
        }

        fqn = cacheUtil.fqn(DbConstants.COLLABRUM);
        if (treeCache.exists(fqn, collabrumId)) {
            treeCache.remove(fqn, collabrumId);
        }

        fqn = cacheUtil.fqn(DbConstants.COLL_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(collabrumId);
        sb.append("-");
        sb.append(ftype);
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
    }

    /**
     *  addCobrandDirStreamBlob method - adds the cobranding information for directory
     *  @param blob - the byte array
     *  @param directoryId - the directory id
     *  @param ftype - the file type (header or footer)
     *  @param loginid - the loginid
     *  @param login - the login
     *  @throws BaseDaoException - when error occurs
     */
    public void addCobrandDirStreamBlob(byte[] blob, String directoryId, String ftype, String loginid, String login)
            throws BaseDaoException {

        if (blob == null || RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(ftype) || (login == null)
                || RegexStrUtil.isNull(loginid)) {
            throw new BaseDaoException("params are null");
        }

        /**
         *  Get scalability datasource for directory cobrand partitioned on directoryId
         */
        String sourceName = scalabilityManager.getWriteScalability(directoryId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, addColMessage() " + sourceName + " directoryId = " + directoryId);
        }

        boolean addEntry = true;
        if (getDirCobrand(directoryId) != null) {
            addEntry = false;
        }

        Connection conn = null;
        try {
            conn = ds.getConnection();
            if (addEntry) {
                //if (ftype.equals(DbConstants.HEADER)) {
                if (ftype.equals("1")) {
                    byte[] mystream = { ' ' };
                    addDirQuery.run(conn, directoryId, blob, mystream);
                } else {
                    byte[] mystream = { ' ' };
                    addDirQuery.run(conn, directoryId, mystream, blob);
                }
            } else {
                if (ftype.equals("1")) {
                    updateDirHeaderQuery.run(conn, directoryId, blob);
                } else {
                    updateDirFooterQuery.run(conn, directoryId, blob);
                }
            }
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("connection close exception while adding cobrand file ", e2);
            }
            throw new BaseDaoException("error occured while adding cobrand file", e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e2) {
            throw new BaseDaoException("connection close exception while adding cobrand file ", e2);
        }

        /**
         *  delete directory cobrand from cache
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.DIR_COBRAND);
        if (treeCache.exists(fqn, directoryId)) {
            treeCache.remove(fqn, directoryId);
        }

        fqn = cacheUtil.fqn(DbConstants.DIRECTORY);
        if (treeCache.exists(fqn, directoryId)) {
            treeCache.remove(fqn, directoryId);
        }

        fqn = cacheUtil.fqn(DbConstants.DIR_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(directoryId);
        sb.append("-");
        sb.append(ftype);
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
    }

    /**
     *  getDirStreamBlob method - gets the cobranding information for this directory 
     *  @param directoryId - the directory id
     *  @param ftype - the header or footer
     *  @return Photo - the cobranding information of this directory
     *  @throws BaseDaoException - when error occurs
     */
    public Photo getDirStreamBlob(String directoryId, String ftype) throws BaseDaoException {

        if (RegexStrUtil.isNull(directoryId)) {
            throw new BaseDaoException("params are null");
        }

        Fqn fqn = cacheUtil.fqn(DbConstants.DIR_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(directoryId);
        sb.append("-");
        sb.append(ftype);
        Object obj = treeCache.get(fqn, sb.toString());
        if (obj != null) {
            return (Photo) obj;
        }

        /**
         *  Get scalability datasource for partitioned on directoryid
         */
        String sourceName = scalabilityManager.getReadScalability(directoryId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, Directory dirCobrandQuery() " + sourceName);
        }
        List result = null;
        try {
            //Object[] params = {(Object)directoryId, (Object)ftype}; 
            Object[] params = { (Object) directoryId };
            if (ftype.equals("0")) {
                result = getDirFooterQuery.execute(params);
            } else {
                result = getDirHeaderQuery.execute(params);
            }
            if ((result != null) && (result.size() > 0)) {
                treeCache.put(fqn, sb.toString(), result.get(0));
                return (Photo) result.get(0);
            }
        } catch (Exception e) {
            throw new BaseDaoException("photo, get dirCobrandQuery(), ftype = " + ftype + ", directoryid =  "
                    + directoryId + dirCobrandQuery.getSql(), e);
        }
        return null;
    }

    /**
     *  getColStreamBlob method - gets the cobranding information for this collabrum 
     *  @param collabrumId - the collabrum id
     *  @param ftype - the header or footer
     *  @return Photo - the cobranding information of this collabrum
     *  @throws BaseDaoException - when error occurs
     */
    public Photo getColStreamBlob(String collabrumId, String ftype) throws BaseDaoException {

        if (RegexStrUtil.isNull(collabrumId)) {
            throw new BaseDaoException("params are null");
        }

        Fqn fqn = cacheUtil.fqn(DbConstants.COLL_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(collabrumId);
        sb.append("-");
        sb.append(ftype);
        Object obj = treeCache.get(fqn, sb.toString());
        if (obj != null) {
            return (Photo) obj;
        }

        /**
         *  Get scalability datasource for partitioned on collabrumId
         */
        String sourceName = scalabilityManager.getReadScalability(collabrumId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, getColStreamBlob() " + sourceName);
        }
        List result = null;
        try {
            Object[] params = { (Object) collabrumId };
            if (ftype.equals("0")) {
                result = getColFooterCobrandQuery.execute(params);
            } else {
                result = getColHeaderCobrandQuery.execute(params);
            }
            if ((result != null) && (result.size() > 0)) {
                treeCache.put(fqn, sb.toString(), result.get(0));
                return (Photo) result.get(0);
            }
        } catch (Exception e) {
            throw new BaseDaoException(
                    "photo, getColStreamBlob(), ftype = " + ftype + ", collabrumId =  " + collabrumId, e);
        }
        return null;
    }

    /**
     *  getUserStreamBlob method - gets the cobranding information for this member 
     *  @param member - the member
     *  @param ftype - the header or footer
     *  @return Photo - the cobranding information of this member 
     *  @throws BaseDaoException - when error occurs
     */
    public Photo getUserStreamBlob(String member, String ftype) throws BaseDaoException {

        if (RegexStrUtil.isNull(member)) {
            throw new BaseDaoException("params are null");
        }

        Hdlogin loginInfo = getLoginid(member);
        Fqn fqn = cacheUtil.fqn(DbConstants.USER_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(member);
        sb.append("-");
        sb.append(ftype);
        Object obj = treeCache.get(fqn, sb.toString());
        if (obj != null) {
            return (Photo) obj;
        }

        /**
         *  Get scalability datasource for partitioned on loginid
         */
        String sourceName = scalabilityManager.getReadScalability(loginInfo.getValue(DbConstants.LOGIN_ID));
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, getUserStreamBlob() " + sourceName);
        }
        List result = null;
        try {
            Object[] params = { (Object) loginInfo.getValue(DbConstants.LOGIN_ID) };
            if (ftype.equals("0")) {
                result = getUserFooterCobrandQuery.execute(params);
            } else {
                result = getUserHeaderCobrandQuery.execute(params);
            }
            if ((result != null) && (result.size() > 0)) {
                treeCache.put(fqn, sb.toString(), result.get(0));
                return (Photo) result.get(0);
            }
        } catch (Exception e) {
            throw new BaseDaoException("photo, getUserStreamBlob(), ftype = " + ftype + ", member =  " + member, e);
        }
        return null;
    }

    /**
     *  deleteCollCobrand method - deletes the cobranding information for collabrum
     *  @param collabrumId - the collabrum id
     *  @throws BaseDaoException - when error occurs
     */
    public void deleteCollCobrand(String collabrumId) throws BaseDaoException {

        if (RegexStrUtil.isNull(collabrumId)) {
            throw new BaseDaoException("params are null");
        }

        /**
         *  Get scalability datasource for collabrumId cobrand partitioned on collabrumId
         */
        String sourceName = scalabilityManager.getWriteScalability(collabrumId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException(
                    "ds null, deleteCollCobrand() " + sourceName + " collabrumId = " + collabrumId);
        }

        Connection conn = null;
        try {
            conn = ds.getConnection();
            deleteCollQuery.run(conn, collabrumId);
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("connection close exception while deleting collabrum cobrand file ", e2);
            }
            throw new BaseDaoException("error occured while deleting collabrum cobrand file", e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e2) {
            throw new BaseDaoException("connection close exception while deleting collabrum cobrand file ", e2);
        }

        /**
         *  delete collabrum cobrand from cache
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.COLL_COBRAND);
        if (treeCache.exists(fqn, collabrumId)) {
            treeCache.remove(fqn, collabrumId);
        }

        fqn = cacheUtil.fqn(DbConstants.COLLABRUM);
        if (treeCache.exists(fqn, collabrumId)) {
            treeCache.remove(fqn, collabrumId);
        }

        fqn = cacheUtil.fqn(DbConstants.COLL_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(collabrumId);
        sb.append("-");
        sb.append("0");
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }

        sb.delete(0, sb.length());
        sb.append(collabrumId);
        sb.append("-");
        sb.append("1");
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
    }

    /**
     *  deleteUserCobrand method - deletes the cobranding information for user
     *  @param loginId - the login id
     *  @param login - the login 
     *  @throws BaseDaoException - when error occurs
     */
    public void deleteUserCobrand(String loginId, String login) throws BaseDaoException {
        if (RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null");
        }

        /**
         *  Get scalability datasource for user cobrand partitioned on user
         */
        String sourceName = scalabilityManager.getWriteScalability(loginId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, deleteUserCobrand() " + sourceName + " loginId = " + loginId);
        }

        Connection conn = null;
        try {
            conn = ds.getConnection();
            deleteUserQuery.run(conn, loginId);
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("connection close exception while deleting user cobrand file ", e2);
            }
            throw new BaseDaoException("error occured while deleting user cobrand file", e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e2) {
            throw new BaseDaoException("connection close exception while deleting user cobrand file ", e2);
        }

        /**
         *  delete user cobrand from cache
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.USER_COBRAND);
        if (treeCache.exists(fqn, loginId)) {
            treeCache.remove(fqn, loginId);
        }

        fqn = cacheUtil.fqn(DbConstants.USER_PAGE);
        if (treeCache.exists(fqn, login)) {
            treeCache.remove(fqn, login);
        }

        fqn = cacheUtil.fqn(DbConstants.USER_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(loginId);
        sb.append("-");
        sb.append("0");
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
        sb.delete(0, sb.length());
        sb.append(loginId);
        sb.append("-");
        sb.append("1");
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
    }

    /**
     *  deleteDirCobrand method - deletes the cobranding information for directory
     *  @param directoryId - the directory id
     *  @throws BaseDaoException - when error occurs
     */
    public void deleteDirCobrand(String directoryId) throws BaseDaoException {
        if (RegexStrUtil.isNull(directoryId)) {
            throw new BaseDaoException("params are null");
        }

        /**
         *  Get scalability datasource for directoryId cobrand partitioned on directoryId
         */
        String sourceName = scalabilityManager.getWriteScalability(directoryId);
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException(
                    "ds null, deleteDirCobrand() " + sourceName + " directoryId = " + directoryId);
        }

        Connection conn = null;
        try {
            conn = ds.getConnection();
            deleteDirectoryQuery.run(conn, directoryId);
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("connection close exception while deleting directory cobrand file ", e2);
            }
            throw new BaseDaoException("error occured while deleting directory cobrand file", e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e2) {
            throw new BaseDaoException("connection close exception while deleting directory cobrand file ", e2);
        }

        /**
         *  delete directory cobrand from cache
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.DIR_COBRAND);
        if (treeCache.exists(fqn, directoryId)) {
            treeCache.remove(fqn, directoryId);
        }

        fqn = cacheUtil.fqn(DbConstants.DIRECTORY);
        if (treeCache.exists(fqn, directoryId)) {
            treeCache.remove(fqn, directoryId);
        }

        fqn = cacheUtil.fqn(DbConstants.DIR_BLOB_COBRAND);
        StringBuffer sb = new StringBuffer(directoryId);
        sb.append("-");
        sb.append("0");
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
        sb.delete(0, sb.length());
        sb.append(directoryId);
        sb.append("-");
        sb.append("1");
        if (treeCache.exists(fqn, sb.toString())) {
            treeCache.remove(fqn, sb.toString());
        }
    }

    /**
     *  checks to see if these properties are set by spring
     */
    public void setJdbcSource(DataSource ds) {
        this.ds = ds;
    }

    public void setusercobrandQuery(BasicQuery daq) {
        this.userCobrandQuery = daq;
    }

    public void setdircobrandQuery(BasicQuery daq) {
        this.dirCobrandQuery = daq;
    }

    public void setcollcobrandQuery(BasicQuery daq) {
        this.collCobrandQuery = daq;
    }

    public void setdiraddcobrandQuery(DirAddCobrandQuery daq) {
        this.addDirQuery = daq;
    }

    public void setdirupdateheaderQuery(DirCobrandUpdateHeaderQuery daq) {
        this.updateDirHeaderQuery = daq;
    }

    public void setdirupdatefooterQuery(DirCobrandUpdateFooterQuery daq) {
        this.updateDirFooterQuery = daq;
    }

    public void setdirheadercobrandQuery(BasicQuery daq) {
        this.getDirHeaderQuery = daq;
    }

    public void setdirfootercobrandQuery(BasicQuery daq) {
        this.getDirFooterQuery = daq;
    }

    public void setuserfootercobrandQuery(BasicQuery daq) {
        this.getUserFooterCobrandQuery = daq;
    }

    public void setuserheadercobrandQuery(BasicQuery daq) {
        this.getUserHeaderCobrandQuery = daq;
    }

    public void setcolheadercobrandQuery(BasicQuery daq) {
        this.getColHeaderCobrandQuery = daq;
    }

    public void setcolfootercobrandQuery(BasicQuery daq) {
        this.getColFooterCobrandQuery = daq;
    }

    public void setusercobrandupdatefooterQuery(UserCobrandUpdateFooterQuery daq) {
        this.updateUserFooterQuery = daq;
    }

    public void setusercobrandupdateheaderQuery(UserCobrandUpdateHeaderQuery daq) {
        this.updateUserHeaderQuery = daq;
    }

    public void setuseraddcobrandQuery(UserAddCobrandQuery daq) {
        this.addUserQuery = daq;
    }

    public void setcollcobrandupdatefooterQuery(ColCobrandUpdateFooterQuery daq) {
        this.updateCollFooterQuery = daq;
    }

    public void setcollcobrandupdateheaderQuery(ColCobrandUpdateHeaderQuery daq) {
        this.updateCollHeaderQuery = daq;
    }

    public void setcolladdcobrandQuery(CollabrumAddCobrandQuery daq) {
        this.addCollQuery = daq;
    }

    public void setdirdeletecobrandQuery(DirectoryDeleteCobrandQuery daq) {
        this.deleteDirectoryQuery = daq;
    }

    public void setcolldeletecobrandQuery(CollabrumDeleteCobrandQuery daq) {
        this.deleteCollQuery = daq;
    }

    public void setuserdeletecobrandQuery(UserDeleteCobrandQuery daq) {
        this.deleteUserQuery = daq;
    }

}