I - The generic ID type, usually Long.public abstract class AuditListener<I extends Comparable<I> & Serializable> extends Object
See Audit for usage instructions.
Audit| Constructor and Description |
|---|
AuditListener() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterUpdate(BaseEntity<I> entity) |
void |
beforeUpdate(BaseEntity<I> entity) |
protected static <T> T |
inject(Class<T> type)
Work around for CDI inject not working in JPA EntityListener.
|
protected abstract void |
saveAuditedChange(BaseEntity<I> entity,
PropertyDescriptor property,
Object oldValue,
Object newValue)
Example implementation:
|
public void beforeUpdate(BaseEntity<I> entity)
public void afterUpdate(BaseEntity<I> entity)
protected abstract void saveAuditedChange(BaseEntity<I> entity, PropertyDescriptor property, Object oldValue, Object newValue)
Example implementation:
YourAuditedChange yourAuditedChange = new YourAuditedChange(); yourAuditedChange.setTimestamp(Instant.now()); yourAuditedChange.setUser(activeUser); yourAuditedChange.setEntityName(entityManager.getMetamodel().entity(entity.getClass()).getName()); yourAuditedChange.setEntityId(entity.getId()); yourAuditedChange.setPropertyName(property.getName()); yourAuditedChange.setOldValue(oldValue != null ? oldValue.toString() : null); yourAuditedChange.setNewValue(newValue != null ? newValue.toString() : null); inject(YourAuditedChangeService.class).persist(yourAuditedChange);
entity - The parent entity.property - The audited property.oldValue - The old value.newValue - The new value.protected static <T> T inject(Class<T> type)
Work around for CDI inject not working in JPA EntityListener. Usage:
YourAuditedChangeService service = inject(YourAuditedChangeService.class);
T - The generic CDI managed bean type.type - The CDI managed bean type.Copyright © 2015–2017 OmniFaces. All rights reserved.