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

📄 tplresourcedocdaoimpl.java

📁 这是一个工作流管理的后端EJB实现
💻 JAVA
字号:
package com.coshare.joyteam.projectMgr.dao.mssql;

import java.io.StringReader;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.coshare.joyteam.projectMgr.dao.DAOException;
import com.coshare.joyteam.projectMgr.dao.TplResourceDocDAO;
import com.coshare.joyteam.projectMgr.dto.ActivityDTO;
import com.coshare.joyteam.projectMgr.dto.TemplateDTO;
import com.coshare.joyteam.projectMgr.dto.TplResourceDocDTO;
import com.coshare.joyteam.util.ID;

public class TplResourceDocDAOImpl extends AbstractMssqlDAO implements
		TplResourceDocDAO {

	static String SQL_INSERT = "insert into [WfTplResourceDoc] ([TemplateId], [ActivityId], [ResId], [ResType], [InputorOutput], [theDescription]) values (?,?,?,?,?,?)";
	static String SQL_UPDATE = "update [WfTplResourceDoc] set [TemplateId] = ?, [ActivityId] = ?, [ResId] = ?, [ResType] = ?, [InputorOutput] = ?, [theDescription] = ? where [TplResDocId] = ?";
	static String SQL_DELETE = "delete from [WfTplResourceDoc] where [TplResDocId] = ?";
	static String SQL_SELECT_ByTplResDocId = "select * from [WfTplResourceDoc] where [TplResDocId] = ?";
	static String SQL_SELECT_ByPRIMARYKEY = "select * from [WfTplResourceDoc] where [TemplateId] = ? and [ActivityId] = ? and [ResId] = ? and [ResType] = ?";
	static String SQL_SELECT_ByactId = "select * from [WfTplResourceDoc] where [ActivityId] = ?";
	static String SQL_SELECT_BytplId = "select * from [WfTplResourceDoc] where [TemplateId] = ?";
	static String SQL_SELECT_ALL = "select * from [WfTplResourceDoc]";

	public boolean AddNew(TplResourceDocDTO dtoObj) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_INSERT);		
		boolean rt = false;
		try {
			ps.setInt(1, dtoObj.getTemplateId().getId());
			ps.setInt(2, dtoObj.getActivityId().getId());
			ps.setString(3, dtoObj.getResId());
			ps.setInt(4, dtoObj.getResType());
			ps.setInt(5, dtoObj.getInputorOutput());
			ps.setCharacterStream(6, new StringReader(dtoObj.getTheDescription()), dtoObj.getTheDescription().length());
			rt = ps.executeUpdate() > 0;
		} catch (SQLException e) {
			throw new DAOException("insert failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public boolean Update(TplResourceDocDTO dtoObj) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_UPDATE);		
		boolean rt = false;
		try {
			ps.setInt(1, dtoObj.getTemplateId().getId());
			ps.setInt(2, dtoObj.getActivityId().getId());
			ps.setString(3, dtoObj.getResId());
			ps.setInt(4, dtoObj.getResType());
			ps.setInt(5, dtoObj.getInputorOutput());
			ps.setCharacterStream(6, new StringReader(dtoObj.getTheDescription()), dtoObj.getTheDescription().length());
			ps.setInt(7, dtoObj.getTplResDocId().getId());
			rt = ps.executeUpdate() > 0;
		} catch (SQLException e) {
			throw new DAOException("update failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public boolean Delete(TplResourceDocDTO dtoObj) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_DELETE);		
		boolean rt = false;
		try {
			ps.setInt(1, dtoObj.getTplResDocId().getId());
			rt = ps.executeUpdate() > 0;
		} catch (SQLException e) {
			throw new DAOException("delete failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public TplResourceDocDTO getTplResourceDoc(ID tplResDocId)
			throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByTplResDocId);
		TplResourceDocDTO rt = null;
		try {
			ps.setInt(1, tplResDocId.getId());
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				rt = getDTOFromRs(rs);
			}
			else {
				throw new DAOException("not found.");
			}
		} catch (SQLException e) {
			throw new DAOException("select failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public TplResourceDocDTO getTplResourceDoc(ID templateId, ID activityId,
			String resId, int resType) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByPRIMARYKEY);
		TplResourceDocDTO rt = null;
		try {
			ps.setInt(1, templateId.getId());
			ps.setInt(2, activityId.getId());
			ps.setString(3, resId);
			ps.setInt(4, resType);
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				rt = getDTOFromRs(rs);
			}
			else {
				throw new DAOException("not found.");
			}
		} catch (SQLException e) {
			throw new DAOException("select failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public List getActResourceDocs(ID activityId) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByactId);
		ArrayList rt = new ArrayList();
		try {
			ps.setInt(1, activityId.getId());
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				rt.add(getDTOFromRs(rs));
			}
		} catch (SQLException e) {
			throw new DAOException("select failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public List getTplResourceDocs(ID templateId) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_BytplId);
		ArrayList rt = new ArrayList();
		try {
			ps.setInt(1, templateId.getId());
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				rt.add(getDTOFromRs(rs));
			}
		} catch (SQLException e) {
			throw new DAOException("select failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public List getTplResourceDocs() throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ALL);
		ArrayList rt = new ArrayList();
		try {
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {
				rt.add(getDTOFromRs(rs));
			}
		} catch (SQLException e) {
			throw new DAOException("select failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}
	public TplResourceDocDTO getDTOFromRs(ResultSet rs) throws SQLException {
		TplResourceDocDTO dto = new TplResourceDocDTO();
		dto.setTplResDocId(rs.getInt("TplResDocId"));
		dto.setTemplateId(TemplateDTO.intToID(rs.getInt("TemplateId")));
		dto.setActivityId(ActivityDTO.intToID(rs.getInt("ActivityId")));
		dto.setResId(rs.getString("ResId"));
		dto.setResType(rs.getInt("ResType"));
		dto.setInputorOutput(rs.getInt("InputorOutput"));
		dto.setTheDescription(rs.getString("theDescription"));
		return dto;
	}

}

⌨️ 快捷键说明

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