@Test public void testRead_presentCached() throws Exception { Mockito.when(cachedDao.find(Matchers.<IpPrefix>any())).thenReturn(Optional.of(MASTER_DB_BINDING_VALUE)); final ListenableFuture<Optional<MasterDatabaseBinding>> read = dao.read(IP_PREFIX); Assert.assertTrue(read.isDone()); Assert.assertTrue(read.get().isPresent()); Assert.assertEquals(KEY_1, read.get().get().getSecurityGroupTag()); }
@Override public ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key) { final Optional<MasterDatabaseBinding> cachedMasterDatabaseBinding = lookup(cachedDao, key); if (cachedMasterDatabaseBinding.isPresent()) { return Futures.immediateFuture(cachedMasterDatabaseBinding); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ListenableFuture<Void> cacheUpdatedFt = updateCache(); return Futures.transform(cacheUpdatedFt, new Function<Void, Optional<MasterDatabaseBinding>>() { @Nullable @Override public Optional<MasterDatabaseBinding> apply(@Nullable final Void input) { return lookup(cachedDao, key); } }, MoreExecutors.directExecutor()); } }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key) { final Optional<MasterDatabaseBinding> cachedMasterDatabaseBinding = lookup(cachedDao, key); if (cachedMasterDatabaseBinding.isPresent()) { return Futures.immediateFuture(cachedMasterDatabaseBinding); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ListenableFuture<Void> cacheUpdatedFt = updateCache(); return Futures.transform(cacheUpdatedFt, new Function<Void, Optional<MasterDatabaseBinding>>() { @Nullable @Override public Optional<MasterDatabaseBinding> apply(@Nullable final Void input) { return lookup(cachedDao, key); } }, MoreExecutors.directExecutor()); } } }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key) { final Optional<MasterDatabaseBinding> cachedMasterDatabaseBinding = lookup(cachedDao, key); if (cachedMasterDatabaseBinding.isPresent()) { return Futures.immediateFuture(cachedMasterDatabaseBinding); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ListenableFuture<Void> cacheUpdatedFt = updateCache(); return Futures.transform(cacheUpdatedFt, new Function<Void, Optional<MasterDatabaseBinding>>() { @Nullable @Override public Optional<MasterDatabaseBinding> apply(@Nullable final Void input) { return lookup(cachedDao, key); } }, MoreExecutors.directExecutor()); } } MasterDatabaseBindingDaoImpl(final DataBroker dataBroker,
                              final SimpleCachedDao<IpPrefix, MasterDatabaseBinding> cachedDao); }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key) { final Optional<MasterDatabaseBinding> cachedMasterDatabaseBinding = lookup(cachedDao, key); if (cachedMasterDatabaseBinding.isPresent()) { return Futures.immediateFuture(cachedMasterDatabaseBinding); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ListenableFuture<Void> cacheUpdatedFt = updateCache(); return Futures.transform(cacheUpdatedFt, new Function<Void, Optional<MasterDatabaseBinding>>() { @Nullable @Override public Optional<MasterDatabaseBinding> apply(@Nullable final Void input) { return lookup(cachedDao, key); } }, MoreExecutors.directExecutor()); } } MasterDatabaseBindingDaoImpl(final DataBroker dataBroker,
                              final SimpleCachedDao<IpPrefix, MasterDatabaseBinding> cachedDao); @Override ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key); @Override ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey); }
MasterDatabaseBindingDaoImpl implements DSAsyncDao<IpPrefix, MasterDatabaseBinding>,
        ReadableAsyncByKey<Sgt, MasterDatabaseBinding> { @Override public ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key) { final Optional<MasterDatabaseBinding> cachedMasterDatabaseBinding = lookup(cachedDao, key); if (cachedMasterDatabaseBinding.isPresent()) { return Futures.immediateFuture(cachedMasterDatabaseBinding); } else if (!cachedDao.isEmpty()) { return READ_FUTURE_ABSENT; } else { final ListenableFuture<Void> cacheUpdatedFt = updateCache(); return Futures.transform(cacheUpdatedFt, new Function<Void, Optional<MasterDatabaseBinding>>() { @Nullable @Override public Optional<MasterDatabaseBinding> apply(@Nullable final Void input) { return lookup(cachedDao, key); } }, MoreExecutors.directExecutor()); } } MasterDatabaseBindingDaoImpl(final DataBroker dataBroker,
                              final SimpleCachedDao<IpPrefix, MasterDatabaseBinding> cachedDao); @Override ListenableFuture<Optional<MasterDatabaseBinding>> read(@Nonnull final IpPrefix key); @Override ListenableFuture<Collection<MasterDatabaseBinding>> readBy(@Nonnull final Sgt specialKey);  }