📄 teacherservice.java
字号:
/**
*
*/
package edu.yinhe.mis.services;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.yinhe.mis.dto.DictionaryDTO;
import edu.yinhe.mis.dto.TeacherDTO;
import edu.yinhe.mis.model.DAOFactory;
import edu.yinhe.system.common.AppException;
import edu.yinhe.system.model.IBaseDAO;
import edu.yinhe.system.services.Service;
/**
* @author 朱进喜
*Creation date:05-02-2008
* @version jdk1.6.0_03
* @since 从jdk1.0版本开始
*/
public class TeacherService extends Service {
private IBaseDAO tdao = null;
/* *验证老师编号的唯一性
* @see edu.yinhe.system.services.Service#load(java.lang.Object)
*/
public Object load(Object obj) throws AppException {
Boolean flag = new Boolean(false);
try {
tdao = DAOFactory.getTeacherDAO(conn);
flag = (Boolean) tdao.find(obj);
} catch (SQLException e) {
try {
this.conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return flag;
}
/**
* 新增老师信息
*/
public Object create(Object obj) throws AppException {
Boolean flag = new Boolean(false);
try {
tdao = DAOFactory.getTeacherDAO(conn);
flag = (Boolean) tdao.insert(obj);
} catch (SQLException e) {
try {
this.conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return flag;
}
/**
* 查看老师详细信息
*/
public Object findAll(Object obj) throws AppException {
Object[] object = null;
try {
tdao = DAOFactory.getTeacherDAO(conn);
object = (Object[]) tdao.findAll(obj);
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return object;
}
/**
* 通过指定的id查询老师信息
*/
public Object findById(Object obj) throws AppException {
List list = null;
try {
tdao = DAOFactory.getTeacherDAO(conn);
list = (ArrayList)tdao.findById(obj);
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return list;
}
/**
* 获得数据字典
*/
public Object findByObject(Object obj) throws AppException {
Map dmap = null;
tdao = DAOFactory.getTeacherDAO(conn);
try {
dmap = (HashMap)tdao.findByObject(obj);
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return dmap;
}
/**
* 更新老师信息
*/
public Object modify(Object obj) throws AppException {
Boolean flag = new Boolean(false);
try {
tdao = DAOFactory.getTeacherDAO(conn);
flag = (Boolean) tdao.update(obj);
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return flag;
}
/**
* 删除老师信息
*/
public Object remove(Object obj) throws AppException {
Boolean flag = new Boolean(false);
TeacherDTO tdto = (TeacherDTO)obj;
if(tdto.getDelType().equals("delAll")){
flag = (Boolean) this.removeAll(obj);
}else{
flag = (Boolean) this.removeOne(obj);
}
return flag;
}
/**
* 批量删除老师信息
* @param obj
* @return
* @throws AppException
*/
private Object removeAll(Object obj) throws AppException {
Boolean flag = new Boolean(false);
TeacherDTO tdto = null;
String[] idStr = null;
try {
tdto = (TeacherDTO) obj;
idStr = tdto.getIdStr().split("_");
tdao = DAOFactory.getTeacherDAO(conn);
for(int i=1; i<idStr.length; i++){
tdto.setId(Integer.parseInt(idStr[i]));
flag = (Boolean) tdao.delete(tdto);
}
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return flag;
}
/**
* 通过指定的id删除老师信息
* @param obj
* @return
* @throws AppException
*/
private Object removeOne(Object obj) throws AppException {
Boolean flag = new Boolean(false);
try {
tdao = DAOFactory.getTeacherDAO(conn);
flag = (Boolean) tdao.delete(obj);
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
throw new AppException(e1.getMessage()+"回滚失败");
}
e.printStackTrace();
}finally{
this.closeConnection();
tdao = null;
}
return flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -