dao.DirectoryAddStreamBlobQuery.java Source code

Java tutorial

Introduction

Here is the source code for dao.DirectoryAddStreamBlobQuery.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.sql.PreparedStatement;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import util.RegexStrUtil;

/**
 * DirectoryAddStreamBlobQuery class
 * This class is used to populate <code>Directory</code> bean
 * It is used by DirectoryBlobStreamDao to add blobstreams to the directory 
 * @author Smitha Gudur (smitha@redbasin.com)
 * @version $Revision: 1.1 $
 */
class DirectoryAddStreamBlobQuery {

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

    /**
    * This method is used to add blobstreams for directory.
    * @param conn - the connection
    * @param blob - the blob stream
    * @param blobType - the blob type (1 - photos, 2-music, 3-video 4 - documents, 5 - archives)
    * @param mimeType - the mime type (image/jpeg, application/octet-stream)
    * @param btitle - the title for this blob
    * @param bsize - the size of the blob
    * @param zoom - the zoom for the blob (used for displaying for image/jpeg)
    * @param directoryId - the directoryId
    * @param loginId - the loginId
    * @param caption - the caption
    * Modified query to accessdate at the end
    * @throws Dao Exception - when an error or exception occurs while inserting this blob in DB.
    *
     **/

    public void run(Connection conn, byte[] blob, int blobType, String mimeType, String btitle, long bsize,
            int zoom, String directoryId, String loginId, String caption) throws BaseDaoException {

        // long dt = new java.util.Date().getTime();
        byte[] capBytes = { ' ' };
        if (!RegexStrUtil.isNull(caption)) {
            capBytes = caption.getBytes();
        }

        long dt = System.currentTimeMillis();
        PreparedStatement s = null;
        String stmt = "insert into dirblob values(?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?, CURRENT_TIMESTAMP())";
        try {
            s = conn.prepareStatement(stmt);
            s.setLong(1, 0);
            s.setLong(2, new Long(directoryId));
            s.setLong(3, new Long(loginId));
            s.setInt(4, new Integer(blobType));
            s.setString(5, mimeType);
            s.setString(6, btitle);
            // s.setDate(7, new Date(dt));
            s.setBytes(7, blob);
            s.setLong(8, bsize);
            s.setInt(9, new Integer(zoom));
            s.setBytes(10, capBytes);
            s.executeUpdate();
        } catch (Exception e) {
            throw new BaseDaoException("Error adding a blob to directory query  stmt " + stmt, e);
        }
    }
}