| 1 |
|
package org.itracker.persistence.dao; |
| 2 |
|
|
| 3 |
|
import java.io.Serializable; |
| 4 |
|
import java.util.Date; |
| 5 |
|
|
| 6 |
|
import org.apache.log4j.Logger; |
| 7 |
|
import org.hibernate.EmptyInterceptor; |
| 8 |
|
import org.hibernate.type.Type; |
| 9 |
|
import org.itracker.model.AbstractEntity; |
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
@author |
| 17 |
|
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 11 |
Complexity Density: 0.65 |
|
| 18 |
|
public class TimestampInterceptor extends EmptyInterceptor { |
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
|
| 23 |
|
private static final long serialVersionUID = 1L; |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
private static final String CREATE_DATE_PROPERTY = "createDate"; |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
private static final String LAST_MODIFIED_DATE_PROPERTY = "lastModifiedDate"; |
| 30 |
|
|
| 31 |
|
@SuppressWarnings("unused") |
| 32 |
|
private static final transient Logger logger = Logger.getLogger(TimestampInterceptor.class); |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 37 |
0
|
public TimestampInterceptor() {... |
| 38 |
|
} |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@return |
| 49 |
|
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 6 |
Complexity Density: 0.6 |
|
| 50 |
0
|
public boolean onSave(Object entity, Serializable id, ... |
| 51 |
|
Object[] state, String[] propertyNames, Type[] types) { |
| 52 |
|
|
| 53 |
0
|
if (entity instanceof AbstractEntity) { |
| 54 |
0
|
final Date timestamp = new Date(); |
| 55 |
|
|
| 56 |
|
|
| 57 |
0
|
int propertiesSet = 0; |
| 58 |
|
|
| 59 |
|
|
| 60 |
0
|
for (int i = 0; i < propertyNames.length; i++) { |
| 61 |
|
|
| 62 |
0
|
if (CREATE_DATE_PROPERTY.equals(propertyNames[i]) |
| 63 |
|
|| LAST_MODIFIED_DATE_PROPERTY.equals(propertyNames[i])) { |
| 64 |
0
|
state[i] = timestamp; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
0
|
if (++propertiesSet == 2) { |
| 72 |
0
|
break; |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
} |
| 76 |
0
|
return (propertiesSet > 0); |
| 77 |
|
} |
| 78 |
0
|
return false; |
| 79 |
|
} |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
|
@return |
| 96 |
|
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.57 |
|
| 97 |
0
|
public boolean onFlushDirty(Object entity, Serializable id, ... |
| 98 |
|
Object[] currentState, Object[] previousState, |
| 99 |
|
String[] propertyNames, Type[] types) { |
| 100 |
|
|
| 101 |
0
|
if (entity instanceof AbstractEntity) { |
| 102 |
0
|
final Date timestamp = new Date(); |
| 103 |
|
|
| 104 |
|
|
| 105 |
0
|
for (int i = 0; i < propertyNames.length; i++) { |
| 106 |
|
|
| 107 |
0
|
if (LAST_MODIFIED_DATE_PROPERTY.equals(propertyNames[i])) { |
| 108 |
0
|
currentState[i] = timestamp; |
| 109 |
|
|
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
0
|
return true; |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
|
} |
| 118 |
0
|
return false; |
| 119 |
|
} |
| 120 |
|
|
| 121 |
|
} |