package com.hxh.spring.test; import java.util.List; import org.hibernate.HibernateException; import org.hibernate.Session; import org.junit.Test; import org.springframework.orm.hibernate4.HibernateCallback; import com.newvideo.dao.VideoYouKuDao; import com.newvideo.iqiyi.util.IqiyiUtil; import com.newvideo.pptv.PPTVUtil; import com.newvideo.sohu.SoHuUtil; import com.newvideo.util.BeanUtil; import com.newvideo.youku.YouKuUtil; import com.newvideo.youku.entity.VideoYouKu; public class VideoUpdateTest { public static void main(String[] args) { YouKuUtil youKuUtil = BeanUtil.getBean(YouKuUtil.class); youKuUtil.startParseVideo(); // SoHuUtil.getCategory(); } // @Test public void iqiyi() { IqiyiUtil iqiyiUtil = (IqiyiUtil) BeanUtil.getBean("iqiyiUtil"); iqiyiUtil.updateAlbum("424141100"); } // @Test public void sohu() { SoHuUtil soHuUtil = (SoHuUtil) BeanUtil.getBean("soHuUtil"); soHuUtil.parseAll(); } @Test public void pptv() { PPTVUtil pptvUtil = BeanUtil.getBean(PPTVUtil.class); pptvUtil.startParseShow(); } @Test @SuppressWarnings("unchecked") public void youku() { YouKuUtil youKuUtil = BeanUtil.getBean(YouKuUtil.class); youKuUtil.startParseVideo(); } @SuppressWarnings("rawtypes") // @Test public void clearYouKuMap() { // SELECT pv.`videoid`,COUNT(*) c FROM wk_video_youku pv GROUP BY // pv.`videoid` HAVING c>1 ORDER BY c DESC; VideoYouKuDao videoYouKuDao = (VideoYouKuDao) BeanUtil.getBean("videoYouKuDao"); // youKuUtil.startParseShow(); videoYouKuDao.excute(new HibernateCallback() { @SuppressWarnings("unchecked") public Object doInHibernate(Session session) throws HibernateException { List list = session .createSQLQuery( "SELECT pv.`videoid`,COUNT(*) c FROM wk_video_youku pv GROUP BY pv.`videoid` HAVING c>1 ORDER BY c DESC;") .list(); for (int i = 0; i < list.size(); i++) { Object[] objs = (Object[]) list.get(i); String vid = objs[0] + ""; List vlist = session .createQuery( "select vyk from VideoYouKu vyk left join vyk.video v where vyk.video.id=v.id and vyk.video.id=?") .setParameter(0, vid).setFirstResult(1).list(); for (VideoYouKu vk : vlist) { try { session.getTransaction().begin(); session.delete(vk); session.flush(); session.getTransaction().commit(); } catch (Exception e) { if (session.getTransaction().isActive()) session.getTransaction().rollback(); } } } return null; } }); } // @Test public static void youkuSingle() { YouKuUtil youKuUtil = (YouKuUtil) BeanUtil.getBean("youKuUtil"); youKuUtil.updateProgramById("facfcb0cec2511e583e8"); youKuUtil.updateProgramById("d21d807e749611e1b356"); youKuUtil.updateProgramById("9cd2277647d311e5b692"); youKuUtil.updateProgramById("67d68692e98711e5b522"); youKuUtil.updateProgramById("c553cf20aad811e59e2a"); } // @Test public void soHu() { SoHuUtil soHuUtil = (SoHuUtil) BeanUtil.getBean("soHuUtil"); soHuUtil.parseAll(); } }