1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package net.smartlab.web.history;
25
26 import java.io.Serializable;
27 import java.sql.Timestamp;
28 import java.util.Iterator;
29
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.hibernate.EntityMode;
33 import org.hibernate.HibernateException;
34 import org.hibernate.MappingException;
35 import org.hibernate.Transaction;
36 import org.hibernate.property.PropertyAccessor;
37 import org.hibernate.property.PropertyAccessorFactory;
38 import org.hibernate.property.Setter;
39 import org.hibernate.type.Type;
40
41
42
43
44
45
46 public class Interceptor implements org.hibernate.Interceptor {
47
48
49
50
51 protected final Log logger = LogFactory.getLog(Interceptor.class);
52
53
54
55
56
57 public boolean onLoad(Object arg0, Serializable arg1, Object[] arg2, String[] arg3, org.hibernate.type.Type[] arg4) throws org.hibernate.CallbackException {
58
59 return false;
60 }
61
62
63
64
65
66 public boolean onFlushDirty(Object entity, Serializable key, Object[] current, Object[] previous, String[] properties, Type[] types) throws org.hibernate.CallbackException {
67 if (logger.isDebugEnabled()) {
68 logger.debug("onFlushDirty(entity = " + entity + ", key = " + key + ", current = " + current + ", previous = " + previous
69 + ", properties = " + properties + ", types = " + types + ") - start");
70 }
71 boolean modified = false;
72 if (entity instanceof HistoricizableBusinessObject) {
73
74 HistorizedBusinessObject historized = ((HistoricizableBusinessObject)entity).getHistorized();
75 historized.setLastModified(new Timestamp(System.currentTimeMillis()));
76 try {
77
78 PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor(null);
79 for (int i = 0; i < properties.length; i++) {
80 if (!current[i].equals(previous[i])) {
81 modified = true;
82 Setter setter = accessor.getSetter(historized.getClass(), properties[i]);
83
84
85 } else if (!(historized instanceof DifferenciallyHistorizedBusinessObject)) {
86 Setter setter = accessor.getSetter(historized.getClass(), properties[i]);
87
88
89 }
90 }
91 if (modified) {
92
93 }
94 } catch (MappingException me) {
95 logger.error("onFlushDirty(entity = " + entity + ", key = " + key + ", current = " + current + ", previous = " + previous
96 + ", properties = " + properties + ", types = " + types + ") - error", me);
97
98 } catch (HibernateException he) {
99 logger.error("onFlushDirty(entity = " + entity + ", key = " + key + ", current = " + current + ", previous = " + previous
100 + ", properties = " + properties + ", types = " + types + ") - error", he);
101 }
102 }
103 return modified;
104 }
105
106
107
108
109
110 public boolean onSave(Object arg0, Serializable arg1, Object[] arg2, String[] arg3, org.hibernate.type.Type[] arg4) throws org.hibernate.CallbackException {
111
112 return false;
113 }
114
115
116
117
118
119 public void onDelete(Object arg0, Serializable arg1, Object[] arg2, String[] arg3, org.hibernate.type.Type[] arg4) throws org.hibernate.CallbackException {
120
121
122 }
123
124
125
126
127
128 public void onCollectionRecreate(Object arg0, Serializable arg1) throws org.hibernate.CallbackException {
129
130
131 }
132
133
134
135
136
137 public void onCollectionRemove(Object arg0, Serializable arg1) throws org.hibernate.CallbackException {
138
139
140 }
141
142
143
144
145
146 public void onCollectionUpdate(Object arg0, Serializable arg1) throws org.hibernate.CallbackException {
147
148
149 }
150
151
152
153
154
155 public void preFlush(Iterator arg0) throws org.hibernate.CallbackException {
156
157
158 }
159
160
161
162
163
164 public void postFlush(Iterator arg0) throws org.hibernate.CallbackException {
165
166
167 }
168
169
170
171
172
173 public Boolean isTransient(Object arg0) {
174
175 return null;
176 }
177
178
179
180
181
182 public int[] findDirty(Object arg0, Serializable arg1, Object[] arg2, Object[] arg3, String[] arg4, org.hibernate.type.Type[] arg5) {
183
184 return null;
185 }
186
187
188
189
190
191 public Object instantiate(String arg0, EntityMode arg1, Serializable arg2) throws org.hibernate.CallbackException {
192
193 return null;
194 }
195
196
197
198
199
200 public String getEntityName(Object arg0) throws org.hibernate.CallbackException {
201
202 return null;
203 }
204
205
206
207
208
209 public Object getEntity(String arg0, Serializable arg1) throws org.hibernate.CallbackException {
210
211 return null;
212 }
213
214
215
216
217
218 public void afterTransactionBegin(Transaction arg0) {
219
220
221 }
222
223
224
225
226
227 public void beforeTransactionCompletion(Transaction arg0) {
228
229
230 }
231
232
233
234
235
236 public void afterTransactionCompletion(Transaction arg0) {
237
238
239 }
240
241
242
243
244
245 public String onPrepareStatement(String arg0) {
246
247 return null;
248 }
249 }