class SampleDao {

  public void updateSample(Sample sample, Long userIdMakingChange) {
    Database db = dbp.get();

    // Insert the history row first, so it will fail (non-unique sample_id + update_sequence)
    // if someone else modified the row. This is an optimistic locking strategy.
    int newUpdateSequence = sample.getUpdateSequence() + 1;
    Date newUpdateTime = db.nowPerApp();
    db.toInsert("insert into sample_history (sample_id, sample_name, update_sequence, update_time, update_user_id,"
        + " is_deleted) values (?,?,?,?,?,'N')")
        .argLong(sample.getSampleId())
        .argString(sample.getName())
        .argInteger(newUpdateSequence)
        .argDate(newUpdateTime)
        .argLong(userIdMakingChange)
        .insert(1);

    db.toUpdate("update sample set sample_name=?, update_sequence=?, update_time=? where sample_id=?")
        .argString(sample.getName())
        .argInteger(newUpdateSequence)
        .argDate(newUpdateTime)
        .argLong(sample.getSampleId())
        .update(1);

    // Make sure the object in memory matches the database.
    sample.setUpdateSequence(newUpdateSequence);
    sample.setUpdateTime(newUpdateTime);
  }

  public  SampleDao(Supplier<Database> dbp);

}