admin
2019-03-13 33b4ed2bbf28ec16b66e552680f56a691a4e908d
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.yeshi.fanli.service.impl.user;
 
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.yeshi.fanli.dao.user.PassWordErrorRecordDao;
import com.yeshi.fanli.entity.bus.user.PassWordErrorRecord;
import com.yeshi.fanli.service.inter.user.PassWordErrorRecordService;
 
@Service
public class PassWordErrorRecordServiceImpl implements
        PassWordErrorRecordService {
 
    @Resource
    public PassWordErrorRecordDao passWordErrorRecordDao;
    
    public PassWordErrorRecord getRecord(long uid) {
        
        List<PassWordErrorRecord> list = passWordErrorRecordDao.list("from PassWordErrorRecord r where r.userInfo.id = ?", new Serializable[]{uid});
        
        if(list.size() > 0){
            return list.get(0);
        }
        
        return new PassWordErrorRecord();
    }
 
    public int setRecord(final PassWordErrorRecord record) {
        return (Integer) passWordErrorRecordDao.excute(new HibernateCallback() {
            public Object doInHibernate(Session session)
                    throws HibernateException {
                session.getTransaction().begin();
                try {
                    int count = record.getCount();
                    record.setCount(++count);
                    session.saveOrUpdate(record);
                    session.flush();
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                    return record.getCount()-1;
                }
                return record.getCount();
            }
        });
    }
 
    public void saveOrUpdate(final PassWordErrorRecord record) {
        passWordErrorRecordDao.excute(new HibernateCallback() {
 
            public Object doInHibernate(Session session)
                    throws HibernateException {
                try {
                    session.getTransaction().begin();
                    session.saveOrUpdate(record);
                    session.getTransaction().commit();
                } catch (Exception e) {
                    e.printStackTrace();
                    session.getTransaction().rollback();
                }
                return null;
            }
        });
        
    }
    
    @Transactional
    public void deleteRecord(final long uid) {
        passWordErrorRecordDao.excute(new HibernateCallback() {
 
            public Object doInHibernate(Session session)
                    throws HibernateException {
                Query q = session.createQuery("delete from PassWordErrorRecord p where p.userInfo.id = ? ");
                q.setParameter(0, uid);
                q.executeUpdate();
                return null;
            }
        });
    }
 
    @Override
    public void deletePasswordErrorRecord() {
        passWordErrorRecordDao.excute(new HibernateCallback() {
 
            public Object doInHibernate(Session session)
                    throws HibernateException {
                Query q = session.createQuery("DELETE FROM PassWordErrorRecord");
                q.executeUpdate();
                return null;
            }
        });
    }
 
}