01: package com.technoetic.xplanner.db.hibernate;
02:
03: import net.sf.hibernate.CallbackException;
04: import net.sf.hibernate.Interceptor;
05: import net.sf.hibernate.type.Type;
06:
07: import java.io.Serializable;
08: import java.util.Date;
09: import java.util.Iterator;
10:
11: public class XPlannerInterceptor implements Interceptor {
12: private static String LAST_UPDATE_TIME = "lastUpdateTime";
13:
14: public boolean onLoad(Object entity, Serializable id,
15: Object[] state, String[] propertyNames, Type[] types) {
16: return false;
17: }
18:
19: public boolean onFlushDirty(Object entity, Serializable id,
20: Object[] currentState, Object[] previousState,
21: String[] propertyNames, Type[] types) {
22: return setLastUpdateTime(propertyNames, currentState);
23: }
24:
25: public boolean onSave(Object entity, Serializable id,
26: Object[] state, String[] propertyNames, Type[] types) {
27: return setLastUpdateTime(propertyNames, state);
28: }
29:
30: private boolean setLastUpdateTime(String[] propertyNames,
31: Object[] state) {
32: for (int i = 0; i < propertyNames.length; i++) {
33: if (LAST_UPDATE_TIME.equals(propertyNames[i])) {
34: state[i] = new Date();
35: return true;
36: }
37: }
38: return false;
39: }
40:
41: public void onDelete(Object entity, Serializable id,
42: Object[] state, String[] propertyNames, Type[] types) {
43: // empty
44: }
45:
46: public void preFlush(Iterator entities) {
47: // empty
48: }
49:
50: public void postFlush(Iterator entities) {
51: // empty
52: }
53:
54: public int[] findDirty(Object entity, Serializable id,
55: Object[] currentState, Object[] previousState,
56: String[] propertyNames, Type[] types) {
57: return null;
58: }
59:
60: public Object instantiate(Class clazz, Serializable id)
61: throws CallbackException {
62: return null;
63: }
64:
65: public Boolean isUnsaved(Object entity) {
66: return null;
67: }
68:
69: }
|