AbstractMongoDao extends AbstractDao<M,P,K,I> { public Update<P> updateOf(P object) { ImmutableSet.Builder<String> attribs = ImmutableSet.builder(); if (object != null) { Document doc = partialMapper.toDocument(object); for (String key : doc.keySet()) { attribs.add(key); } } return Update.of(object, attribs.build()); } AbstractMongoDao(Class<M> modelClass, Class<P> partialClass, MongoCollection<Document> collection);  AbstractMongoDao(Class<M> modelClass, Class<P> partialClass, MongoCollection<Document> collection, ObjectMapper objectMapper, ObjectMapper extendedJsonMapper);  AbstractMongoDao(Class<M> modelClass, Class<P> partialClass, MongoCollection<Document> collection,
                            DocumentMapper<M> modelMapper, DocumentMapper<P> partialMapper); MongoCollection<Document> getCollection(); String getCollectionName(); DocumentMapper<M> getModelMapper(); DocumentMapper<P> getPartialMapper(); @Override Optional<M> loadOpt(K id); Optional<P> loadOpt(K id, Iterable<String> fields); @Override Iterable<M> iterateAll(); @Override M create(P partial, Instant createAt, I createBy); @Override void update(K id, Update<P> update, Instant updateAt, I updateBy); @Override M updateAndReturn(K id, Update<P> update, Instant updateAt, I updateBy); @Override void delete(K id); @Override void initTable(); @Override void dropTable(); List<IndexModel> getIndexes(); Update<P> updateOf(P object); Update<P> updateOf(P object, Iterable<String> removeFields); static final String ID_FIELD; }
@Test public void testUpdateOf() throws Exception { Update<TestUser> update = dao.updateOf(TestUser.builder().name("Rename").build()); assertTrue(update.isUpdateField("name")); assertEquals(ImmutableSet.of("name"), update.getUpdateFields()); assertEquals("Rename", update.getPartial().getName()); }
@Test public void testUpdateOfWithRemoveFields() throws Exception { Update<TestUser> update = dao.updateOf(TestUser.builder().name("Rename").build(), ImmutableList.of("email")); assertTrue(update.isUpdateField("name")); assertTrue(update.isUpdateField("email")); assertEquals("Rename", update.getPartial().getName()); assertEquals(ImmutableSet.of("name"), update.getSetFields()); assertEquals(ImmutableSet.of("email"), update.getRemoveFields()); }