@Test public void findById() { List<Item> items = ImmutableList.of(createItem(1)); SelectResult result = createMock(SelectResult.class); Capture<SelectRequest> requestCapture = new Capture<SelectRequest>(); expect(domainFactory.createFromRing(RING_NAME)).andReturn(domain(RING_NAME)); expect(simpleDbClient.select(capture(requestCapture))).andReturn(result); expect(result.getItems()).andStubReturn(items); replayAll(); Set<CassandraInstance> expected = transform(items); assertEquals(expected.iterator().next(), dao.findById(RING_NAME, ID)); assertEquals(String.format(SdbCassandraInstanceDao.INSTANCE_QUERY, DOMAIN, ID), requestCapture.getValue().getSelectExpression()); assertNull(requestCapture.getValue().getNextToken()); }
@Override public @Nullable CassandraInstance findById(String ring, int id) { SelectRequest request = new SelectRequest(String.format(INSTANCE_QUERY, domain(ring), id)); SelectResult result = client.select(request); if (result.getItems().size() == 0) { return null; } return transform(result.getItems().get(0)); }
SdbCassandraInstanceDao implements CassandraInstanceDao { @Override public @Nullable CassandraInstance findById(String ring, int id) { SelectRequest request = new SelectRequest(String.format(INSTANCE_QUERY, domain(ring), id)); SelectResult result = client.select(request); if (result.getItems().size() == 0) { return null; } return transform(result.getItems().get(0)); } }
SdbCassandraInstanceDao implements CassandraInstanceDao { @Override public @Nullable CassandraInstance findById(String ring, int id) { SelectRequest request = new SelectRequest(String.format(INSTANCE_QUERY, domain(ring), id)); SelectResult result = client.select(request); if (result.getItems().size() == 0) { return null; } return transform(result.getItems().get(0)); } @Inject  SdbCassandraInstanceDao(AmazonSimpleDBClient client, CassandraDomainFactory domainFactory); }
SdbCassandraInstanceDao implements CassandraInstanceDao { @Override public @Nullable CassandraInstance findById(String ring, int id) { SelectRequest request = new SelectRequest(String.format(INSTANCE_QUERY, domain(ring), id)); SelectResult result = client.select(request); if (result.getItems().size() == 0) { return null; } return transform(result.getItems().get(0)); } @Inject  SdbCassandraInstanceDao(AmazonSimpleDBClient client, CassandraDomainFactory domainFactory); @Override ImmutableSet<CassandraInstance> findAll(String ring); @Override @Nullable CassandraInstance findById(String ring, int id); @Override void save(String ring, CassandraInstance instance); @Override void delete(String ring, CassandraInstance instance); }
SdbCassandraInstanceDao implements CassandraInstanceDao { @Override public @Nullable CassandraInstance findById(String ring, int id) { SelectRequest request = new SelectRequest(String.format(INSTANCE_QUERY, domain(ring), id)); SelectResult result = client.select(request); if (result.getItems().size() == 0) { return null; } return transform(result.getItems().get(0)); } @Inject  SdbCassandraInstanceDao(AmazonSimpleDBClient client, CassandraDomainFactory domainFactory); @Override ImmutableSet<CassandraInstance> findAll(String ring); @Override @Nullable CassandraInstance findById(String ring, int id); @Override void save(String ring, CassandraInstance instance); @Override void delete(String ring, CassandraInstance instance);  }