@Test void testFindAllTransactionReadonly() { boolean previousReadOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly(); try { TransactionSynchronizationManager.setCurrentTransactionReadOnly(true); List<Object> ids = asList("0", "1", "2"); Entity entity0 = when(mock(Entity.class).getIdValue()).thenReturn("0").getMock(); Entity entity1 = when(mock(Entity.class).getIdValue()).thenReturn("1").getMock(); Entity entity2 = when(mock(Entity.class).getIdValue()).thenReturn("2").getMock(); List<Entity> entities = asList(entity0, entity1, entity2); when(l2Cache.getBatch(delegateRepository, ids)).thenReturn(entities); assertEquals(entities, l2CacheRepositoryDecorator.findAll(ids.stream()).collect(toList())); } finally { TransactionSynchronizationManager.setCurrentTransactionReadOnly(previousReadOnly); } }
@SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } L2CacheRepositoryDecorator(
      Repository<Entity> delegateRepository,
      L2Cache l2Cache,
      TransactionInformation transactionInformation); }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } L2CacheRepositoryDecorator(
      Repository<Entity> delegateRepository,
      L2Cache l2Cache,
      TransactionInformation transactionInformation); @Override Entity findOneById(Object id); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch); @Override Entity findOneById(Object id, Fetch fetch); }
L2CacheRepositoryDecorator extends AbstractRepositoryDecorator<Entity> { @SuppressWarnings("UnstableApiUsage") @Override public Stream<Entity> findAll(Stream<Object> ids) { if (doRetrieveFromCache()) { Iterator<List<Object>> batches = Iterators.partition(ids.iterator(), ID_BATCH_SIZE); Iterable<List<Object>> iterable = () -> batches; return Streams.stream(iterable).flatMap(batch -> findAllCache(batch).stream()); } else { return delegate().findAll(ids); } } L2CacheRepositoryDecorator(
      Repository<Entity> delegateRepository,
      L2Cache l2Cache,
      TransactionInformation transactionInformation); @Override Entity findOneById(Object id); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids); @SuppressWarnings("UnstableApiUsage") @Override Stream<Entity> findAll(Stream<Object> ids, Fetch fetch); @Override Entity findOneById(Object id, Fetch fetch);  }