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

📄 taskreldaoimpl.java

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

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.TaskRelDAO;
import com.coshare.joyteam.projectMgr.dto.TaskRelDTO;
import com.coshare.joyteam.util.ID;

public class TaskRelDAOImpl extends AbstractMssqlDAO implements TaskRelDAO {

	static String SQL_INSERT = "insert into [WfTaskRel] ([SucTask], [PreTask]) values (?,?)";
	static String SQL_UPDATE = "update [WfTaskRel] set [SucTask] = ?, [PreTask] = ? where [TaskRelId] = ?";
	static String SQL_DELETE = "delete from [WfTaskRel] where [TaskRelId] = ?";
	static String SQL_SELECT_ByTaskRelId = "select * from [WfTaskRel] where [TaskRelId] = ?";
	static String SQL_SELECT_ALL = "select * from [WfTaskRel]";
	static String SQL_SELECT_ByPRIMARYKEY = "select * from [WfTaskRel] where [SucTask] = ? and [PreTask] = ?";

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

	public TaskRelDTO getTaskRel(ID taskRelId) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByTaskRelId);
		TaskRelDTO rt = null;
		try {
			ps.setInt(1, taskRelId.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 List getTaskRels() 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 TaskRelDTO getDTOFromRs(ResultSet rs) throws SQLException {
		TaskRelDTO dto = new TaskRelDTO();
		dto.setTaskRelId(rs.getInt("TaskRelId"));
		dto.setPreTask(rs.getInt("PreTask"));
		dto.setSucTask(rs.getInt("SucTask"));
		return dto;
	}

	public TaskRelDTO getTaskRel(ID sucTask, ID preTask) throws DAOException {
		PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByPRIMARYKEY);
		TaskRelDTO rt = null;
		try {
			ps.setInt(1, sucTask.getId());
			ps.setInt(2, preTask.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;
	}
}

⌨️ 快捷键说明

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