@Test void testCleanCacheBeforeUpdate() { EntityType entityType = mock(EntityType.class); when(entityType.getInversedByAttributes()).thenReturn(Stream.empty()); Entity entity = mock(Entity.class); when(entity.getEntityType()).thenReturn(entityType); l1CacheJanitorImpl.cleanCacheBeforeUpdate(entity); verifyNoInteractions(l1Cache); }
@Override public void cleanCacheBeforeUpdate(Entity entity) { EntityType entityType = entity.getEntityType(); Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity currentEntity = l1Cache.get(entityType, entity.getIdValue()).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeUpdate(iterator.next(), entity, currentEntity); } while (iterator.hasNext()); }
L1CacheJanitorImpl implements L1CacheJanitor { @Override public void cleanCacheBeforeUpdate(Entity entity) { EntityType entityType = entity.getEntityType(); Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity currentEntity = l1Cache.get(entityType, entity.getIdValue()).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeUpdate(iterator.next(), entity, currentEntity); } while (iterator.hasNext()); } }
L1CacheJanitorImpl implements L1CacheJanitor { @Override public void cleanCacheBeforeUpdate(Entity entity) { EntityType entityType = entity.getEntityType(); Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity currentEntity = l1Cache.get(entityType, entity.getIdValue()).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeUpdate(iterator.next(), entity, currentEntity); } while (iterator.hasNext()); } L1CacheJanitorImpl(L1Cache l1Cache); }
L1CacheJanitorImpl implements L1CacheJanitor { @Override public void cleanCacheBeforeUpdate(Entity entity) { EntityType entityType = entity.getEntityType(); Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity currentEntity = l1Cache.get(entityType, entity.getIdValue()).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeUpdate(iterator.next(), entity, currentEntity); } 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 cleanCacheBeforeUpdate(Entity entity) { EntityType entityType = entity.getEntityType(); Iterator<Attribute> iterator = entityType.getInversedByAttributes().iterator(); if (!iterator.hasNext()) { return; } Entity currentEntity = l1Cache.get(entityType, entity.getIdValue()).map(CacheHit::getValue).orElse(null); do { cleanCacheBeforeUpdate(iterator.next(), entity, currentEntity); } 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);  }