다음 작업을 수행하려고합니다. 기본적으로 mongodb 문서를 복사하고 문서에 변경된 순서를 재구성하기 위해 timestamp 필드를 추가하기 만하면됩니다. 이 항목들.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 방법이 있나요 :
내 접근 방식은 다음과 같다?
또는 귀하의 접근 방식은 어떻습니까? 사전에
감사합니다,
스테판