📄 setcontenttypeimpl.java
字号:
package com.myContent.service.impl;
import java.sql.SQLException;
import java.util.List;
import org.apache.log4j.Logger;
import com.gd.jdbc.impl.GdDbConnection;
import com.myContent.dao.ContentTypeDAO;
import com.myContent.dao.impl.ContentTypeDAOImpl;
import com.myContent.dao.impl.UserDAOImpl;
import com.myContent.service.SetContentType;
import com.myContent.vo.ContentType;
import com.myContent.vo.User;
public class SetContentTypeImpl implements SetContentType{
static Logger logger = Logger.getLogger(SetContentTypeImpl.class.getName());
private ContentTypeDAO contentTypeDao = null;
/**该方法用来获取所有的内容类别
*/
public List getAllContentType() throws Exception {
List list = null;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentTypeDao = new ContentTypeDAOImpl(con.getConnection(this));
//获取所有内容类别
list = contentTypeDao.queryAllContentType();
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
logger.error(e);
} finally {
//关闭连接
con.close(this);
return list;
}
}
/**该方法用来实现向数据库查询内容类别
*/
public ContentType queryContentType(ContentType contentType) throws Exception {
ContentType contentType1 = null;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentTypeDao = new ContentTypeDAOImpl(con.getConnection(this));
//获取内容类别
contentType1 = contentTypeDao.queryContentType(contentType.getContentTypeId());
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
logger.error(e);
} finally {
//关闭连接
con.close(this);
return contentType1;
}
}
/**该方法用来实现向数据库新增内容类别
*/
public int saveContentType(ContentType contentType) throws Exception {
int counts = 0;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentTypeDao = new ContentTypeDAOImpl(con.getConnection(this));
//开始进行事务处理
con.beginTransaction(this);
//新增内容类别
counts = contentTypeDao.createContentType(contentType);
//事务提交
con.commit(this);
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
//事务回滚
con.rollback(this);
logger.error(e);
} finally {
//关闭连接
con.close(this);
return counts;
}
}
/**该方法用来实现向数据库修改内容类别
*/
public int updateContentType(ContentType contentType) throws Exception {
int counts = 0;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentTypeDao = new ContentTypeDAOImpl(con.getConnection(this));
//开始进行事务处理
con.beginTransaction(this);
//新增内容类别
counts = contentTypeDao.updateContentType(contentType);
//事务提交
con.commit(this);
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
//事务回滚
con.rollback(this);
logger.error(e);
} finally {
//关闭连接
con.close(this);
return counts;
}
}
/**该方法用来实现向数据库删除内容类别
*/
public int deleteContentType(ContentType contentType) throws Exception {
int counts = 0;
//取得连接
GdDbConnection con = new GdDbConnection(this);
try {
contentTypeDao = new ContentTypeDAOImpl(con.getConnection(this));
//开始进行事务处理
con.beginTransaction(this);
//新增内容类别
counts = contentTypeDao.deleteContentType(contentType);
//事务提交
con.commit(this);
} catch (SQLException e) {
logger.error(e);
} catch(Exception e) {
//事务回滚
con.rollback(this);
logger.error(e);
} finally {
//关闭连接
con.close(this);
return counts;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -