On 19 Jan., 19:32, David Pollak <[email protected]> wrote:
> > i am trying to extend my logging trait. The Problem is, i can't say
> > something like A <: LongKeyedMapper[A] in my trait since ProtoUser
> > doesn't use IdPK but uses it's own declarations (which look the same
> > to me).
>
> Why do you need ProtoUser extended with IdPK? Why can't your trait work
> with LongKeyedMapper?
The code relies on having a .id method on the passed object. The Three
Traits are below. It works fine with anything having IdPK. At the
moment i have this code copied into my User singleton which is exactly
what i want to avoid.
I don't know how i would dynamify the use of the .id method. In
ActionLog and the Stamped trait.
trait Stamped[A <: LongKeyedMapper[A] with IdPK]
extends SkipLogging with KeyedMetaMapper[Long, A] {
self: A with MetaMapper[A] with KeyedMapper[Long, A] =>
override def afterCreate = (crudLog(_: A, "create")) ::
super.afterCreate
override def afterUpdate = (crudLog(_: A, "update")) ::
super.afterUpdate
override def afterDelete = (crudLog(_: A, "delete")) ::
super.afterDelete
private def crudLog(obj: A, action: String): Unit = {
if (!self.skipLogging) {
val log = new ActionLog
log.action(action).klass(obj.getClass.getName).record(obj.id).save
}
}
}
trait SkipLogging {
var skipLogging = false
}
trait ActionLogs[A <: Mapper[A] with IdPK] {
this: A =>
def logs: List[ActionLog] = ActionLog.findAll(
By(ActionLog.klass, this.getClass.getName),
By(ActionLog.record, this.id)
)
}
--
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.