instresourcedocdaoimpl.java

来自「这是一个工作流管理的后端EJB实现」· Java 代码 · 共 224 行

JAVA
224
字号
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.InstResourceDocDAO;
import com.coshare.joyteam.projectMgr.dto.InstResourceDocDTO;
import com.coshare.joyteam.projectMgr.dto.InstanceDTO;
import com.coshare.joyteam.projectMgr.dto.TaskDTO;
import com.coshare.joyteam.util.ID;

public class InstResourceDocDAOImpl extends AbstractMssqlDAO implements
		InstResourceDocDAO {

	static String SQL_INSERT = "insert into [WfInstResourceDoc] ([InstanceId], [TaskId], [ResId], [ResType], [InputorOutput], [theDescription], [StatusKey]) values (?,?,?,?,?,?,?)";
	static String SQL_UPDATE = "update [WfInstResourceDoc] set [InstanceId] = ?, [TaskId] = ?, [ResId] = ?, [ResType] = ?, [InputorOutput] = ?, [theDescription] = ?, [StatusKey] = ? where [InstResDocId] = ?";
	static String SQL_DELETE = "delete from [WfInstResourceDoc] where [InstResDocId] = ?";
	static String SQL_SELECT_ByInstResDocId = "select * from [WfInstResourceDoc] where [InstResDocId] = ?";
	static String SQL_SELECT_ByPRIMARYKEY = "select * from [WfInstResourceDoc] where [InstanceId] = ? and [TaskId] = ? and [ResId] = ? and [ResType] = ?";
	static String SQL_SELECT_BytaskId = "select * from [WfInstResourceDoc] where [TaskId] = ?";
	static String SQL_SELECT_ByinstId = "select * from [WfInstResourceDoc] where [InstanceId] = ?";
	static String SQL_SELECT_ALL = "select * from [WfInstResourceDoc]";

	public boolean AddNew(InstResourceDocDTO dtoObj) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_INSERT);		
		boolean rt = false;
		try {
			ps.setInt(1, dtoObj.getInstanceId().getId());
			ps.setInt(2, dtoObj.getTaskId().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.getStatusKey());
			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(InstResourceDocDTO dtoObj) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_UPDATE);		
		boolean rt = false;
		try {
			ps.setInt(1, dtoObj.getInstanceId().getId());
			ps.setInt(2, dtoObj.getTaskId().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.getStatusKey());
			ps.setInt(8, dtoObj.getInstResDocId().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(InstResourceDocDTO dtoObj) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_DELETE);		
		boolean rt = false;
		try {
			ps.setInt(1, dtoObj.getInstResDocId().getId());
			rt = ps.executeUpdate() > 0;
		} catch (SQLException e) {
			throw new DAOException("delete failed.", e);
		}
		finally {
			try {
				ps.close();
			} catch (SQLException e) {
			}
		}
		return rt;
	}

	public InstResourceDocDTO getInstResourceDoc(ID instResDocId) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByInstResDocId);
		InstResourceDocDTO rt = null;
		try {
			ps.setInt(1, instResDocId.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 InstResourceDocDTO getInstResourceDoc(ID instanceId, ID taskId,
			String resId, int resType) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByPRIMARYKEY);
		InstResourceDocDTO rt = null;
		try {
			ps.setInt(1, instanceId.getId());
			ps.setInt(2, taskId.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 getTaskResourceDocs(ID taskId) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_BytaskId);
		ArrayList rt = new ArrayList();
		try {
			ps.setInt(1, taskId.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 getInstResourceDocs(ID instanceId) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByinstId);
		ArrayList rt = new ArrayList();
		try {
			ps.setInt(1, instanceId.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 getInstResourceDocs() 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 InstResourceDocDTO getDTOFromRs(ResultSet rs) throws SQLException {
		InstResourceDocDTO dto = new InstResourceDocDTO();
		dto.setInstResDocId(rs.getInt("InstResDocId"));
		dto.setInstanceId(InstanceDTO.intToID(rs.getInt("InstanceId")));
		dto.setTaskId(TaskDTO.intToID(rs.getInt("TaskId")));
		dto.setResId(rs.getString("ResId"));
		dto.setResType(rs.getInt("ResType"));
		dto.setInputorOutput(rs.getInt("InputorOutput"));
		dto.setTheDescription(rs.getString("theDescription"));
		dto.setStatusKey(rs.getInt("StatusKey"));
		return dto;
	}

}

⌨️ 快捷键说明

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