dao.ColStreamBlobAddQuery.java Source code

Java tutorial

Introduction

Here is the source code for dao.ColStreamBlobAddQuery.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;

/**
 * This class implements ColStreamBlobAddQuery
 * Used by <code>Collabrum</code> bean
 * @author Smitha Gudur (smitha@redbasin.com)
 * @version $Revision: 1.1 $
 */
class ColStreamBlobAddQuery {

    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 collabrumid - the collabrumid
    * @param loginId - the loginId
    * @param caption - caption
    * @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 collabrumid, 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 collblob values(?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP(), ?, ?, ?, ?)";
        try {
            s = conn.prepareStatement(stmt);
            s.setLong(1, 0);
            s.setLong(2, new Long(collabrumid));
            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 collabrum query  stmt " + stmt, e);
        }
    }
}