AbstractDynamoDao extends AbstractDao<M,P,K,I> { public Update<P> updateOf(P partial) { ImmutableSet.Builder<String> attribs = ImmutableSet.builder(); if (partial != null) { Item item = partialMapper.toItem(partial); for (Map.Entry<String, Object> attr : item.attributes()) { attribs.add(attr.getKey()); } } return Update.of(partial, attribs.build()); } AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName);  AbstractDynamoDao(Class<M> modelClass, Class<P> partialClass, AmazonDynamoDB db, String tableName, ItemMapper<M> modelMapper, ItemMapper<P> partialMapper); String getTableName(); Table getTable(); Optional<M> loadOpt(K id); Optional<P> loadOpt(K id, Iterable<String> fields); @Override Iterable<M> iterateAll(); Results<M,K> scanAll(); @Override M create(P partial, Instant createAt, I creatorId); void update(K id, Update<P> update, Instant updateAt, I updaterId); M updateAndReturn(K id, Update<P> update, Instant updateAt, I updaterId); Update<P> updateOf(P partial); Update<P> updateOf(P partial, Iterable<String> removeFields); @Override void delete(K id); abstract List<KeySchemaElement> getKeySchema(); abstract List<AttributeDefinition> getAttributeDefinitions(); List<GlobalSecondaryIndex> getGlobalSecondaryIndexes(); void initTable(); void dropTable(); void copyTable(AmazonDynamoDB sourceDb, String sourceTable); void ensureIndexes();  }
@Test public void testUpdateOf() throws Exception { Update<TestModel> update = dao.updateOf(TestModel.builder().name("Ian").build()); assertEquals("Ian", update.getPartial().getName()); assertTrue(update.isUpdateField("name")); }
@Test public void testUpdateOfWithRemove() throws Exception { Update<TestModel> update = dao.updateOf(TestModel.builder().name("Ian").build(), ImmutableList.of("email")); assertEquals("Ian", update.getPartial().getName()); assertTrue(update.isUpdateField("name")); assertTrue(update.isUpdateField("email")); assertEquals(ImmutableSet.of("email"), update.getRemoveFields()); }