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.MatchMode; 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_ERROR_LOGS; @Repository public class ErrorLogsDAOImpl implements ErrorLogsDAO { private Logger log = Logger.getLogger(this.getClass()); private SessionFactory sessionFactory; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } //AdminErrorLogsSetService public T_ERROR_LOGS getErrorLogsForm(Integer errorLogsIdx){ return (T_ERROR_LOGS) this.sessionFactory.getCurrentSession().load(T_ERROR_LOGS.class, errorLogsIdx); } //AdminErrorLogsSetService public Long getErrorLogsListCnt(String column, String search){ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_ERROR_LOGS.class); if (!column.equals("")) { if (column.equals("A")) { if (!search.equals("")) { criteria.add( Restrictions.or( Restrictions.like("errorLogsUrl", search, MatchMode.ANYWHERE), Restrictions.like("errorLogsType", search, MatchMode.ANYWHERE))); } } else { criteria.add(Restrictions.like(column, search, MatchMode.ANYWHERE)); } } criteria.setProjection(Projections.rowCount()); return (Long)criteria.uniqueResult(); } //AdminErrorLogsSetService @SuppressWarnings("unchecked") public List getErrorLogsList(int page, int row, String orderColumn, String order, String column, String search, String[] qryColumns){ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_ERROR_LOGS.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 (!column.equals("")) { if (column.equals("A")) { if (!search.equals("")) { criteria.add( Restrictions.or( Restrictions.like("errorLogsUrl", search, MatchMode.ANYWHERE), Restrictions.like("errorLogsType", search, MatchMode.ANYWHERE))); } } else { criteria.add(Restrictions.like(column, search, MatchMode.ANYWHERE)); } } if(order.equals("DESC")){ criteria.addOrder(Order.desc(orderColumn)); }else{ criteria.addOrder(Order.asc(orderColumn)); } return criteria.list(); } //CommonErrorLogsService public void setErrorLogsRegProc(T_ERROR_LOGS tErrorLogs) { try{ this.sessionFactory.getCurrentSession().save(tErrorLogs); this.sessionFactory.getCurrentSession().flush(); this.sessionFactory.getCurrentSession().clear(); }catch(HibernateException e){ log.error(e); } } }