package seed.dao; import java.util.List; import org.apache.log4j.Logger; import org.hibernate.Criteria; import org.hibernate.HibernateException; import org.hibernate.SessionFactory; import org.hibernate.criterion.Order; import org.hibernate.criterion.ProjectionList; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.springframework.stereotype.Repository; import seed.map.T_FILE_DOWNLOAD; /** * T_FILE_DOWNLOAD 테이블을 select,insert,update,delete하기 위한 DAO메소드 * */ @Repository public class FileDownLoadDAOImpl implements FileDownLoadDAO { private Logger log = Logger.getLogger(this.getClass()); private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } public Long getFileDownLoadCnt(String funcType, String funcSetIdx, String funcDataIdx) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_FILE_DOWNLOAD.class); if(!funcSetIdx.equals("0") && !funcDataIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcSetIdx", funcSetIdx)), Restrictions.eq("funcDataIdx", funcDataIdx))); }else if(!funcSetIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcSetIdx", funcSetIdx))); }else if(!funcDataIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcDataIdx", funcDataIdx))); } criteria.setProjection(Projections.rowCount()); return (Long)criteria.uniqueResult(); } @SuppressWarnings("unchecked") public List getFileDownLoadList(String funcType, String funcSetIdx, String funcDataIdx, int page, int row, String[] qryColumns){ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_FILE_DOWNLOAD.class); criteria.setFirstResult(page); criteria.setMaxResults(row); if(qryColumns != null && qryColumns.length > 0){ ProjectionList projectionList = Projections.projectionList(); boolean groupCheck = false; for(int q=0; q= 0){ groupCheck = true; continue; } if(groupCheck){ if(qryColumns[q].indexOf("Cnt") >= 0){ String qryColumn = qryColumns[q].substring(0, qryColumns[q].indexOf("Cnt")); projectionList.add(Projections.count(qryColumn).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1))); }else{ projectionList.add(Projections.groupProperty(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1))); } }else{ projectionList.add(Projections.property(qryColumns[q]).as("_"+qryColumns[q].substring(qryColumns[q].lastIndexOf(".")+1))); } } criteria.setProjection(projectionList); criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); } if(!funcSetIdx.equals("0") && !funcDataIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcSetIdx", funcSetIdx)), Restrictions.eq("funcDataIdx", funcDataIdx))); }else if(!funcSetIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcSetIdx", funcSetIdx))); }else if(!funcDataIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcDataIdx", funcDataIdx))); } criteria.addOrder(Order.desc("fileDownLoadIdx")); return criteria.list(); } @SuppressWarnings("unchecked") public List getFileDownLoadList(String funcType, String funcSetIdx, String funcDataIdx){ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_FILE_DOWNLOAD.class); if(!funcSetIdx.equals("0") && !funcDataIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcSetIdx", funcSetIdx)), Restrictions.eq("funcDataIdx", funcDataIdx))); }else if(!funcSetIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcSetIdx", funcSetIdx))); }else if(!funcDataIdx.equals("0")){ criteria.add( Restrictions.and( Restrictions.eq("funcType", funcType), Restrictions.eq("funcDataIdx", funcDataIdx))); } criteria.addOrder(Order.desc("fileDownLoadIdx")); return criteria.list(); } public boolean setFileDownLoadDelProc(T_FILE_DOWNLOAD tFileDownLoad){ boolean success = false; try{ this.sessionFactory.getCurrentSession().delete(tFileDownLoad); this.sessionFactory.getCurrentSession().flush(); this.sessionFactory.getCurrentSession().clear(); success = true; }catch(HibernateException e){ log.error("CHECK ERROR:",e); } return success; } public boolean setFileDownLoadProc(T_FILE_DOWNLOAD tFileDownLoad){ boolean success = false; try{ this.sessionFactory.getCurrentSession().save(tFileDownLoad); this.sessionFactory.getCurrentSession().flush(); this.sessionFactory.getCurrentSession().clear(); success = true; }catch(HibernateException e){ log.error("CHECK ERROR:",e); } return success; } }