GenericDAO { public void update(PK id, T model) { try (Connection connection = connectionProvider.get()) { Map<?, ?> map = MAPPER.map(model); Map<String, ?> result = R.table(tableName).get(id).update(map).run(connection); if (((Long) result.get("errors")) > 0) { throw new ReqlClientError("Failed to update model. %s", ((String) result.get("first_error")).split("\n")[0]); } } } GenericDAO(Provider<Connection> connection, Class<T> clazz, String tableName, String primaryKey); void initTable(); void create(T model); Optional<T> read(PK id); DAOIterator<T> read(); DAOIterator<T> read(Function<Table, ReqlExpr> filter); void update(PK id, T model); void updateNonAtomic(PK id, T model); void delete(PK id); Observable<ChangeFeedElement<T>> changes(); @SuppressWarnings("unchecked") Observable<ChangeFeedElement<T>> changes(Function<Table, ReqlExpr> filter);  }
@Test public void update() { TestModel model = new TestModel("1"); dao.create(model); model.sub = new TestModel.SubModel(); model.sub.name = "test"; dao.update(model.id, model); assertThat(dao.read("1").get().sub.name).isEqualTo(model.sub.name); }