admin
2021-01-04 aa6ef62aef83e277d4171df1d9f0803f91738216
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.newvideo.service.imp;
 
import java.io.Serializable;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate4.HibernateCallback;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.newvideo.dao.FindVideoDao;
import com.newvideo.domain.FindVideo;
import com.newvideo.util.Constant;
 
@Service
public class FindVideoService {
 
    @Resource
    private FindVideoDao dao;
 
    public List<FindVideo> getFindVideoList(long cid, int page) {
        return dao.list(
                "from FindVideo where findClass.id = ? order by orderBy desc",
                (page - 1) * Constant.pageCount, Constant.pageCount,
                new Serializable[] { cid });
    }
 
    public FindVideo getFindVideo(long id) {
        return dao.find(FindVideo.class, id);
    }
 
    @Transactional
    public void delete(long id) {
        dao.delete(new FindVideo(id));
    }
    
    @Transactional
    public void update(FindVideo fv) {
        dao.update(fv);
    }
    @Transactional
    public Long save(FindVideo fv) {
        return (Long) dao.save(fv);
    }
 
    public int getCount(long cid) {
        return (int) dao.getCount("select count(*) from FindVideo where findClass.id=?", new Serializable[]{cid});
    }
    
    @Transactional
    public void deleteByCid(final Long id) {
        dao.excute(new HibernateCallback() {
            @Override
            public Object doInHibernate(Session session)
                    throws HibernateException {
                Query query = session.createQuery("delete FindVideo fv where fv.findClass.id = ? ");
                query.setParameter(0, id);
                query.executeUpdate();
                return null;
            }
        });
    }
 
}