private Work interceptWork(EntityIndexBinding indexBindingForEntity, Work work) { if (indexBindingForEntity == null) { return work; } EntityIndexingInterceptor interceptor = indexBindingForEntity.getEntityIndexingInterceptor(); if (interceptor == null) { return work; } IndexingOverride operation; switch (work.getType()) { case ADD: operation = interceptor.onAdd(work.getEntity()); break; case UPDATE: operation = interceptor.onUpdate(work.getEntity()); break; case DELETE: operation = interceptor.onDelete(work.getEntity()); break; case COLLECTION: operation = interceptor.onCollectionUpdate(work.getEntity()); break; case PURGE: case PURGE_ALL: case INDEX: case DELETE_BY_QUERY: operation = IndexingOverride.APPLY_DEFAULT; break; default: throw new AssertionFailure("Unknown work type: " + work.getType()); } Work result = work; Class<?> entityClass = work.getEntityClass(); switch (operation) { case APPLY_DEFAULT: break; case SKIP: result = null; log.forceSkipIndexOperationViaInterception(entityClass, work.getType()); break; case UPDATE: result = new Work(work.getTenantIdentifier(), work.getEntity(), work.getId(), WorkType.UPDATE); log.forceUpdateOnIndexOperationViaInterception(entityClass, work.getType()); break; case REMOVE: // This works because other Work constructors are never used from WorkType ADD, UPDATE, // REMOVE, COLLECTION // TODO should we force isIdentifierRollback to false if the operation is not a delete? result = new Work( work.getTenantIdentifier(), work.getEntity(), work.getId(), WorkType.DELETE, work.isIdentifierWasRolledBack()); log.forceRemoveOnIndexOperationViaInterception(entityClass, work.getType()); break; default: throw new AssertionFailure("Unknown action type: " + operation); } return result; }