@Test void testGetFetchStringIdCachesLoadedData() { Fetch fetch = new Fetch().field(EntityTestHarness.ATTR_ID); when(entityManager.createFetch(emd, fetch)) .thenAnswer( invocation -> new EntityWithComputedAttributes( new PartialEntity(new DynamicEntity(emd), fetch, entityManager))); Entity entity2 = testEntities.get(2); when(repository.findOneById("2")).thenReturn(entity2); Entity result = l2Cache.get(repository, "2", fetch); assertEquals("2", result.getIdValue()); result = l2Cache.get(repository, "2", fetch); assertEquals("2", result.getIdValue()); verify(repository, times(1)).findOneById("2"); }
public Entity get(Repository<Entity> repository, Object id) { LoadingCache<Object, Optional<Map<String, Object>>> cache = getEntityCache(repository); EntityType entityType = repository.getEntityType(); return cache.getUnchecked(id).map(e -> entityHydration.hydrate(e, entityType)).orElse(null); }
L2Cache implements TransactionListener { public Entity get(Repository<Entity> repository, Object id) { LoadingCache<Object, Optional<Map<String, Object>>> cache = getEntityCache(repository); EntityType entityType = repository.getEntityType(); return cache.getUnchecked(id).map(e -> entityHydration.hydrate(e, entityType)).orElse(null); } }
L2Cache implements TransactionListener { public Entity get(Repository<Entity> repository, Object id) { LoadingCache<Object, Optional<Map<String, Object>>> cache = getEntityCache(repository); EntityType entityType = repository.getEntityType(); return cache.getUnchecked(id).map(e -> entityHydration.hydrate(e, entityType)).orElse(null); } L2Cache(
      TransactionManager transactionManager,
      EntityHydration entityHydration,
      TransactionInformation transactionInformation,
      MeterRegistry meterRegistry); }
L2Cache implements TransactionListener { public Entity get(Repository<Entity> repository, Object id) { LoadingCache<Object, Optional<Map<String, Object>>> cache = getEntityCache(repository); EntityType entityType = repository.getEntityType(); return cache.getUnchecked(id).map(e -> entityHydration.hydrate(e, entityType)).orElse(null); } L2Cache(
      TransactionManager transactionManager,
      EntityHydration entityHydration,
      TransactionInformation transactionInformation,
      MeterRegistry meterRegistry); @Override void afterCommitTransaction(String transactionId); Entity get(Repository<Entity> repository, Object id); Entity get(Repository<Entity> repository, Object id, Fetch fetch); List<Entity> getBatch(Repository<Entity> repository, Iterable<Object> ids); List<Entity> getBatch(Repository<Entity> repository, Iterable<Object> ids, Fetch fetch); @Scheduled(fixedRate = 60000) void logStatistics(); }
L2Cache implements TransactionListener { public Entity get(Repository<Entity> repository, Object id) { LoadingCache<Object, Optional<Map<String, Object>>> cache = getEntityCache(repository); EntityType entityType = repository.getEntityType(); return cache.getUnchecked(id).map(e -> entityHydration.hydrate(e, entityType)).orElse(null); } L2Cache(
      TransactionManager transactionManager,
      EntityHydration entityHydration,
      TransactionInformation transactionInformation,
      MeterRegistry meterRegistry); @Override void afterCommitTransaction(String transactionId); Entity get(Repository<Entity> repository, Object id); Entity get(Repository<Entity> repository, Object id, Fetch fetch); List<Entity> getBatch(Repository<Entity> repository, Iterable<Object> ids); List<Entity> getBatch(Repository<Entity> repository, Iterable<Object> ids, Fetch fetch); @Scheduled(fixedRate = 60000) void logStatistics();  }