DATACMNS-957 - AuditingHandler now works with entities without an identifier.

Entities without an identifier previously an exception because the IsNewStrategyFactory wasn't able to determine a strategy even if there was no auditing to be applied in the first place.

We now eagerly check for auditability and skip the lookup for an IsNewStrategy completely in case that check returns false.

Related pull request: #189.
This commit is contained in:
Oliver Gierke
2016-12-14 13:54:01 +01:00
parent 74426c01e1
commit e3b7bb8b01
3 changed files with 18 additions and 1 deletions

View File

@@ -134,6 +134,16 @@ public class AuditingHandler implements InitializingBean {
touch(source, false);
}
/**
* Returns whether the given source is considered to be auditable in the first place
*
* @param source can be {@literal null}.
* @return
*/
protected final boolean isAuditable(Object source) {
return factory.getBeanWrapperFor(source) != null;
}
private void touch(Object target, boolean isNew) {
AuditableBeanWrapper wrapper = factory.getBeanWrapperFor(target);

View File

@@ -73,7 +73,7 @@ public class IsNewAwareAuditingHandler extends AuditingHandler {
*/
public void markAudited(Object object) {
if (object == null) {
if (!isAuditable(object)) {
return;
}