/
FapiDAO.java
147 lines (130 loc) · 4.89 KB
/
FapiDAO.java
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.huagu.vcoin.main.dao;
import static org.hibernate.criterion.Example.create;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;
import com.huagu.vcoin.main.dao.comm.HibernateDaoSupport;
import com.huagu.vcoin.main.model.Fapi;
/**
* A data access object (DAO) providing persistence and search support for Fapi
* entities. Transaction control of the save(), update() and delete() operations
* can directly support Spring container-managed transactions or they can be
* augmented to handle user-managed Spring transactions. Each of these methods
* provides additional information for how to configure it for the desired type
* of transaction control.
*
* @see ztmp.Fapi
* @author MyEclipse Persistence Tools
*/
@Repository
public class FapiDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(FapiDAO.class);
// property constants
public static final String FPARTNER = "fpartner";
public static final String FSECRET = "fsecret";
public void save(Fapi transientInstance) {
log.debug("saving Fapi instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Fapi persistentInstance) {
log.debug("deleting Fapi instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Fapi findById(java.lang.Integer id) {
log.debug("getting Fapi instance with id: " + id);
try {
Fapi instance = (Fapi) getSession().get("com.huagu.vcoin.main.model.Fapi", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List<Fapi> findByExample(Fapi instance) {
log.debug("finding Fapi instance by example");
try {
List<Fapi> results = getSession().createCriteria("com.huagu.vcoin.main.model.Fapi").add(create(instance))
.list();
log.debug("find by example successful, result size: " + results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Fapi instance with property: " + propertyName + ", value: " + value);
try {
String queryString = "from Fapi as model where model." + propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List<Fapi> findByFpartner(Object fpartner) {
return findByProperty(FPARTNER, fpartner);
}
public List<Fapi> findByFsecret(Object fsecret) {
return findByProperty(FSECRET, fsecret);
}
public List findAll() {
log.debug("finding all Fapi instances");
try {
String queryString = "from Fapi";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Fapi merge(Fapi detachedInstance) {
log.debug("merging Fapi instance");
try {
Fapi result = (Fapi) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Fapi instance) {
log.debug("attaching dirty Fapi instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Fapi instance) {
log.debug("attaching clean Fapi instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}