dao.DirectoryStreamBlobDaoDb.java Source code

Java tutorial

Introduction

Here is the source code for dao.DirectoryStreamBlobDaoDb.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.io.File;
import java.sql.Connection;
import java.util.List;
import javax.sql.DataSource;
import model.Photo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Fqn;
import san.SanException;
import util.*;

/** 
  * <B>DirectoryStreamBlobDaoDb</B> <BR>
  * This object implements DirectoryStreamBlobDao interface
  *
  * @author Smitha Gudur (smitha@redbasin.com)
  * @version $Revision: 1.1 $
  */
public class DirectoryStreamBlobDaoDb extends DirectoryAbstractDao implements DirectoryStreamBlobDao {

    protected final Log logger = LogFactory.getLog(getClass());

    // private volatile DiaryAdmin diaryAdmin;
    // private volatile DirAdminExistsQuery diradminexistsQuery; 
    //private volatile ExpiringObjectPool eop;
    //private volatile DirBlobTagsAllQuery  allTagsQuery;
    //private volatile DirBlobTagsQuery  tagsQuery;
    //private volatile DirBlobTags10Query  tags10Query;

    /**
     * these objects are set by spring
     */
    protected volatile LuceneManager luceneManager;
    private volatile DirectoryDeleteStreamBlobQuery deletestreamblobQuery;
    private volatile DefaultDirectoryQuery defaultQuery;
    private volatile DirectoryAddStreamBlobQuery addStreamBlobQuery;
    private volatile DefaultDirectoryBlobDeleteQuery deleteDefaultQuery;
    private volatile DirBlobEntryIdQuery entryIdQuery;

    private volatile DirBlobTagsAddQuery addTagQuery;
    private volatile DirBlobTagsUpdateQuery updateTagsQuery;
    private volatile DirBlobTagsDeleteQuery deleteTagsQuery;

    private volatile BasicQuery tagsQuery;
    private volatile BasicQuery tags10Query;
    private volatile BasicQuery allTagsQuery;
    private volatile BasicQuery blobTitleQuery;
    // private volatile DirBlobTitleQuery blobTitleQuery;

    private volatile DirImageAddQuery addImageQuery;
    private volatile DirImageDeleteQuery deleteImageQuery;
    // private volatile DirBlobSortSizeQuery dirBlobSortSizeQuery; 
    // private volatile DirBlobSortNameQuery dirBlobSortNameQuery; 

    private volatile BasicQuery dirBlobSortSizeAscQuery;
    private volatile BasicQuery dirBlobSortSizeDescQuery;

    private volatile BasicQuery dirBlobSortNameAscQuery;
    private volatile BasicQuery dirBlobSortNameDescQuery;

    // ascending is default set in the directory
    private volatile BasicQuery dirBlobSortDateAscQuery;

    private volatile BasicQuery dirBlobSortDateRangeQuery;
    private volatile BasicQuery dirBlobFilesDeletedRangeQuery;

