예제 #1
0
 public void onPostUpdate(PostUpdateEvent event) {
   GenericModel entity = (GenericModel) event.getEntity();
   if (entity.getClass().isAnnotationPresent(Auditable.class)) {
     String model = entity.getClass().getName().replaceFirst("models.", "");
     String modelId = entity.getEntityId().toString();
     String[] properties = event.getPersister().getPropertyNames();
     Object[] oldValues = event.getOldState();
     Object[] values = event.getState();
     for (int i = 0; i < properties.length; i++) {
       boolean updated = false;
       if (oldValues[i] == null) {
         if (values[i] != null) {
           updated = true;
         }
       } else if (!oldValues[i].equals(values[i])) {
         updated = true;
       }
       if (updated) {
         AuditLog.invoke(
             "onUpdate",
             model,
             modelId,
             properties[i],
             oldValues[i] == null ? "NULL" : oldValues[i].toString(),
             values[i] == null ? "NULL" : values[i].toString());
       }
     }
   }
 }
예제 #2
0
 @Override
 public UserEntity delete() {
   super.delete();
   String cacheKey = new StringBuilder().append(CacheKey.userByUserId).append(id).toString();
   Cache.delete(cacheKey);
   return this;
 }
예제 #3
0
 public void onPostDelete(PostDeleteEvent event) {
   GenericModel entity = (GenericModel) event.getEntity();
   if (entity.getClass().isAnnotationPresent(Auditable.class)) {
     String model = entity.getClass().getName().replaceFirst("models.", "");
     String modelId = entity.getEntityId().toString();
     String[] properties = event.getPersister().getPropertyNames();
     Object[] values = event.getDeletedState();
     for (int i = 0; i < properties.length; i++) {
       AuditLog.invoke(
           "onDelete",
           model,
           modelId,
           properties[i],
           values[i] == null ? "NULL" : values[i].toString());
     }
   }
 }