Я пытаюсь добиться следующего: в основном просто копируя документ mongodb и добавляю к нему поле метки времени, чтобы восстановить порядок, в котором документ был изменен, и в случае необходимости восстановить эти записи.Обратная связь по объектам Versioning с Salat
Мой подход заключается в следующем:
@Salat
trait Version[A <: DBEntity] extends ModelCompanion[A, ObjectId] {
def timeStamp: Long = System.currentTimeMillis()
/**
* this method overrides the default salat dao save method in order to make a copy for versioning of Objects
*/
override def save(entity: A) =
{
if (entity.id != null) {
// let salat deserialze the case class into a DBObject
val dbo = dao._grater.asDBObject(entity)
//convert the Object into a Map and append our timestamp
val builder = BasicDBObjectBuilder.start(dbo.toMap()).add("timeStamp", timeStamp)
val copyCollection = MongoDBLayer.mongoDB("history")
//and save it in the historic collection
copyCollection.insert(builder.get())
}
//delegate to the superclass to perform the actual save process
val wr = dao.save(entity)
wr
}
}
Есть ли более элегантный/convienent способ сделать это?
Или как бы ваш подход был?
Спасибо заранее,
Стефан