    /**
     * Add a new blob to a directory of blobs
     * User permissions are checked before the user is allowed to add it.
     * If the user is the is the author of this directory or diaryadmin, allow this user to add it.
     * @param fieldsize
     * @param blobtype
     * @param mtype
     * @param btitle
     * @param blob
     * @param zoom
     * @param userid
     * @param directoryid
     * @param userLogin
     * @param usertags
     * @param caption
     * @param dirPath
     * @param dirName
     * @throws BaseDaoException If we have a problem interpreting the data or 
     *  the data is missing or incorrect
    */
    public void addStreamBlob(long bsize, int blobtype, String mtype, String btitle, byte[] blob, int zoom,
            String userId, String directoryId, String userLogin, String usertags, String caption, String dirPath,
            String dirName) throws BaseDaoException {

        if ((bsize <= 0) || RegexStrUtil.isNull(mtype) || RegexStrUtil.isNull(btitle) || (blob == null)) {
            throw new BaseDaoException("params are null");
        }

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

        //List dResult = null;
        //Object[] params = {(Object)directoryId, (Object)userId};
        // check authority to add
        //if ( !isAuthor(params, dResult) && !diaryAdmin.isDiaryAdmin(userLogin) ) {
        if (!isAuthor(directoryId, userId) && !diaryAdmin.isDiaryAdmin(userLogin)) {
            throw new BaseDaoException("user does not have permission to add streamblobs in directory "
                    + directoryId + " userId " + userId);
        }

        Connection conn = null;
        String entryId = null;
        if (RegexStrUtil.isNull(caption)) {
            caption = btitle;
        }

        if (WebUtil.isSanEnabled()) {
            /**
            * A file gets overwritten in file storage systems if the same
            * filename is used that is already exists.
            * If it is only in the database, we can support same file names
            * as they have unique ids
            * If samename exists, give an error
            */
            if (isFileNameExists(btitle, directoryId)) {
                throw new BaseDaoException(
                        "File already exists with the same name " + btitle + " directoryId = " + directoryId);
            }

            try {
                SanUtils sanUtils = new SanUtils();
                logger.info("dirPath=" + dirPath + " dirName=" + dirName + " sanPath=" + SanConstants.sanPath);

                /** dirPath = users|1 
                *   dirName = smitha
                *   SanConstants.sanPath = /home/usr/local/tomcat
                */
                sanUtils.addSanFile(dirPath, dirName, btitle, SanConstants.sanPath, blob);
            } catch (SanException e) {
                throw new BaseDaoException("directory addstreamblob, addSanFile() error " + dirName + dirPath
                        + btitle + e.getMessage(), e);
            }
        }

        try {
            conn = ds.getConnection();
            if (WebUtil.isSanEnabled()) {
                byte[] noBlobData = null;
                addStreamBlobQuery.run(conn, noBlobData, blobtype, mtype, btitle, bsize, zoom, directoryId, userId,
                        caption);
            } else {
                addStreamBlobQuery.run(conn, blob, blobtype, mtype, btitle, bsize, zoom, directoryId, userId,
                        caption);
            }
            List entryIdResult = entryIdQuery.run(conn, directoryId, btitle);
            if (entryIdResult != null && entryIdResult.size() > 0) {
                if ((Photo) entryIdResult.get(0) != null) {
                    entryId = ((Photo) entryIdResult.get(0)).getValue(DbConstants.ENTRYID);
                }
            }
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e2) {
                throw new BaseDaoException("addBlob error " + e2.getMessage(), e2);
            }
            throw new BaseDaoException("addBlob error(e) " + e.getMessage(), e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            throw new BaseDaoException("addBlob error " + e.getMessage(), e);
        }

        /* add this entry even if the usertags is null */
        if (!RegexStrUtil.isNull(entryId)) {
            addImagesAndTags(directoryId, usertags, entryId, blobtype, mtype, btitle, bsize, zoom, userId, caption);
        }

        /**
             * lucenesearch
        */
        if (WebUtil.isSanEnabled()) {
            if (WebUtil.isLuceneSearchEnabled()) {
                StringBuffer filePath = new StringBuffer(
                        RegexStrUtil.sanFilePath(dirPath, SanConstants.sanPath, dirName));
                logger.info("filePath = " + filePath.toString());
                if (filePath != null) {
                    filePath.append(File.separator);
                    filePath.append(btitle);
                }
                logger.info("filePath = " + filePath.toString());
                try {
                    luceneManager.indexDoc(filePath.toString());
                } catch (Exception e) {
                    throw new BaseDaoException("Exception in LuceneManager, luceneManager.indexDoc(), file="
                            + filePath.toString() + " errorMsg=" + e.getMessage());
                }
            }
        }

        /**
         * get stream blobs for a directory from cache, if it exists
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.DIRECTORY_STREAM_BLOBS);
        if (treeCache.exists(fqn, directoryId)) {
            treeCache.remove(fqn, directoryId);
        }

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

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

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

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

    /**
     * addTags - add tags to directory images
     */
    private void addTags(String directoryId, String usertags, String entryId) {

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

        String sourceName = scalabilityManager.getWriteZeroScalability();
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, addTags " + sourceName);
        }
        Connection conn = null;
        try {
            conn = ds.getConnection();
            addTagQuery.run(conn, directoryId, usertags, entryId);
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e1) {
                throw new BaseDaoException("addTags () " + e.getMessage(), e1);
            }
            throw new BaseDaoException("addTags () " + e.getMessage(), e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            throw new BaseDaoException("conn.close() error" + e.getMessage(), e);
        }
    }

