package org.joonzis.ex;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.session.SqlSession;
import org.joonzis.mybatis.DBService;
public class BDao {
private static SqlSession sqlsession = null;
// 싱글톤
// mybatis와 다른 점 각 메소드마다 객체생성 할 필요없이 미리 만듬
private synchronized static SqlSession getSqlSession() {
if(sqlsession == null) {
sqlsession = DBService.getFactory().openSession(false); // 수동 커밋이므로 커밋 필요한 메소드에서 따로 처리해줘야됌
}
return sqlsession;
}
// 메소드
// 전체 데이터 개수 가져오기
public static int getTotalRecord() {
return getSqlSession().selectOne("total_record");
}
// 1. 전체 검색(index.jsp)
// select * from bbs_t;
public static List<BVO> getList(Map<String, Integer> map){
return getSqlSession().selectList("list_bbs" , map);
}
// 2. 게시글 저장(insert.jsp)
// insert into bbs_t values(작성자, 제목, 비밀번호, 첨부파일, 내용)
public static int getInsert(BVO vo) {
int result = getSqlSession().insert("insert_bbs", vo);
if(result >0) {
getSqlSession().commit();
}
return result;
}
// 3. 게시글 상세페이지(view.jsp)
public static BVO getBBS(int b_idx) {
return getSqlSession().selectOne("select_bbs", b_idx);
}
//4. 게시글 삭제
public static int getRemove(int b_idx) {
int result = getSqlSession().delete("remove_bbs", b_idx);
if(result >0) {
getSqlSession().commit();
}
return result;
}
//5. 게시글 수정
public static int getupdate(BVO bvo) {
int result = getSqlSession().update("update_bbs", bvo);
if(result >0) {
getSqlSession().commit();
}
return result;
}
//6.조회수 증가
public static int getUpdateHit(BVO bvo) {
return getSqlSession().update("UpdateHit",bvo);
}
//7.댓글 작성
public static int getInsertComment(CVO vo) {
int result = getSqlSession().insert("insertComment_t", vo);
if(result >0) {
getSqlSession().commit();
}
return result;
}
//8.댓글 목록
public static List<CVO> getCommentList(int b_idx){
return getSqlSession().selectList("getCommentList",b_idx);
}
//9.댓글 삭제
public static int removeComment(int c_idx) {
int result = getSqlSession().delete("deleteComment_t", c_idx);
if(result >0) {
getSqlSession().commit();
}
return result;
}
}