Repository navigation
Expand file tree
/
Copy pathNoticeDAO.java
More file actions
188 lines (164 loc) · 5.24 KB
/
Copy pathNoticeDAO.java
File metadata and controls
188 lines (164 loc) · 5.24 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// default package
import java.util.Date;
import java.util.List;
import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.transaction.annotation.Transactional;
/**
* A data access object (DAO) providing persistence and search support for
* Notice 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 .Notice
* @author MyEclipse Persistence Tools
*/
@Transactional
public class NoticeDAO {
private static final Logger log = LoggerFactory.getLogger(NoticeDAO.class);
// property constants
public static final String _ATITLE = "ATitle";
public static final String _ACONTENT = "AContent";
public static final String _AAUTHOR = "AAuthor";
public static final String _APHONE = "APhone";
public static final String _APICTUREPATH = "APicturepath";
public static final String _ATYPE = "AType";
public static final String _ALOG = "ALog";
private SessionFactory sessionFactory;
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
private Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}
protected void initDao() {
// do nothing
}
public void save(Notice transientInstance) {
log.debug("saving Notice instance");
try {
getCurrentSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Notice persistentInstance) {
log.debug("deleting Notice instance");
try {
getCurrentSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Notice findById(java.lang.Integer id) {
log.debug("getting Notice instance with id: " + id);
try {
Notice instance = (Notice) getCurrentSession().get("Notice", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Notice instance) {
log.debug("finding Notice instance by example");
try {
List results = getCurrentSession().createCriteria("Notice").add(Example.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 Notice instance with property: " + propertyName + ", value: " + value);
try {
String queryString = "from Notice as model where model." + propertyName + "= ?";
Query queryObject = getCurrentSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List findByATitle(Object ATitle) {
return findByProperty(_ATITLE, ATitle);
}
public List findByAContent(Object AContent) {
return findByProperty(_ACONTENT, AContent);
}
public List findByAAuthor(Object AAuthor) {
return findByProperty(_AAUTHOR, AAuthor);
}
public List findByAPhone(Object APhone) {
return findByProperty(_APHONE, APhone);
}
public List findByAPicturepath(Object APicturepath) {
return findByProperty(_APICTUREPATH, APicturepath);
}
public List findByAType(Object AType) {
return findByProperty(_ATYPE, AType);
}
public List findByALog(Object ALog) {
return findByProperty(_ALOG, ALog);
}
public List findAll() {
log.debug("finding all Notice instances");
try {
String queryString = "from Notice";
Query queryObject = getCurrentSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Notice merge(Notice detachedInstance) {
log.debug("merging Notice instance");
try {
Notice result = (Notice) getCurrentSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Notice instance) {
log.debug("attaching dirty Notice instance");
try {
getCurrentSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Notice instance) {
log.debug("attaching clean Notice instance");
try {
getCurrentSession().buildLockRequest(LockOptions.NONE).lock(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static NoticeDAO getFromApplicationContext(ApplicationContext ctx) {
return (NoticeDAO) ctx.getBean("NoticeDAO");
}
}