@Test void testCleanCacheBeforeDeleteByIdNotCached() { EntityType refEntityType = mock(EntityType.class); Attribute attribute = mock(Attribute.class); when(attribute.getRefEntity()).thenReturn(refEntityType); EntityType entityType = mock(EntityType.class); when(entityType.getInversedByAttributes()).thenReturn(Stream.of(attribute)); Object entityId = mock(Object.class); when(l1Cache.get(entityType, entityId)).thenReturn(Optional.empty()); l1CacheJanitorImpl.cleanCacheBeforeDeleteById(entityType, entityId); verify(l1Cache).evictAll(refEntityType); verifyNoMoreInteractions(l1Cache); }
@Override public void cleanCacheBeforeDeleteById(EntityType entityType, Object entityId) { Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity entity = l1Cache.get(entityType, entityId).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeDeleteById(iterator.next(), entity); } while (iterator.hasNext()); }
L1CacheJanitorImpl implements L1CacheJanitor { @Override public void cleanCacheBeforeDeleteById(EntityType entityType, Object entityId) { Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity entity = l1Cache.get(entityType, entityId).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeDeleteById(iterator.next(), entity); } while (iterator.hasNext()); } }
L1CacheJanitorImpl implements L1CacheJanitor { @Override public void cleanCacheBeforeDeleteById(EntityType entityType, Object entityId) { Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity entity = l1Cache.get(entityType, entityId).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeDeleteById(iterator.next(), entity); } while (iterator.hasNext()); } L1CacheJanitorImpl(L1Cache l1Cache); }
L1CacheJanitorImpl implements L1CacheJanitor { @Override public void cleanCacheBeforeDeleteById(EntityType entityType, Object entityId) { Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity entity = l1Cache.get(entityType, entityId).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeDeleteById(iterator.next(), entity); } while (iterator.hasNext()); } L1CacheJanitorImpl(L1Cache l1Cache); @Override void cleanCacheBeforeAdd(Entity entity); @Override Stream<Entity> cleanCacheBeforeAdd(EntityType entityType, Stream<Entity> entityStream); @Override void cleanCacheBeforeUpdate(Entity entity); @Override Stream<Entity> cleanCacheBeforeUpdate(EntityType entityType, Stream<Entity> entityStream); @Override void cleanCacheBeforeDelete(Entity entity); @Override Stream<Entity> cleanCacheBeforeDelete(EntityType entityType, Stream<Entity> entityStream); @Override void cleanCacheBeforeDeleteById(EntityType entityType, Object entityId); @Override Stream<Object> cleanCacheBeforeDeleteById(
      EntityType entityType, Stream<Object> entityIdStream); @Override void cleanCacheBeforeDeleteAll(EntityType entityType); }
L1CacheJanitorImpl implements L1CacheJanitor { @Override public void cleanCacheBeforeDeleteById(EntityType entityType, Object entityId) { Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity entity = l1Cache.get(entityType, entityId).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeDeleteById(iterator.next(), entity); } while (iterator.hasNext()); } L1CacheJanitorImpl(L1Cache l1Cache); @Override void cleanCacheBeforeAdd(Entity entity); @Override Stream<Entity> cleanCacheBeforeAdd(EntityType entityType, Stream<Entity> entityStream); @Override void cleanCacheBeforeUpdate(Entity entity); @Override Stream<Entity> cleanCacheBeforeUpdate(EntityType entityType, Stream<Entity> entityStream); @Override void cleanCacheBeforeDelete(Entity entity); @Override Stream<Entity> cleanCacheBeforeDelete(EntityType entityType, Stream<Entity> entityStream); @Override void cleanCacheBeforeDeleteById(EntityType entityType, Object entityId); @Override Stream<Object> cleanCacheBeforeDeleteById(
      EntityType entityType, Stream<Object> entityIdStream); @Override void cleanCacheBeforeDeleteAll(EntityType entityType);  }