⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileattachmentdao.java

📁 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网!
💻 JAVA
字号:
    /* CRMS, customer relationship management system    Copyright (C) 2003  Service To Youth Council    This program 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 2 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, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    For further information contact the SYC ICT department on GPL@syc.net.au    98 Kermode Street    North Adelaide    South Australia    SA 5006     +61 (0)8 8367 0755    *//* * FileAttachmentDAO.java * * Created on 5 May 2003, 16:31 */package crms.dao;import crms.vo.*;import crms.util.*;import java.sql.*;import java.io.*;import java.util.*;import org.apache.log4j.Logger;/** * * @author  dmurphy */public class FileAttachmentDAO extends crms.dao.AbstractDAO {        static Logger logger = Logger.getLogger(FileAttachmentDAO.class);        /** Creates a new instance of FileAttachmentDAO */    public FileAttachmentDAO() {    }        public List getFileAttachments(EntityType type, String referenceID) {                String sql = "";                sql += "SELECT * from \"Attachment\"\n";        sql += " WHERE \"AttachmentType\" = " + quoteSingle(type.getCode()) + "\n";        sql += "   AND \"ReferenceID\" = " + quoteSingle(referenceID) + "\n";                        ArrayList attachments = (ArrayList) executeQuery(sql);        return attachments;    }        public FileAttachment getFileAttachment(String attachmentID) {                String sql = "";                sql += "SELECT * from \"Attachment\"\n";        sql += " WHERE \"AttachmentID\" = " + quoteSingle(attachmentID) + "\n";                        ArrayList attachments = (ArrayList) executeQuery(sql);                if (attachments == null) {            return null;        }                return (FileAttachment)attachments.get(0);    }           public FileAttachment insertFileAttachment(FileAttachment attach) {                        Connection con = null;        Statement stmt = null;        ResultSet rs = null;        String sql = "";                try {            con = getFactory().getConnection();            // There's three queries that need to happen atomically here,            // so we'll make it transactional by setting autoCommit to false            // and then doing a con.commit at the end.            con.setAutoCommit(false);            stmt = con.createStatement();            sql += "INSERT INTO \"Attachment\"\n";            sql += "(\"AttachmentType\", \"AttachmentDescription\", \"AttachedBy\", \"FileName\", \"CascadeRights\", \"ReferenceID\")\n";            sql += "VALUES\n";            sql += "(";            sql += quoteSingle(attach.getAttachmentType().getCode()) + ", ";            sql += quoteSingle(encode(attach.getDescription())) + ", ";            sql += quoteSingle(attach.getAttachedBy()) + ", ";            sql += quoteSingle(attach.getLocation()) + ", ";            sql += attach.hasCascadeRights() + ", ";            sql += attach.getReferenceID();            sql += ")\n";            try {                logger.debug("Executing sql:\n" + sql);                int rows = stmt.executeUpdate(sql);;                if (rows != 1) {                    logger.error("Incorrect number of rows inserted executing: " + sql);                    throw new RuntimeException("Incorrect number of rows inserted!");                }            }            catch (Exception ex) {                logger.error("Error executing sql: " + sql, ex);            }            // Get the ID of the row just inserted            sql = "select max(\"AttachmentID\")\n";            sql += "  from \"Attachment\"\n";            logger.debug("Executing sql:\n" + sql);            rs = stmt.executeQuery(sql);            int attachID = -1;            if (rs.next()) {                attachID = rs.getInt(1);            } else {                attachID = 1;            }            attach.setAttachmentID(attachID);            rs.close();            con.commit();                    }        catch (Exception ex) {            logger.error("Error executing sql: " + sql, ex);        }        finally {            try {                if (stmt != null) {                    stmt.close();                }                if (con != null) {                    con.close();                }            }            catch (SQLException ex) {                logger.error("Error executing sql: " + sql, ex);            }        }                return attach;    }        public void deleteFileAttachment(FileAttachment attach) {        String sql = "";                sql += "DELETE FROM  \"Attachment\"\n";        sql += "WHERE \"AttachmentID\" = " + attach.getAttachmentID() + "\n";        try {            int rows = super.updateSQL(sql);                        if (rows != 1) {                throw new RuntimeException("Incorrect number of rows inserted!");            }        }        catch (Exception ex) {            logger.error(ex);        }    }        public Object createFromResultSet(ResultSet rs) throws SQLException, UnsupportedEncodingException {        FileAttachment attach = new FileAttachment();                attach.setAttachmentID(rs.getInt("AttachmentID"));        attach.setAttachmentType((EntityType)EntityType.decode(rs.getString("AttachmentType"), EntityType.class));        attach.setDescription(decode(rs.getString("AttachmentDescription")));        attach.setAttachedBy(rs.getString("AttachedBy"));        attach.setLocation(rs.getString("FileName"));        attach.setCascadeRights(rs.getBoolean("CascadeRights"));        attach.setReferenceID(rs.getString("ReferenceID"));                return attach;    }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -