package com.hxh.spring.test;
|
|
import java.util.List;
|
|
import org.hibernate.HibernateException;
|
import org.hibernate.Session;
|
import org.springframework.orm.hibernate4.HibernateCallback;
|
|
import com.yeshi.buwan.dao.juhe.sohu.SoHuVideoDao;
|
import com.yeshi.buwan.videos.sohu.SoHuUtil;
|
import com.yeshi.buwan.util.BeanUtil;
|
|
public class SoHuTest {
|
|
public static void main(String[] args) {
|
startParseSoHu();
|
}
|
|
public static void startParseSoHu() {
|
SoHuUtil soHuUtil = BeanUtil.getBean(SoHuUtil.class);
|
soHuUtil.parseAll();
|
}
|
|
@org.junit.Test
|
public void test1() {
|
SoHuVideoDao soHuVideoDao = BeanUtil.getBean(SoHuVideoDao.class);
|
soHuVideoDao.excute(new HibernateCallback() {
|
public Object doInHibernate(Session session) throws HibernateException {
|
List list = session
|
.createSQLQuery("SELECT rv.`videoid` FROM wk_resource_video rv WHERE rv.`resourceid`=14")
|
.list();
|
for (int i = 0; i < list.size(); i++) {
|
// 查询是否包含多个来源
|
Object count = session
|
.createSQLQuery("select count(*) from wk_resource_video rv where rv.videoid=?")
|
.setParameter(0, list.get(i) + "").uniqueResult();
|
int c = Integer.parseInt(count + "");
|
session.getTransaction().begin();
|
if (c > 1) {
|
session.createSQLQuery("delete from wk_resource_video where videoid=? and resourceid=14")
|
.setParameter(0, list.get(i) + "").executeUpdate();
|
} else {
|
// c==0 删除
|
session.createSQLQuery("update wk_video_video v set v.show=0 where v.id=?")
|
.setParameter(0, list.get(i) + "").executeUpdate();
|
}
|
session.flush();
|
session.getTransaction().commit();
|
}
|
return null;
|
}
|
});
|
|
}
|
|
}
|