copy method on trait in scala

22 views
Skip to first unread message

Yadukrishnan K

unread,
Feb 12, 2015, 10:01:53 AM2/12/15
to scala...@googlegroups.com
I have the below scenario

trait Persistable

abstract class BaseEntity extends Persistable{
val id:Long
}

trait Auditable {
val createdDate: java.sql.Timestamp
val modifiedDate : java.sql.Timestamp
}

I have a table say,
UserAccount(id, name, createdDate, modifiedDate) 

The corresponding case class will be
case class UserAccount(overide val id:Long, name:String, override val createdDate:java.sql.Timestamp, override val modifiedDate: java.sql.Timestamp) extends BaseEntity with Auditable

I do not want to save the createdDate and modifiedDate that is sent from the service. I want to set those values in the scala code itself for 2 reason.
1. to get without time zone issues
2. Security: Do not want anyone to change createdDate and modifiedDate.

I am using repository pattern and using generics with constraint as Persistable.

I thought I would check in the repository that if it is type of Auditable, i will make a copy of the incoming case class and then updated the createdDate and modifiedDate.

However, since trait doesnt allow that, I am not able to do that.
Is there anyway, in which I can set these values in the repository before calling the insert method ?


Reply all
Reply to author
Forward
0 new messages