126 lines
3.7 KiB
Java
126 lines
3.7 KiB
Java
package seed.dao;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.HibernateException;
|
|
import org.hibernate.Query;
|
|
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_ACCESS_STATISTICS;
|
|
|
|
@Repository
|
|
public class AccessStatisticsDAOImpl implements AccessStatisticsDAO {
|
|
|
|
private Logger log = Logger.getLogger(this.getClass());
|
|
|
|
private SessionFactory sessionFactory;
|
|
|
|
public void setSessionFactory(SessionFactory sessionFactory) {
|
|
this.sessionFactory = sessionFactory;
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public List<HashMap<Object,Object>> getAccessStatisticsList(String memberMergeSiteIdx, String[] qryColumns){
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_ACCESS_STATISTICS.class);
|
|
|
|
if(qryColumns != null && qryColumns.length > 0){
|
|
ProjectionList projectionList = Projections.projectionList();
|
|
boolean groupCheck = false;
|
|
for(int i=0; i<qryColumns.length; i++){
|
|
if(qryColumns[i]!=null && !"".equals(qryColumns[i])){
|
|
if(!groupCheck && qryColumns[i].indexOf("groupBy") >= 0){
|
|
groupCheck = true;
|
|
continue;
|
|
}
|
|
if(groupCheck){
|
|
if(qryColumns[i].indexOf("Count") >= 0){
|
|
projectionList.add(Projections.count(qryColumns[i]).as(qryColumns[i]));
|
|
}else{
|
|
projectionList.add(Projections.groupProperty(qryColumns[i]).as(qryColumns[i]));
|
|
}
|
|
}else{
|
|
projectionList.add(Projections.property(qryColumns[i]).as(qryColumns[i]));
|
|
}
|
|
}
|
|
}
|
|
criteria.setProjection(projectionList);
|
|
criteria.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
|
|
}
|
|
|
|
if(!memberMergeSiteIdx.equals("")){
|
|
criteria.add(Restrictions.ne("siteIdx", memberMergeSiteIdx));
|
|
}
|
|
|
|
criteria.addOrder(Order.desc("siteIdx"));
|
|
|
|
return criteria.list();
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
public T_ACCESS_STATISTICS getAccessStatisticsInfo(String siteIdx, Integer year, Integer month, Integer day, Integer hour) {
|
|
|
|
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(T_ACCESS_STATISTICS.class);
|
|
|
|
criteria.add(Restrictions.eq("siteIdx", siteIdx));
|
|
criteria.add(Restrictions.eq("accessYear", year));
|
|
criteria.add(Restrictions.eq("accessMonth", month));
|
|
criteria.add(Restrictions.eq("accessDay", day));
|
|
criteria.add(Restrictions.eq("accessHour", hour));
|
|
|
|
List<T_ACCESS_STATISTICS> dataList = criteria.list();
|
|
|
|
if(dataList!=null && dataList.size()>0){
|
|
return dataList.get(0);
|
|
}else{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public boolean setInsertAccessStatistics(T_ACCESS_STATISTICS accessStatistics) {
|
|
|
|
boolean success = false;
|
|
|
|
try{
|
|
this.sessionFactory.getCurrentSession().save(accessStatistics);
|
|
this.sessionFactory.getCurrentSession().flush();
|
|
this.sessionFactory.getCurrentSession().clear();
|
|
success = true;
|
|
}catch(HibernateException e){
|
|
log.error(e);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
|
|
public boolean setUpdateAccessStatistics(T_ACCESS_STATISTICS accessStatistics) {
|
|
|
|
boolean success = false;
|
|
|
|
try{
|
|
|
|
Query createQuery = this.sessionFactory.getCurrentSession().createQuery("UPDATE T_ACCESS_STATISTICS SET accessCount = :accessCount WHERE dataIdx = :dataIdx ");
|
|
|
|
createQuery.setInteger("accessCount", accessStatistics.getAccessCount());
|
|
createQuery.setInteger("dataIdx", accessStatistics.getDataIdx());
|
|
|
|
int rowCount = createQuery.executeUpdate();
|
|
|
|
if(rowCount>0){
|
|
success = true;
|
|
}
|
|
|
|
}catch(HibernateException e){
|
|
log.error(e);
|
|
}
|
|
return success;
|
|
}
|
|
} |