    /**
     * addImagesAndTags - add image details and tags for a dirimage
     */
    private void addImagesAndTags(String directoryId, String usertags, String entryId, int blobtype, String mtype,
            String btitle, long bsize, int zoom, String userId, String caption) {

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

        String sourceName = scalabilityManager.getWriteZeroScalability();
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, addImagesAndTags " + sourceName);
        }
        if (RegexStrUtil.isNull(usertags)) {
            usertags = btitle;
        } else {
            usertags = usertags + "," + btitle;
        }
        Connection conn = null;
        try {
            conn = ds.getConnection();
            addTagQuery.run(conn, directoryId, usertags, entryId);
            boolean convertEntryId = true;
            addImageQuery.run(conn, entryId, blobtype, mtype, btitle, bsize, zoom, directoryId, userId, caption,
                    true);
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e1) {
                throw new BaseDaoException("addTags () " + e1.getMessage(), e1);
            }
            throw new BaseDaoException("addTags () " + e.getMessage(), e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            throw new BaseDaoException("conn.close() error" + e.getMessage(), e);
        }
    }

    /**
    * Deletes stream Blob 
    * @param entryid - entryid
    * @param userId - userId
    * @param directoryId - directoryId
    * @param userLogin - userLogin
    * @param dirPath - directory path
    * @param dirName - directory name
    * @param btitle - blob title
    * @return none
    */
    public void deleteStreamBlob(String entryid, String userId, String directoryId, String userLogin,
            String dirPath, String dirName, String btitle) {

        if (RegexStrUtil.isNull(userId)) {
            throw new BaseDaoException("params are null");
        }
        if (!isAuthor(directoryId, userId) && !diaryAdmin.isDiaryAdmin(userLogin)) {
            throw new BaseDaoException("user does not have permission to delete blob for directory " + directoryId
                    + " userId " + userId);
        }

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

        boolean exists = false;
        String defId = null;
        try {
            Object[] params = { (Object) directoryId };
            List result = defaultQuery.execute(params);
            if (result != null && result.size() > 0) {
                defId = ((Photo) result.get(0)).getValue(DbConstants.ENTRYID);
                if (!RegexStrUtil.isNull(defId) && defId.equals(entryid)) {
                    exists = true;
                }
            }
        } catch (Exception e) {
            throw new BaseDaoException("error " + e.getMessage() + defaultQuery.getSql());
        }

        if (exists) {
            Connection conn = null;
            try {
                conn = ds.getConnection();
                deleteDefaultQuery.run(conn, directoryId);
            } catch (Exception e) {
                try {
                    if (conn != null) {
                        conn.close();
                    }
                } catch (Exception e1) {
                    throw new BaseDaoException(
                            "conn.close() error in deleteDefaultQuery for stream blob in directory = " + directoryId
                                    + e.getMessage(),
                            e1);
                }
                throw new BaseDaoException(
                        "error deleteDefaultQuery for stream blob in directory = " + directoryId + e.getMessage(),
                        e);
            }

            /**
             *  conn.close for default blob
             */
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e) {
                throw new BaseDaoException(
                        "conn.close() error in deleteDefaultQuery for stream blob in directory = " + directoryId
                                + e.getMessage(),
                        e);
            }
        }

        /**
        * delete stream blob
        */
        try {
            if (WebUtil.isSanEnabled()) {
                SanUtils sanUtils = new SanUtils();
                sanUtils.deleteSanFile(dirPath, dirName, btitle, SanConstants.sanPath);
            }
            deletestreamblobQuery.run(entryid);
        } catch (Exception e) {
            throw new BaseDaoException("exception for deleting a blob() " + deletestreamblobQuery.getSql(), e);
        }
        deleteDirImage(directoryId, entryid);

        /**
         * generate a key for the directory stream blob (directoryId + entryid)
         * remove blobstream of directory, from cache
        * DIR_STREAM_BLOB - with blob data, DIR_PHOTO without the blob data
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.DIR_STREAM_BLOB);
        StringBuffer sb = new StringBuffer(directoryId);
        sb.append("-");
        sb.append(entryid);
        String key = sb.toString();
        if (treeCache.exists(fqn, key)) {
            treeCache.remove(fqn, key);
        }

        fqn = cacheUtil.fqn(DbConstants.DIR_PHOTO);
        if (treeCache.exists(fqn, key)) {
            treeCache.remove(fqn, key);
        }

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

        /** remove the existing default photo from cache */
        sb.delete(0, sb.length());
        sb.append(directoryId);
        sb.append("-");
        sb.append(defId);
        key = sb.toString();
        if (treeCache.exists(fqn, key)) {
            treeCache.remove(fqn, key);
        }

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

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

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

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

    /**
     * Delete directory usertags
     * @param directoryid
     * @param entryid
     * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
    */
    public void deleteTags(String directoryid, String entryid) throws BaseDaoException {

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

        /**
         *  Get scalability usertab - not partitioned
         *  not being used right now.
         */
        String sourceName = scalabilityManager.getWriteZeroScalability();
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, deleteTags() " + sourceName);
        }
        try {
            deleteTagsQuery.run(directoryid, entryid);
        } catch (Exception e) {
            throw new BaseDaoException("deleteTags is null" + e.getMessage() + deleteTagsQuery.getSql());
        }
    }

    /**
     * Delete directory image
     * @param directoryid
     * @param entryid
     * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
    */
    private void deleteDirImage(String directoryid, String entryid) throws BaseDaoException {

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

        /**
         *  Get scalability usertab - not partitioned
         *  not being used right now.
         */
        String sourceName = scalabilityManager.getWriteZeroScalability();
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, deleteDirImage() " + sourceName);
        }
        try {
            deleteImageQuery.run(directoryid, entryid);
        } catch (Exception e) {
            throw new BaseDaoException("Error, deleteDirImage " + e.getMessage() + deleteImageQuery.getSql());
        }
    }

    /**
     * get dirblob usertags
     * @param entryid
     * @param directoryid
     * @param accessflag
     * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
    */
    public String getTags(String entryid, String directoryid, int accessFlag) throws BaseDaoException {

        /**
         *  Get scalability usertab - not partitioned
         *  not being used right now.
         */
        String queryName = null;
        if (accessFlag == DbConstants.READ_FROM_MASTER) {
            queryName = scalabilityManager.getWriteZeroScalability("dirblobtagsQuery");
        } else {
            queryName = scalabilityManager.getReadZeroScalability("dirblobtagsQuery");
        }
        tagsQuery = getQueryMapper().getQuery(queryName);

        /** loginid  missing, add to usertab, hdprofile
         *  fname, lname, email
         */
        List uResult = null;
        try {
            Object[] params = { (Object) directoryid, entryid };
            uResult = tagsQuery.execute(params);
        } catch (Exception e) {
            throw new BaseDaoException("error executing Query" + tagsQuery.getSql() + e.getMessage(), e);
        }

        if (uResult == null) {
            throw new BaseDaoException("dirTagsQuery result is null" + tagsQuery.getSql());
        } else {
            if (uResult.size() > 0) {
                if ((Photo) uResult.get(0) != null) {
                    return ((Photo) uResult.get(0)).getValue(DbConstants.USER_TAGS);
                }
            }
        }
        return null;
    }

    /**
     * get all dirblob usertags
     * @param directoryid
     * @param accessFlag
     * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
    */
    public List getAllTags(String directoryid, int accessFlag) throws BaseDaoException {

        /**
         *  Get scalability usertab - not partitioned
         *  not being used right now.
         */
        String queryName = null;
        if (accessFlag == DbConstants.READ_FROM_MASTER) {
            queryName = scalabilityManager.getWriteZeroScalability("dirbloballtagsQuery");
        } else {
            queryName = scalabilityManager.getReadZeroScalability("dirbloballtagsQuery");
        }
        allTagsQuery = getQueryMapper().getQuery(queryName);

        /** loginid  missing, add to usertab, hdprofile
         *  fname, lname, email
         */
        List uResult = null;
        try {
            Object[] params = { (Object) directoryid };
            uResult = allTagsQuery.execute(params);
        } catch (Exception e) {
            throw new BaseDaoException("error executing Query" + allTagsQuery.getSql() + e.getMessage(), e);
        }
        return uResult;
    }

    /**
     * Update usertags
     * @param entryid
     * @param directoryid
     * @param usertags
     * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
    */
    public void updateTags(String entryid, String directoryid, String usertags) throws BaseDaoException {
        if (RegexStrUtil.isNull(entryid) || RegexStrUtil.isNull(directoryid)) {
            throw new BaseDaoException("params are null");
        }

        /* check if the tags exists, if the tag does not exist, create a new entry */
        if ((getTags(entryid, directoryid, DbConstants.READ_FROM_MASTER) == null)) {
            addTags(directoryid, usertags, entryid);
            return;
        }

        String sourceName = scalabilityManager.getWriteZeroScalability();
        ds = scalabilityManager.getSource(sourceName);
        if (ds == null) {
            throw new BaseDaoException("ds null, updateTags() " + sourceName);
        }

        Connection conn = null;
        try {
            conn = ds.getConnection();
            updateTagsQuery.run(conn, entryid, directoryid, usertags);
        } catch (Exception e) {
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (Exception e1) {
                throw new BaseDaoException("updateTags() () " + e1.getMessage(), e1);
            }
            throw new BaseDaoException("updateTags() () " + e.getMessage(), e);
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (Exception e) {
            throw new BaseDaoException("conn.close() error" + e.getMessage(), e);
        }
    }

    /**
     * isAuthor() method
     * checks if this user is the author of this directory and returns the value of either true or false 
     * @param myparams
     * @param adminResult
     * @return boolean
     * @throws BaseDaoException
     */
    /*   
        private boolean isAuthor(Object[] myparams, List adminResult) {
    */

    /**
     *  create the key, (directoryId + userId)
     *  get isAuthor value for this userId in this directory
     */
    /*
    StringBuffer sb = new StringBuffer((String)myparams[0]);
    sb.append("-");
    sb.append((String)myparams[1]);
    String key = sb.toString();
    Fqn fqn = cacheUtil.fqn(DbConstants.DIR_AUTHOR);
    Object obj = treeCache.get(fqn, key);
    if (obj != null) {
       String isAuthor = ((DirAuthor)obj).getValue(DbConstants.IS_AUTHOR);
       if (!RegexStrUtil.isNull(isAuthor)) {
          return (isAuthor.equals("1"));
       }
    }
        
       boolean isAuthor = false;   
    try {
        adminResult = diradminexistsQuery.execute(myparams);
        if (adminResult != null) {
           if (adminResult.size() > 0) {
              ((DirAuthor)adminResult.get(0)).setValue(DbConstants.IS_AUTHOR, "1");
              treeCache.put(fqn, key, (DirAuthor)adminResult.get(0));
    return true;
      }
           }
    } catch (BaseDaoException e) {
        throw new BaseDaoException("exception for isauthor," + diradminexistsQuery.getSql() + e.getMessage(), e);
    }
    */

    /**
     * put it in the cache
     */
    /*
    DirAuthor author = (DirAuthor)eop.newObject(DbConstants.DIR_AUTHOR);
    author.setValue(DbConstants.IS_AUTHOR, "0");
    treeCache.put(fqn, key, (DirAuthor)author);
    return isAuthor;
        }
    */

    /**
     * get any 10 dirblob usertags
     * @param accessflag
     * @throws BaseDaoException If we have a problem interpreting the data or the data is missing or incorrect
    */
    public List get10Tags(int accessFlag) throws BaseDaoException {

        /**
         *  Get scalability usertab - not partitioned
         *  not being used right now.
         */
        Fqn fqn = cacheUtil.fqn(DbConstants.DIR_BLOB);
        Object obj = treeCache.get(fqn, DbConstants.DIR_BLOB_10);
        if (obj != null) {
            return (List) obj;
        }

        String queryName = null;
        if (accessFlag == DbConstants.READ_FROM_MASTER) {
            queryName = scalabilityManager.getWriteZeroScalability("dirblobtags10Query");
        } else {
            queryName = scalabilityManager.getReadZeroScalability("dirblobtags10Query");
        }
        tags10Query = getQueryMapper().getQuery(queryName);

        /** loginid  missing, add to usertab, hdprofile
         *  fname, lname, email
         */
        List uResult = null;
        try {
            uResult = tags10Query.execute();
            if (uResult != null && uResult.size() > 0) {
                treeCache.put(fqn, DbConstants.DIR_BLOB_10, uResult);
            }
        } catch (Exception e) {
            throw new BaseDaoException("error executing Query" + tags10Query.getSql() + e.getMessage(), e);
        }
        return uResult;
    }

    /* 
        public void deleteSanFile(String dirPath, String dirName, String fileName) {
    if (WebUtil.isSanEnabled()) {
       if (RegexStrUtil.isNull(dirPath) || RegexStrUtil.isNull(dirName) ||
     RegexStrUtil.isNull(fileName)) {
     return BaseDaoException("deleteSanFile(), directory is null.");
          } else {
     String filePath = RegexStrUtil.sanFilePath(dirPath, dirName);
     if (RegexStrUtil.isNull(filePath)) {
        return BaseDaoException("deleteSanFile(), filepath is null");
     }
     logger.info("filePath = " + filePath);
     try {
             FileSystemImpl fApi = new FileSystemImpl();
         if (fApi != null) {
            fApi.deleteFile(filePath, SanConstants.sanPath, fileName);
              }
          } catch(SanException e1) {
        return BaseDaoException("deleteSanFile(), san.deleteFile() error" + e1.getMessage(), e1);
          }
          }
    }
        }
    */

    /**
    * check if the filename with the same title exists
    * give an error to the user as it will overwrite the file and add an
    * an entry in the database.
    * @param btitle
    * @return boolean - true if filename already exists, false otherwise
    * @throws exception
    */
    public boolean isFileNameExists(String btitle, String directoryId) {

        if (RegexStrUtil.isNull(btitle) || RegexStrUtil.isNull(directoryId)) {
            throw new BaseDaoException("btitle is null");
        }

        String queryName = scalabilityManager.getReadZeroScalability("dirblobtitlequery");

        blobTitleQuery = getQueryMapper().getQuery(queryName);
        List uResult = null;
        try {
            Object[] params = { (Object) directoryId, (Object) btitle };
            uResult = blobTitleQuery.execute(params);
        } catch (Exception e) {
            throw new BaseDaoException("error executing Query" + blobTitleQuery.getSql() + e.getMessage(), e);
        }

        /** filename with the same blob title exists **/
        if (uResult == null) {
            return false;
        } else {
            if (uResult.size() > 0) {
                return true;
            }
        }
        return false;
    }

    /**
    * returns files sorted by name ascending order
    * @param directoryId - directoryid
    * @param blobtype - blobtype
    * @param loginId - loginId
    * @return List - list of files
    */
    public List getFilesSortByNameAsc(String directoryId, String blobType, String loginId) throws BaseDaoException {

        if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(blobType) || RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null in getFilesSortByNameAsc");
        }

        /**
         *  Get scalability datasource partitioned
         */
        String queryName = scalabilityManager.getReadBlobScalability(loginId, "dirblobsortnameascquery");
        dirBlobSortNameAscQuery = getQueryMapper().getQuery(queryName);
        if (dirBlobSortNameAscQuery == null) {
            throw new BaseDaoException("dirBlobSortNameAscQuery is null");
        }

        try {
            Object[] params = { (Object) directoryId, (Object) blobType };
            List result = dirBlobSortNameAscQuery.execute(params);
            return result;
        } catch (BaseDaoException e) {
            throw new BaseDaoException("dirBlobSortNameAscQuery exception, directoryId = "
                    + dirBlobSortNameAscQuery.getSql() + directoryId, e);
        }
    }

    /**
    * returns files sorted by size ascending order
    * @param directoryId - directoryid
    * @param blobtype - blobtype
    * @param loginId - loginId
    * @return List - list of files
    */
    public List getFilesSortBySizeAsc(String directoryId, String blobType, String loginId) throws BaseDaoException {

        if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(blobType) || RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null in getFilesSortBySizeAsc");
        }

        /**
         *  Get scalability datasource partitioned
         */
        String queryName = scalabilityManager.getReadBlobScalability(loginId, "dirblobsortsizeascquery");
        dirBlobSortSizeAscQuery = getQueryMapper().getQuery(queryName);
        if (dirBlobSortSizeAscQuery == null) {
            throw new BaseDaoException("dirBlobSortSizeAscQuery is null");
        }

        try {
            Object[] params = { (Object) directoryId, (Object) blobType };
            List result = dirBlobSortSizeAscQuery.execute(params);
            return result;
        } catch (BaseDaoException e) {
            throw new BaseDaoException("dirBlobSortSizeAscQuery exception, directoryId = "
                    + dirBlobSortSizeAscQuery.getSql() + directoryId, e);
        }
    }

    /**
    * returns files sorted by name descending order
    * @param directoryId - directoryid
    * @param blobtype - blobtype
    * @param loginId - loginId
    * @return List - list of files
    */
    public List getFilesSortByNameDesc(String directoryId, String blobType, String loginId)
            throws BaseDaoException {

        if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(blobType) || RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null in getFilesSortByNameDesc");
        }

        /**
         *  Get scalability datasource partitioned
         */
        String queryName = scalabilityManager.getReadBlobScalability(loginId, "dirblobsortnamedescquery");
        dirBlobSortNameDescQuery = getQueryMapper().getQuery(queryName);
        if (dirBlobSortNameDescQuery == null) {
            throw new BaseDaoException("dirBlobSortNameDescQuery is null");
        }

        try {
            Object[] params = { (Object) directoryId, (Object) blobType };
            List result = dirBlobSortNameDescQuery.execute(params);
            return result;
        } catch (BaseDaoException e) {
            throw new BaseDaoException("dirBlobSortNameDescQuery exception, directoryId = "
                    + dirBlobSortNameDescQuery.getSql() + directoryId, e);
        }
    }

    /**
    * returns files sorted by size descending order
    * @param directoryId - directoryid
    * @param blobtype - blobtype
    * @param loginId - loginId
    * @return List - list of files
    */
    public List getFilesSortBySizeDesc(String directoryId, String blobType, String loginId)
            throws BaseDaoException {

        if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(blobType) || RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null in getFilesSortBySizeDesc");
        }

        /**
         *  Get scalability datasource partitioned
         */
        String queryName = scalabilityManager.getReadBlobScalability(loginId, "dirblobsortsizedescquery");
        dirBlobSortSizeDescQuery = getQueryMapper().getQuery(queryName);
        if (dirBlobSortSizeDescQuery == null) {
            throw new BaseDaoException("dirBlobSortSizeDescQuery is null");
        }

        try {
            Object[] params = { (Object) directoryId, (Object) blobType };
            return dirBlobSortSizeDescQuery.execute(params);
        } catch (BaseDaoException e) {
            throw new BaseDaoException("dirBlobSortSizeDescQuery exception, directoryId = "
                    + dirBlobSortSizeDescQuery.getSql() + directoryId, e);
        }
    }

    /**
    * returns files sorted by date descending order
    * @param directoryId - directoryid
    * @param blobtype - blobtype
    * @param loginId - loginId
    * @return List - list of files
    */
    public List getFilesSortByDateAsc(String directoryId, String blobType, String loginId) throws BaseDaoException {

        if (RegexStrUtil.isNull(directoryId) || RegexStrUtil.isNull(blobType) || RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null in getFilesSortByDateAsc");
        }

        /**
         *  Get scalability datasource partitioned
         */
        String queryName = scalabilityManager.getReadBlobScalability(loginId, "dirblobsortdateascquery");
        dirBlobSortDateAscQuery = getQueryMapper().getQuery(queryName);
        if (dirBlobSortDateAscQuery == null) {
            throw new BaseDaoException("dirBlobSortDateAscQuery is null");
        }

        try {
            Object[] params = { (Object) directoryId, (Object) blobType };
            return dirBlobSortDateAscQuery.execute(params);
        } catch (BaseDaoException e) {
            throw new BaseDaoException("dirBlobSortDateAscQuery exception, directoryId = "
                    + dirBlobSortDateAscQuery.getSql() + directoryId, e);
        }
    }

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

    /**
    * returns files sorted within a certain date range
    * @param startdate - startdate
    * @param enddate - enddate
    * @param loginId - loginId
    * @param userLogin - userLogin
    * @return List - list of files
    */
    public List getFilesSortDateRange(String startdate, String enddate, String loginId, String userLogin)
            throws BaseDaoException {

        if (RegexStrUtil.isNull(startdate) || RegexStrUtil.isNull(enddate) || RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null in getFilesSortByDateRange");
        }

        if (!diaryAdmin.isDiaryAdmin(userLogin)) {
            throw new BaseDaoException("user does not have permission to generate reports, login " + userLogin);
        }

        /**
         *  Get scalability datasource partitioned
         */
        String queryName = scalabilityManager.getReadBlobScalability(loginId, "dirblobsortdaterangequery");
        dirBlobSortDateRangeQuery = getQueryMapper().getQuery(queryName);
        if (dirBlobSortDateRangeQuery == null) {
            throw new BaseDaoException("dirBlobSortDateRangeQuery is null");
        }

        try {
            Object[] params = { (Object) startdate, (Object) enddate };
            return dirBlobSortDateRangeQuery.execute(params);
        } catch (BaseDaoException e) {
            throw new BaseDaoException("dirBlobSortDateRangeQuery exception, login = " + userLogin
                    + dirBlobSortDateRangeQuery.getSql() + e.getMessage(), e);
        }
    }

    /**
    * returns files that are deleted within a certain date range (used for reporting)
    * @param startdate - startdate
    * @param enddate - enddate
    * @param loginId - loginId
    * @param userLogin - userLogin
    * @return List - list of files
    */
    public List getFilesDeletedSortDateRange(String startdate, String enddate, String loginId, String userLogin)
            throws BaseDaoException {

        if (RegexStrUtil.isNull(startdate) || RegexStrUtil.isNull(enddate) || RegexStrUtil.isNull(loginId)) {
            throw new BaseDaoException("params are null in getFilesDeletedSortDateRange");
        }

        if (!diaryAdmin.isDiaryAdmin(userLogin)) {
            throw new BaseDaoException("user does not have permission to generate reports, login " + userLogin);
        }

        /**
         *  Get scalability datasource partitioned
         */
        String queryName = scalabilityManager.getReadBlobScalability(loginId, "dirblobfilesdeletedrangequery");
        dirBlobFilesDeletedRangeQuery = getQueryMapper().getQuery(queryName);
        if (dirBlobFilesDeletedRangeQuery == null) {
            throw new BaseDaoException("dirBlobSortDateRangeQuery is null");
        }

        try {
            Object[] params = { (Object) startdate, (Object) enddate };
            logger.info("dirBlobDeletedRange=" + dirBlobFilesDeletedRangeQuery.getSql());
            return dirBlobFilesDeletedRangeQuery.execute(params);
        } catch (BaseDaoException e) {
            throw new BaseDaoException(
                    "dirBlobFilesDeletedRangeQuery exception," + dirBlobFilesDeletedRangeQuery.getSql() + userLogin,
                    e);
        }
    }

    /*
        public void setDiaryadmin(DiaryAdmin diaryAdmin ) {
     this.diaryAdmin = diaryAdmin;
        
        
    /*
        public void setDiaryadmin(DiaryAdmin diaryAdmin ) {
     this.diaryAdmin = diaryAdmin;
        }
    */

    // directory adminquery
    /*
        public void setdiradminexistsQuery(DirAdminExistsQuery daq ) {
        this.diradminexistsQuery = daq;
        }
    */

    public void setdeletestreamblobQuery(DirectoryDeleteStreamBlobQuery daq) {
        this.deletestreamblobQuery = daq;
    }

    public void setaddstreamblobQuery(DirectoryAddStreamBlobQuery daq) {
        this.addStreamBlobQuery = daq;
    }

    public void setdeletedefaultdirectoryQuery(DefaultDirectoryBlobDeleteQuery daq) {
        this.deleteDefaultQuery = daq;
    }

    public void setdefaultdirQuery(DefaultDirectoryQuery daq) {
        this.defaultQuery = daq;
    }

    public void setdirblobtagsaddQuery(DirBlobTagsAddQuery daq) {
        this.addTagQuery = daq;
    }

    public void setdirblobentryidQuery(DirBlobEntryIdQuery daq) {
        this.entryIdQuery = daq;
    }

    public void setdirblobupdatetagsQuery(DirBlobTagsUpdateQuery daq) {
        this.updateTagsQuery = daq;
    }

    public void setdirblobdeletetagsQuery(DirBlobTagsDeleteQuery daq) {
        this.deleteTagsQuery = daq;
    }

    public void setdirdeleteimageQuery(DirImageDeleteQuery daq) {
        this.deleteImageQuery = daq;
    }

    public void setdiraddimageQuery(DirImageAddQuery daq) {
        this.addImageQuery = daq;
    }

    public void setdirblobsortnameascquery(DirBlobSortNameAscQuery daq) {
        this.dirBlobSortNameAscQuery = daq;
    }

    public void setdirblobsortnamedescquery(DirBlobSortNameDescQuery daq) {
        this.dirBlobSortNameDescQuery = daq;
    }

    public void setdirblobsortsizeascquery(DirBlobSortSizeAscQuery daq) {
        this.dirBlobSortSizeAscQuery = daq;
    }

    public void setdirblobsortsizedescquery(DirBlobSortSizeDescQuery daq) {
        this.dirBlobSortSizeDescQuery = daq;
    }

    public void setdirblobsortdateascquery(DirBlobSortDateAscQuery daq) {
        this.dirBlobSortDateAscQuery = daq;
    }

    public void setdirblobsortdaterangequery(DirBlobSortDateRangeQuery daq) {
        this.dirBlobSortDateRangeQuery = daq;
    }

    public void setdirblobfilesdeletedrangequery(DirBlobFilesDeletedRangeQuery daq) {
        this.dirBlobFilesDeletedRangeQuery = daq;
    }

    public void setluceneManager(LuceneManager lm) {
        this.luceneManager = lm;
    }

}