📄 tplresourceorgdaoimpl.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.TplResourceOrgDAO;
import com.coshare.joyteam.projectMgr.dto.ActivityDTO;
import com.coshare.joyteam.projectMgr.dto.TemplateDTO;
import com.coshare.joyteam.projectMgr.dto.TplResourceOrgDTO;
import com.coshare.joyteam.util.ID;
public class TplResourceOrgDAOImpl extends AbstractMssqlDAO implements
TplResourceOrgDAO {
static String SQL_INSERT = "insert into [WfTplResourceOrg] ([TemplateId], [ActivityId], [ResId], [Type]) values (?,?,?,?)";
static String SQL_UPDATE = "update [WfTplResourceOrg] set [TemplateId] = ?, [ActivityId] = ?, [ResId] = ?, [Type] = ? where [TplResOrgId] = ?";
static String SQL_DELETE = "delete from [WfTplResourceOrg] where [TplResOrgId] = ?";
static String SQL_SELECT_ByTplResOrgId = "select * from [WfTplResourceOrg] where [TplResOrgId] = ?";
static String SQL_SELECT_ByactId = "select * from [WfTplResourceOrg] where [ActivityId] = ?";
static String SQL_SELECT_BytplId = "select * from [WfTplResourceOrg] where [TemplateId] = ?";
static String SQL_SELECT_ALL = "select * from [WfTplResourceOrg]";
static String SQL_SELECT_ByPRIMARYKEY = "select * from [WfTplResourceOrg] where [TemplateId] = ? and [ActivityId] = ? and [ResId] = ? and [Type] = ?";
public boolean AddNew(TplResourceOrgDTO 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.getType());
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(TplResourceOrgDTO 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.getType());
ps.setInt(5, dtoObj.getTplResOrgId().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(TplResourceOrgDTO dtoObj) throws DAOException {
PreparedStatement ps = da.prepareStatement(SQL_DELETE);
boolean rt = false;
try {
ps.setInt(1, dtoObj.getTplResOrgId().getId());
rt = ps.executeUpdate() > 0;
} catch (SQLException e) {
throw new DAOException("delete failed.", e);
}
finally {
try {
ps.close();
} catch (SQLException e) {
}
}
return rt;
}
public TplResourceOrgDTO getTplResourceOrg(ID tplResOrgId)
throws DAOException {
PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByTplResOrgId);
TplResourceOrgDTO rt = null;
try {
ps.setInt(1, tplResOrgId.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 getActResourceOrgs(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 getTplResourceOrgs(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 getTplResourceOrgs() 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 TplResourceOrgDTO getDTOFromRs(ResultSet rs) throws SQLException {
TplResourceOrgDTO dto = new TplResourceOrgDTO();
dto.setTplResOrgId(rs.getInt("TplResOrgId"));
dto.setTemplateId(TemplateDTO.intToID(rs.getInt("TemplateId")));
dto.setActivityId(ActivityDTO.intToID(rs.getInt("ActivityId")));
dto.setResId(rs.getString("ResId"));
dto.setType(rs.getInt("Type"));
return dto;
}
public TplResourceOrgDTO getTplResourceOrg(ID templateId, ID activityId, String resId, int type) throws DAOException {
PreparedStatement ps = da.prepareStatement(SQL_SELECT_ByPRIMARYKEY);
TplResourceOrgDTO rt = null;
try {
ps.setInt(1, templateId.getId());
ps.setInt(2, activityId.getId());
ps.setString(3, resId);
ps.setInt(4, type);
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 + -