See SalatDAO#decorateDBO
- this method is called before every insert/save/update. This could be a logical place to park the code that adds a timestamp to your DBO and saves a copy in your history collection. Just override it and call super.decorateDBO at the beginning. Then proceed to add your timestamp and do whatever else you need to do.
/** A central place to modify DBOs before inserting, saving, or updating.
* @param toPersist object to be serialized
* @return decorated DBO for persisting
*/
def decorateDBO(toPersist: ObjectType) = {
val dbo = _grater.asDBObject(toPersist)
if (forceTypeHints) {
// take advantage of the mutability of DBObject by cramming in a type hint
dbo(ctx.typeHintStrategy.typeHint) = ctx.typeHintStrategy.encode(toPersist.getClass.getName).asInstanceOf[AnyRef]
}
dbo
}
(Also DBOs are mutable so there is no need to make call toMap
. You can just directly assign the timestamp to dbo("timestamp")
)